时进研二了,现在才系统的看编程的书,以前用的最多的是TC ,写的是C程序,现在大家都使用VC++了,只好与时俱进,看VC++了,同时特意开辟此blog,记录学习的点点滴滴。
下面是我写的第一个win32程序:
#include <windows.h>
INT WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,INT);
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE myhInst;
static LPCWSTR szAppName=L"WinAPI";
static LPCWSTR szAppTitle=L"my first Application use Windows API";
INT WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR IpCmdLine,int nShowCmd)
{
HWND hMainwnd;
MSG message;
WNDCLASS myWinProc;
if(!hPrevInstance)
{
myWinProc.style =CS_HREDRAW | CS_VREDRAW;
myWinProc.lpfnWndProc =WndProc;
myWinProc.cbClsExtra =0;
myWinProc.cbWndExtra =0;
myWinProc.hInstance =hInstance;
myWinProc.hIcon =LoadIcon(NULL,IDI_APPLICATION);
myWinProc.hCursor =LoadCursor(NULL,IDC_ARROW);
myWinProc.hbrBackground=static_cast <HBRUSH>(GetStockObject(WHITE_BRUSH));
myWinProc.lpszClassName=szAppName;
myWinProc.lpszMenuName =NULL;
RegisterClass(&myWinProc);
}
hMainwnd=CreateWindow(szAppName,
szAppTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hMainwnd,SW_SHOWMAXIMIZED);
UpdateWindow(hMainwnd);
while(GetMessage(&message,NULL,0,0))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
return static_cast<INT> (message.wParam);
}
LRESULT CALLBACK WndProc(HWND hMainwnd,
UINT message,
WPARAM wParam,
LPARAM IParam)
{
LPCWSTR messageLeft=L"我点鼠标左键!/n";
LPCWSTR messageRight=L"我点鼠标右键!/n";
switch(message)
{
case WM_RBUTTONDOWN:
{
MessageBeep(MB_ICONINFORMATION);
MessageBox(GetFocus(),messageRight,L"Message",
MB_OK | MB_ICONINFORMATION);
break;
}
case WM_LBUTTONDOWN:
{
MessageBeep(MB_ICONINFORMATION);
MessageBox(GetFocus(),messageLeft,L"Message",
MB_OK | MB_ICONINFORMATION);
break;
}
case WM_PAINT:
{
MessageBeep(MB_ICONINFORMATION);
HDC hdc;
PAINTSTRUCT PaintSt;
RECT myrect;
hdc=BeginPaint(hMainwnd,&PaintSt);
GetClientRect(hMainwnd,&myrect);
SetBkMode(hdc,TRANSPARENT);
DrawText(
hdc,
L"我开始点了",
-1,
&myrect,
DT_SINGLELINE|DT_CENTER|DT_VCENTER
);
EndPaint(hMainwnd,&PaintSt);
MessageBeep(MB_ICONINFORMATION);
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
default:
break;
}
return DefWindowProc(hMainwnd,message,wParam,IParam);
}