Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Is there something wrong with my dialogbox's procedure?

Posted on 2004-08-15
1
Medium Priority
?
292 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 400 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
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…
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.

704 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