I'm not sure how to call Dialog Procedures of certain classes and was looking for some help.

I'm aware for a normal Message Procedure you can do this in the MessageProc:

case WM_CREATE:
{   
    CREATESTRUCT* cs = (CREATESTRUCT*)_lParam;
    pApplication = (CApplication*)cs->lpCreateParams;

    return pApplication->MessageProc(_Msg, _wParam, _lParam);
}

which will allow you to create a Message Proc independent to the class.

However due to the fact I don't know exactly how the first two lines work (just the definition that they return the 'this' pointer of the application), I can't work out what to do to get my Dialog Procedures to do a similar thing

case WM_INITDIALOG:
{
    //How can I get the pointer to the inspector that 
    //I want to call the dialog proc on?

    return pInspector->DlgProc(_hWndDlg, _Msg, _wParam, _lParam);
}

Any help to both get the pointer to the inspector working and also clarify exactly what the other two lines are doing in WM_CREATE would be appreciated

有帮助吗?

解决方案

When a window is created, it receives a WM_CREATE message with a pointer to a CREATESTRUCT structure, and in there is a pointer-sized userdata field (lpCreateParams). This value comes from the lpParam argument passed to the CreateWindowEx() function.

This is the general mechanism which lets you associate your own class or data structure with an instance of a window.

This pointer generally needs to be saved somewhere in order to use it later on. One common way of doing this is to store it in a window property:

case WM_CREATE:
{
    CREATESTRUCT* cs = (CREATESTRUCT*)_lParam;
    pApplication = (CApplication*)cs->lpCreateParams;

    SetProp(hWnd, L"my.property", (HANDLE)pApplication);
}

Then to retrieve the value when handling other messages:

pApplication = (CApplication*)GetProp(hWnd, L"my.property");

Dialogs are not exactly like normal windows, so although a similar mechanism exists, it is implemented differently. When a dialog procedure receives the WM_INITDIALOG message, the lParam value is equivalent to the lpCreateParams value in a WM_CREATE message.

In order to save your pInspector value it would need to have been provided as the dwInitParam value when the dialog was created, but assuming that it was, you can handle this in a similar way:

case WM_INITDIALOG:
{
    pInspector = (CInspector*)lParam;
    SetProp(hWnd, L"my.property", (HANDLE)pInspector);
}

And to retrieve the value when handling other messages:

pInspector = (CInspector*)GetProp(hWnd, L"my.property");
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top