How to get the controls of a dialog defined in an RC file?

Forgive my experience, but I'm trying to get the dimensions of some controls in a dialog that is defined in a resource file. It looks something like this:

1
2
3
4
5
6
IDD_MY_DLG DIALOG  0, 0, 300, 200
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,40,45,30,17
    PUSHBUTTON      "Cancel",IDCANCEL,135,45,30,17
END


I am trying to get the dimensions of the OK and CANCEL buttons.

I am able to get the size of the dialog itself using the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
SIZE GetDialogSize(INT nResourceId, BOOL bApproximateCalcMethod = FALSE, LPCTSTR strDllName = NULL)
{

    SIZE dlgSize = {0}; 
    HINSTANCE hModule = 0;

    if(strDllName != NULL)   
        hModule= ::LoadLibrary(strDllName);              
    else
        hModule = ::GetModuleHandle(NULL);   

    HRSRC hRsrc = ::FindResource(hModule, MAKEINTRESOURCE(nResourceId), RT_DIALOG);  

    HGLOBAL hTemplate = ::LoadResource(hModule, hRsrc);  

    DLGTEMPLATE* pTemplate = (DLGTEMPLATE*)::LockResource(hTemplate);

    if (bApproximateCalcMethod) // the approximate method of calculating
    {
        LONG dlgBaseUnits = GetDialogBaseUnits();
        int baseunitX = LOWORD(dlgBaseUnits), baseunitY = HIWORD(dlgBaseUnits);
        dlgSize.cx = MulDiv(pTemplate->cx, baseunitX, 4);
        dlgSize.cy = MulDiv(pTemplate->cy, baseunitY, 8);
    }
    else // the accurate method of calculation
    {
        HWND hDlg = ::CreateDialogIndirect(0, pTemplate, NULL, DialogProc);         
        RECT rc = {0};
        ::GetWindowRect(hDlg, &rc);
        ::DestroyWindow(hDlg);

        dlgSize.cx = rc.right - rc.left;
        dlgSize.cy = rc.bottom - rc.top;
    }

    UnlockResource(hTemplate);
    ::FreeResource(hTemplate);

    if(strDllName != NULL)
        ::FreeLibrary(hModule);

    return dlgSize;
}


However, I'm not sure how to do the same for the controls. According to the documentation, the DLGTEMPLATE structure "specifies the number of controls in the dialog box and therefore specifies the number of subsequent DLGITEMTEMPLATE structures in the template".

I am not sure exactly how to use the DLGITEMTEMPLATE struct and examples I've found does not specifically show how to obtain the controls, only describing wha t it is.

Can someone provide a concrete example of how to achieve this?
Last edited on
Topic archived. No new replies allowed.