We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,571 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Using DialogBox in a separate class (non-MFC)

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.

3
Contributors
3
Replies
1 Day
Discussion Span
5 Months Ago
Last Updated
4
Views
Question
Answered
dshiells
Newbie Poster
13 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

Check out this link

Ancient Dragon
Achieved Level 70
Team Colleague
32,275 posts since Aug 2005
Reputation Points: 5,852
Solved Threads: 2,590
Skill Endorsements: 70
sujayg
Newbie Poster
8 posts since Nov 2008
Reputation Points: 24
Solved Threads: 2
Skill Endorsements: 0

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

dshiells
Newbie Poster
13 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 5 Months Ago by sujayg and Ancient Dragon

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0703 seconds using 2.76MB