#include "windows.h"
#include "pro2.h"
long WINAPI WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);
HWND hWndMain,hWndPush,hWndDefPush;
HINSTANCE hInst;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
MSG Msg;
if(!InitWindowsClass(hInstance))
return FALSE;
if(!InitWindows(hInstance,nCmdShow))
return FALSE;
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
//消息处理函数
long WINAPI WndProc(HWND hWnd,UINT iMessage,UINT wParam,LONG lParam)
{
static int x=50,y=30;
switch(iMessage)
{
case WM_CREATE:
//创建普通按钮
hWndPush=CreateWindow("pro1",
"普通按钮",
BS_PUSHBUTTON|WS_CHILD|WS_VISIBLE,
x,y,
240,25,
hWnd,
(HMENU)IDB_PUSHBUTTON,
hInst,
NULL);
//创建默认按钮控件子窗口
hWndDefPush=CreateWindow("pro1",
"默认按钮",
BS_DEFPUSHBUTTON|WS_CHILD|WS_VISIBLE,
x,y+30,
240,25,
hWnd,
(HMENU)IDB_DEFPUSHBUTTON,
hInst,
NULL);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd,iMessage,wParam,lParam);
}
return 0;
}
//初始化窗口类
BOOL InitWindowsClass(HINSTANCE hInstance)
{
WNDCLASS WndClass;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)(GetStockObject(WHITE_BRUSH));
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,"END");
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=WndProc;
WndClass.lpszClassName="pro1";
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW|CS_VREDRAW;
return RegisterClass(&WndClass);
}
//初始化窗口
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;
hWnd=CreateWindow("pro1",
"pro1",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
if(!hWnd)
return FALSE;
hWndMain=hWnd;
hInst=hInstance;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
改了还是不行啊
[此贴子已经被作者于2006-12-12 11:01:26编辑过]