Jesse Moreland
Jesse Moreland

Reputation: 443

Opening a dialog box

I don't quite understand how this works. So I've made my dialog box.. or boxes. And I don't know how to make them appear in my code. Right now I'm trying to just get them to pop up right when I start my program so I can get a basic understanding of how this works.

 switch (message)
 {
 case WM_CREATE:
     HINSTANCE hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
     CreateDialog(hInstance, "Whatever", hwnd, ABOUT_DIALOG);

That gives me an error in CreateDialog saying a parameter of type int is incompatible with DLGPROC. I'm assuming that I need to declare my dialog box somewhere?

And If I had a button on my very first start up window, how would I know that the user pressed the button? I'm going to once again assume and say that I need to catch it somewhere in the WM_COMMAND command?

Upvotes: 1

Views: 856

Answers (1)

David Heffernan
David Heffernan

Reputation: 612964

The final parameter, the thing that you pass ABOUT_DIALOG to, needs to be a DLGPROC. That is a function of this form:

INT_PTR CALLBACK DialogProc(
  HWND hwndDlg,
  UINT uMsg,
  WPARAM wParam,
  LPARAM lParam
);

The compiler is telling you that ABOUT_DIALOG is not a function of that form. In fact the compiler tells you that ABOUT_DIALOG is an int which is definitely not the right thing!

To get it up and running with a default do-nothing dialog procedure implement it like this:

INT_PTR CALLBACK DialogProc(
  HWND hwndDlg,
  UINT uMsg,
  WPARAM wParam,
  LPARAM lParam
)
{
    return FALSE;
}

The documentation says this:

Typically, the dialog box procedure should return TRUE if it processed the message, and FALSE if it did not. If the dialog box procedure returns FALSE, the dialog manager performs the default dialog operation in response to the message.

So by returning FALSE we are asking for default processing.

Once you have the dialog up and running, you can then fill out the dialog procedure with any functionality that you need.

Upvotes: 3

Related Questions