Hard coding of resources in the application

I have code that shows a simple dialog and handles a user action (written using a simple WinAPI).

// Display dialog and handle user action
LRESULT choice = DialogBoxParam(NULL, MAKEINTRESOURCE(AP_IDD_DIALOG), NULL, (DLGPROC)DialogCallback, NULL);

Is there a way to hardcode a resource file dialog.rcthat is used to create a dialog? (I would like to get rid of the files .rc, and I'm sure that there is a way, but I do not know what it is :)

Edit

Also, does anyone have any ideas on converting existing files .rcto hard-coded resources? Is it possible?

+3
source share
5 answers

, , , Google , .

, DLGTEMPLATE - , , .

lib, "blob" dlgtemplate, blob. ( blob , )

DLGTemplate, . ( )

HGLOBAL LoadResourceImpl(wchar_t *resource, wchar_t *type)
{
    HRSRC handle = FindResource(hInstance, resource,type);
    if (handle)
    {
        HGLOBAL hResource = LoadResource(hInstance, handle);
        if (hResource)
            return LockResource(hResource);  
    }
    return 0;
}

DLGTEMPLATE * LoadDialog(wchar_t *resource)
{
    return (DLGTEMPLATE *) LoadResourceImpl(resource,RT_DIALOG);
}

DLGTEMPLATE * LoadDialog(int resource)
{
    return (DLGTEMPLATE *) LoadResourceImpl(MAKEINTRESOURCE(resource),RT_DIALOG);
}

, , - LoadDialog .

"", blob - 1 - , , , , ( DLGTEMPLATE:: cdit)

2 - , - , HEX

"HEX" DLGTEMPLATE , .

+1

*. rc (resource) , (.exe/.dll)

.

, , QT/wxWidgets. 1 !

+3

DialogBoxParamIndirect . . Raymond Chen , API- DialogBox * Indirect API.

Per MSDN, DLGTEMPLATE DLGITEMTEMPLATE. , API (FindResource, LoadResource LockResource), .

, , .rc. , , .

+2

.res ?

  • .rc .res
  • (, winhex) .res ( C).
  • .
  • DialogBoxIndirect.
+1

, DLGTEMPLATE?

Nothing prevents you from simply doing :: CreateWindow's these controls directly. If this is a simple dialog with 2-3 buttons and several text fields, just call :: CreateWindow, passing any common control you use to the window class.

These, in fact, are still DialogXxxxx functions. DLGTEMPLATE is a convenience for declarative styling of your forms, and using the template to make the corresponding calls to CreateWindow, etc.

0
source

Source: https://habr.com/ru/post/1749303/


All Articles