#include <Windows.h>
#include "resource.h"
#include <stdio.h>
void RegisterClass_CLS(WNDCLASS &wndcls, const HINSTANCE hInstance);
void CreateWindow_Wnd(HWND &hWnd,const HINSTANCE hInstance);
LRESULT CALLBACK WindowProc( HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance,
__in LPSTR lpCmdLine, __in int nShowCmd )
{
WNDCLASS cls;
RegisterClass_CLS(cls,hInstance);
if( !RegisterClass(&cls) ){
MessageBox(NULL,TEXT("注册窗口类失败!"),TEXT("标题"),MB_OKCANCEL);
return -1;
}
HWND hWnd;
CreateWindow_Wnd(hWnd,hInstance);
if( !hWnd ){
MessageBox(NULL,TEXT("创建窗口失败!"),TEXT("标题"), MB_OKCANCEL );
return -1;
}
ShowWindow(hWnd,SW_SHOW);
UpdateWindow(hWnd);
MSG msg;
while ( GetMessage(&msg,NULL,0,0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
void RegisterClass_CLS(WNDCLASS &wndcls, const HINSTANCE hInstance)
{
wndcls.cbClsExtra = 0;
wndcls.cbWndExtra = 0;
wndcls.hbrBackground = (HBRUSH)::GetStockObject(NULL_BRUSH);
wndcls.hCursor = ::LoadCursor(NULL,IDC_ARROW);
wndcls.hIcon = ::LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));
wndcls.hInstance = hInstance;
wndcls.lpfnWndProc = WindowProc;
wndcls.lpszClassName = TEXT("HellCpp");
wndcls.lpszMenuName = NULL;
wndcls.style = CS_HREDRAW | CS_VREDRAW ;
}
void CreateWindow_Wnd(HWND &hWnd,const HINSTANCE hInstance)
{
hWnd = CreateWindow( TEXT("HellCpp"), TEXT("win程序"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT ,CW_USEDEFAULT ,
CW_USEDEFAULT ,CW_USEDEFAULT ,
NULL,NULL,
hInstance,0
);
}
LRESULT CALLBACK WindowProc( HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
DestroyWindow(hwnd);
PostQuitMessage(0);
break;
case WM_CREATE:
SetTimer(hwnd, 1, 3000, NULL);
break;
case WM_TIMER:
MessageBox(hwnd,"时间到!","caption",MB_OK);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}