Home > Software engineering >  Win32sdk china-africa pop up a modal dialog box messgebox, but messagebox cannot close
Win32sdk china-africa pop up a modal dialog box messgebox, but messagebox cannot close

Time:10-12

Vs2010 create a win32 application, and then add a dialog resource idd_dialog1, click ok button will pop up a messagebox, click message box sure button but no response,

Delete the system automatically generated code, copy the code below to engineering,
 
# include "stdafx. H"
# include "testdlg. H"

# define MAX_LOADSTRING 100

//global variables:
HINSTANCE hInst,//the current instance
TCHAR szTitle [MAX_LOADSTRING];//title bar text
TCHAR szWindowClass [MAX_LOADSTRING];//the main window class name

BOOL InitInstance (HINSTANCE, int);
INT_PTR CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About (HWND, UINT, WPARAM, LPARAM);

Int APIENTRY _tWinMain (HINSTANCE HINSTANCE,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
Int nCmdShow)
{
UNREFERENCED_PARAMETER (hPrevInstance);
UNREFERENCED_PARAMETER (lpCmdLine);

MSG MSG.

if (! InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

//the main message loop:
While (GetMessage (& amp; MSG, NULL, 0, 0))
{
if (! IsDialogMessage (HWND. MSG., & amp; MSG))
{
TranslateMessage (& amp; MSG);
DispatchMessage (& amp; MSG);
}
}

Return (int) MSG. WParam;
}


BOOL InitInstance (HINSTANCE HINSTANCE, int nCmdShow)
{
The HWND HWND;

HInst=hInstance;//handle to the instance is stored in the global variable

HWnd=CreateDialog (hInstance, MAKEINTRESOURCE (IDD_DIALOG1), NULL, WndProc);

if (! HWnd)
{
return FALSE;
}

ShowWindow (hWnd, nCmdShow);
UpdateWindow (hWnd);

return TRUE;
}

INT_PTR CALLBACK WndProc (HWND HWND, UINT message, WPARAM WPARAM, LPARAM LPARAM)
{
Int wmId wmEvent;
PAINTSTRUCT ps;
HDC HDC.

The switch (the message)
{
Case WM_COMMAND:
WmId=LOWORD (wParam);
WmEvent=HIWORD (wParam);
//analysis menu choice:
The switch (wmId)
{
Case IDOK:
MessageBox (hWnd, _T (" cannot close!" ), _T (" blue "), MB_OK);
break;
Case IDCANCEL:
The DestroyWindow (hWnd);
break;
Default:
Return DefWindowProc (hWnd, message, wParam, lParam);
}
break;
In case the WM_PAINT:
HDC=BeginPaint (hWnd, & amp; Ps);
//TODO: add any in this drawing code...
EndPaint (hWnd, & amp; Ps);
break;
Case WM_DESTROY:
The PostQuitMessage (0);
break;
Default:
Return DefWindowProc (hWnd, message, wParam, lParam);
}
return 0;
}


CodePudding user response:

CreateDialog with independent WndProc
Reference App wizard generated Hello word About

CodePudding user response:

 default: 
//return DefWindowProc (hWnd, message, wParam, lParam);
break;
  • Related