Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Dialog Box error

Dialog Box error

Scheduled Pinned Locked Moved C / C++ / MFC
delphihelplearning
3 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    The_Server
    wrote on last edited by
    #1

    Hey again to all... I have a code that creates a dialog box... But this dialog box is useless cause it doesn't handle none of its messages... And when I call DefDlgProc there is an error when it tries to handle message #48 (I think) about a 1000 times. here is my code:

    #include <windows.h>
    #include "resource.h"

    bool g_run = true;

    LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    switch (message)
    {
    case WM_INITDIALOG:
    ShowWindow(hDlg,SW_SHOW);
    return TRUE;

    case WM\_COMMAND:
    	if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
    	{
    		g\_run = false;
    		EndDialog(hDlg, LOWORD(wParam));
    		return TRUE;
    	}
    	break;
    

    /* default:
    return DefDlgProc(hDlg,message,wParam,lParam);
    break;
    */ }
    return FALSE;
    }

    int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
    {
    HWND hwnd = CreateDialog(hInstance, (LPCTSTR)IDD_DIALOG1, NULL ,(DLGPROC)About);
    if (hwnd == NULL)
    {
    DWORD err = GetLastError();
    }

    while (g\_run);
    
    return 0;
    

    };

    T 1 Reply Last reply
    0
    • T The_Server

      Hey again to all... I have a code that creates a dialog box... But this dialog box is useless cause it doesn't handle none of its messages... And when I call DefDlgProc there is an error when it tries to handle message #48 (I think) about a 1000 times. here is my code:

      #include <windows.h>
      #include "resource.h"

      bool g_run = true;

      LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
      {
      switch (message)
      {
      case WM_INITDIALOG:
      ShowWindow(hDlg,SW_SHOW);
      return TRUE;

      case WM\_COMMAND:
      	if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
      	{
      		g\_run = false;
      		EndDialog(hDlg, LOWORD(wParam));
      		return TRUE;
      	}
      	break;
      

      /* default:
      return DefDlgProc(hDlg,message,wParam,lParam);
      break;
      */ }
      return FALSE;
      }

      int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
      {
      HWND hwnd = CreateDialog(hInstance, (LPCTSTR)IDD_DIALOG1, NULL ,(DLGPROC)About);
      if (hwnd == NULL)
      {
      DWORD err = GetLastError();
      }

      while (g\_run);
      
      return 0;
      

      };

      T Offline
      T Offline
      The_Server
      wrote on last edited by
      #2

      Hey... dude... You need to change your while (g_run); line to this lines:

      BOOL bRet;
      MSG msg;
      
      while ((g\_run) && ( (bRet = GetMessage(&msg, NULL, 0, 0)) != 0 ))
      { 
      	if (bRet == -1 )
      	{
      		// handle the error and possibly exit
      	}
      	else if (!IsWindow(hwnd) || !IsDialogMessage(hwnd, &msg)) 
      	{ 
      		TranslateMessage(&msg); 
      		DispatchMessage(&msg); 
      	} 
      } 
      

      **I wonder why it works ???? Really.. I don't know why it works... but it does**

      T 1 Reply Last reply
      0
      • T The_Server

        Hey... dude... You need to change your while (g_run); line to this lines:

        BOOL bRet;
        MSG msg;
        
        while ((g\_run) && ( (bRet = GetMessage(&msg, NULL, 0, 0)) != 0 ))
        { 
        	if (bRet == -1 )
        	{
        		// handle the error and possibly exit
        	}
        	else if (!IsWindow(hwnd) || !IsDialogMessage(hwnd, &msg)) 
        	{ 
        		TranslateMessage(&msg); 
        		DispatchMessage(&msg); 
        	} 
        } 
        

        **I wonder why it works ???? Really.. I don't know why it works... but it does**

        T Offline
        T Offline
        The_Server
        wrote on last edited by
        #3

        I tell why it works... :-O it didn't work because your dialog window didn't recieve the messages. :-O Now it works because your dialog now recieves the messages... that is why we need to use TranslateMessage and DispatchMessage. :-O

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups