问个对话框的问题!
原代码如下不知道哪里写的不对了
一进入对话框就死那里了
//这个是MainWin.h
#include <windows.h>
#include <cstring>
#include "resource.h"
using namespace std;
class CMainWin
{
private://data
HWND hwnd ;
MSG msg ;
HINSTANCE hInstance;
INT iCmdShow; //
TCHAR szAppName[100];//the class 's name
private://function
ATOM RegisterMyClass()
{
WNDCLASSEX wndclassex ;
wndclassex.cbSize = sizeof(WNDCLASSEX);
wndclassex.style = CS_HREDRAW | CS_VREDRAW;
wndclassex.lpfnWndProc = WndProc;
wndclassex.cbClsExtra = 0;
wndclassex.cbWndExtra = 0;
wndclassex.hInstance = hInstance;
wndclassex.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclassex.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclassex.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclassex.lpszMenuName = szAppName ;
wndclassex.lpszClassName = szAppName;
wndclassex.hIconSm = NULL;
return RegisterClassEx(&wndclassex);
}
bool CreateMyWindow()
{
hwnd = CreateWindowEx(WS_EX_APPWINDOW,
szAppName, // window class name
TEXT ("GSEdit"), // window caption
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // initial x position
CW_USEDEFAULT, // initial y position
CW_USEDEFAULT, // initial x size
CW_USEDEFAULT, // initial y size
NULL, // parent window handle
LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENU1)), // window menu handle
hInstance, // program instance handle
NULL) ;
if(!hwnd)
return false;
ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;
return true;
}
static LRESULT CALLBACK WndProc (HWND ,UINT ,WPARAM , LPARAM );
static BOOL CALLBACK ABOUT (HWND ,UINT ,WPARAM , LPARAM );
public:
CMainWin(const HINSTANCE &hInstance,const HINSTANCE &hPrevInstance,
const PSTR &szCmdLine,const int &iCmdShow)
{}
CMainWin(const HINSTANCE &hInstance,const INT &iCmdShow)
{
strcpy(szAppName,"chensha");
this->hInstance = hInstance;
this->iCmdShow = iCmdShow;
}
bool InitMyWindow()
{
if(RegisterMyClass()&&CreateMyWindow())
return true;
MessageBox (NULL, TEXT ("ERROR OCCUR!"),
szAppName, MB_ICONERROR) ;
return false;
}
void RunMyWindow()
{
while(GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
}
INT WINAPI ExitMyWindow()
{
return msg.wParam ;
}
};
LRESULT CALLBACK
CMainWin:: WndProc (HWND hwnd,UINT message,WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ;
static HINSTANCE his;
switch (message)
{
case WM_CREATE:
his = ((LPCREATESTRUCT)lParam)->hInstance;
return 0 ;
case WM_COMMAND:
if(LOWORD(wParam)==ID_ABOUT1)
DialogBox(his,(LPCTSTR)IDD_dilog1,hwnd,(DLGPROC)ABOUT);
return 0;
case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
};
BOOL CALLBACK
CMainWin::ABOUT (HWND hDlg ,UINT message ,WPARAM wParam , LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BUTTON1:
case IDC_BUTTON2:
EndDialog(hDlg,0);
return TRUE;
}
}
return FALSE;
}
//这个是主函数
#include "MainWin.h"
INT WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
CMainWin object(hInstance,iCmdShow);
if(!object.InitMyWindow())
return false;
object.RunMyWindow();
object.ExitMyWindow();
}