1.11M Members

Using DialogBox in a separate class (non-MFC)

 
0
 

Hi all,

I want to create a separate class in my C++ application which creates a dialog from a resource, similar to extending CDialog in MFC, however I would like to avoid using MFC.

For example, I would like to be able to run the following code in my WinMain function:

int WINAPI WinMain(HINSTANCE hInst, HINSTANCE h0, LPSTR lpCmdLine, int nCmdShow)
{
    MainWindow(this);
}

and have it display my dialog. I have tried using the following code in my MainWindow class:

MainWindow::MainWindow(HWND hWnd)
{
    DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_MAINDLG), NULL, MainWindow::MainDlgProc);
}

BOOL CALLBACK MainWindow::MainDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    switch(Message)
    {
        case WM_INITDIALOG:
            return TRUE;
        default:
            return FALSE;
    }
    return TRUE;
}

But am getting errors regarding the MainWindow::MainDlgProc argument in the DialogBox() call. I have tried a variety of options like reinterpret_cast<DLGPROC>(MainDlgProc), (DLGPROC) MainDlgProc, both with and without MainWindow:: prepended, however as you may guess this was just me guessing as I have got in over my head!

Any help someone could give me would be greatly appriciated - even if it is in the form of a tutorial, although sample code would be preferable :)

Thanks in advance.

 
2
 

Is MainWindow::MainDlgProc() a static method? Only static methods can be used as callback functions.

Check out this link

 
0
 

ARGH! So many hours lost for something so simple, thanks Ancient Dragon!!

Question Answered as of 1 Year Ago by Ancient Dragon and sujayg
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article