Question

In short, how can one programatically access a compiled resource at runtime to extract strings from a DLGINIT structure?

A little more detailed...

In an MFC application, a Combo Box can be defined in an .rc file as a line in a dialog description using COMBOBOX and having a corresponding DLGINIT structure like so:

IDD_COMBOBOXTEST_DIALOG DIALOGEX 0, 0, 320, 200
STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU |     WS_THICKFRAME
EXSTYLE WS_EX_APPWINDOW
CAPTION "ComboBoxTest"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,209,179,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,263,179,50,14
    COMBOBOX        IDC_COMBO1,22,20,132,30,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP
    EDITTEXT        IDC_EDIT1,22,42,132,134,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY
    PUSHBUTTON      "Load",IDC_BUTTON1,159,42,50,14
END

//...

IDD_COMBOBOXTEST_DIALOG DLGINIT
BEGIN
    IDC_COMBO1, 0x403, 4,  0    0x6e4f, 0x0065, 
    IDC_COMBO1, 0x403, 4,  0    0x7754, 0x006f, 
    0
END

I have learned that a Visual C++ resource file is encoded in single byte text encoding using a given code page at the top of the resource file. I've also learned that the lines in the DLGINIT structure are broken down as follows:

<CONTROL ID>, 0x403, <STRING LENGTH>, 0    <STRING BYTES ENCODED FOR CODE PAGE>

What I want to do is get in this compiled resource and pull out that string. There's API for some of this kind of thing using AfxFindResourceHandle, but I'm not sure that's the way I need to go.

Était-ce utile?

La solution

To my knowledge the way the dialogs are laid out in the resource section is mirrored by how you would manually create a dialog in memory using DLGTEMPLATE and DLGITEMTEMPLATE. So consult that part of the MSDN documentation to parse them. I have so far only done the inverse (i.e. created such a dialog template in memory from scratch).

There is no function to do it, you will have to do it manually.

Also, to my knowledge the DLGINIT isn't even stored in the PE file. I think it is merely there for the resource editor itself, but I'm not 100% sure.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top