Solved

Is there something wrong with my dialogbox's procedure?

Posted on 2004-08-15
1
285 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Find boost header files using gnu make (MinGW) on Win 7 11 105
Building cUrl in Windows v7.43.0 4 39
Compile GLUT with Visual Studio 2015 1 209
Issues with C++ Class 19 109
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

696 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