Solved

Is there something wrong with my dialogbox's procedure?

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

770 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