Solved

Is there something wrong with my dialogbox's procedure?

Posted on 2004-08-15
1
281 Views
Last Modified: 2010-04-01
I seem to have somekind of a problem with my dialogbox's procedure. I made my program based on a c -language tutorial and the result is in c++ that the dialogprocedure steals the messagehandling and doesn't accept any input! There could be something else wrong, so I'll show the whole program here:

These functions are in headerfile:

BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
      switch(Message)
      {
            case WM_INITDIALOG:
                  return TRUE;

            case WM_COMMAND:
                  {
                        if(LOWORD(wParam) == IDC_SOMETHING)
                        {
                              EndDialog(hwnd, wParam);
                              return true;
                        }
                  }
                  break;

            default:
                  return FALSE;
      }
      return TRUE;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
      switch(Message)
      {
      case WM_COMMAND:
            switch(LOWORD(wParam))
            {
            case ID_STUFF:
                  int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG), hwnd, DlgProc);
                  
                  if(ret == IDC_SOMETHING)
                  {
                        MessageBox(hwnd, "Dialog exited with IDC_SOMETHING).", "Notice",
                              MB_OK | MB_ICONINFORMATION);
                  }
                  else if(ret == IDC_ELSE)
                  {
                        MessageBox(hwnd, "Dialog exited with IDC_ELSE.", "Notice",
                              MB_OK | MB_ICONINFORMATION);
                  }
                  else if(ret == -1)
                  {
                        MessageBox(hwnd, "Dialog failed!", "Error",
                              MB_OK | MB_ICONINFORMATION);
                  }
                  break;
            }
            break;
      case WM_CLOSE:
            DestroyWindow(hwnd);
            break;
      case WM_DESTROY:
            PostQuitMessage(0);
            break;
      default:
            return DefWindowProc(hwnd, Message, wParam, lParam);
      }
      return 0;
}

And here is the main file:

#include "winmain.h"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
      LPSTR lpCmdLine, int nCmdShow)
{
      wc.cbSize             = sizeof(WNDCLASSEX);
      wc.style             = 0;
      wc.lpfnWndProc       = WndProc;
      wc.cbClsExtra       = 0;
      wc.cbWndExtra       = 0;
      wc.hInstance       = hInstance;
      wc.hIcon             = LoadIcon(NULL, IDI_APPLICATION);
      wc.hCursor             = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
      wc.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU1);
      wc.lpszClassName = "MYCLASS";
      wc.hIconSm             = LoadIcon(NULL, IDI_APPLICATION);

      if(!RegisterClassEx(&wc))
      {
            MessageBox(NULL, "Window Registration Failed!", "Error!",
                  MB_ICONEXCLAMATION | MB_OK);
            return 0;
      }

      hwnd = CreateWindowEx(
            WS_EX_CLIENTEDGE,
            "MYCLASS",
            "The title of my window",
            WS_OVERLAPPEDWINDOW,
            CW_USEDEFAULT, CW_USEDEFAULT, 400, 600,
            NULL, NULL, hInstance, NULL);

      if(hwnd == NULL)
      {
            MessageBox(NULL, "Window Creation Failed!", "Error!",
                  MB_ICONEXCLAMATION | MB_OK);
            return 0;
      }

      ShowWindow(hwnd, nCmdShow);
      UpdateWindow(hwnd);

      while(GetMessage(&Msg, NULL, 0, 0))
      {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
      }
      return Msg.wParam;
}

The dialogprocedure checks only the IDC_SOMETHING-button input at this time although windowprocedure checks exitcode for all the buttons.

As a sidenote, I changed the dialog procedures default-command as EndDialog(), and it worked. The dialog quitted right after initializing it.
0
Comment
Question by:Tuomas
1 Comment
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 100 total points
ID: 11804977
DialogBox creates  a modal dialog that has it's own message loop. But you'll get all Dialog messages in DlgProc.

To have a non-modal dialog you have to call CreateDialog instead of DialogBox.

Regards, Alex
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now