#include "windows.h"
#include "stdio.h"
#include "resource.h"
// 消息处理过程, 其地址填入 WNDCLASS 结构的 lpfnWndProc 后, 由系统自动调用
LRESULT CALLBACK WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"Char code is %d", wParam);
MessageBox(hwnd, szChar, "char", 0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd, "mouse clicked","message", 0);
HDC hdc;
hdc = GetDC(hwnd);
TextOut(hdc, 0, 50, "天成数码", strlen("天成数码"));
ReleaseDC(hwnd, hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd, &ps);
TextOut(hDC,0,0,"http://www.baidu.com/",strlen("http://www.baidu.com/"));
EndPaint(hwnd, &ps);
break;
case WM_CLOSE:
if( IDYES==MessageBox(hwnd,"退出吗?","message",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_COMMAND:
if( wParam==ID_MENUITEM40001 )
{
PostMessage(hwnd,WM_CLOSE,0,0);
break;
}
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
WNDCLASS aaa;
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
{
// 填充窗口类初始值
aaa.style = CS_HREDRAW | CS_VREDRAW ;//| CS_NOCLOSE;
aaa.lpfnWndProc = WindowProc;
aaa.cbClsExtra=0;
aaa.cbWndExtra=0;
aaa.hInstance = hInstance;
aaa.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1) );
aaa.hCursor = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_CURSOR1) );
aaa.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH );
aaa.lpszClassName="tc2007"; // 关键部位
aaa.lpszMenuName=0;
// 注册窗口类
RegisterClass(&aaa);
// 建立窗口
HWND h = CreateWindow( "tc2007","first program",WS_OVERLAPPEDWINDOW,0,0,500,300,NULL,LoadMenu( hInstance, MAKEINTRESOURCE(IDR_MENU1)),hInstance,NULL);
// 显示和刷新窗口
ShowWindow(h, nCmdShow );
UpdateWindow(h);
// 进入消息循环, 退出则程序也退出
MSG msg;
while( GetMessage(&msg, NULL, 0, 0) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
|