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
Solved

Is there something wrong with my dialogbox's procedure?

Posted on 2004-08-15
1
284 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Prototype for MessageDlg in Embacadero XE 2 2 42
Socket Programming (Unix) 8 140
sorting efficency of sorting algorithm 30 121
Precision Problem in C++ 7 43
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 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.

809 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