1.windows编程两个准则:序列 和 可识别
2.CreateWindow创建窗口在内存中,showwindow显示在显示屏上。
CreateWindow发送消息给操作系统,操作系统调用WM_CREATE,此时没有进入消息循环。
一般在WM_CREATE的时候加载动态链接库。
4.InvalidateRect()发送消息给操作系统,操作系统调用WM_PAINT消息。
5.消息分成两种:进队列,不进队列的。
6.自定义消息:WM_USER。 SendMessage();
7.双键同时按消息响应。(wParam & MK_RBUTTON)(wParam & MK_LBUTTON).
经典中的经典:Hello windows!!!!
#pragma comment(lib, "Winmm.lib")
#include <Windows.h>
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
int WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
static TCHAR szAppName[] = TEXT("windows程序设计");
HWND hwnd;
WNDCLASS wndclass;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance = hInstance;
wndclass.lpfnWndProc = WndProc;
wndclass.lpszClassName = szAppName;
wndclass.lpszMenuName = NULL;
wndclass.style = 0;
if (!RegisterClass(&wndclass))
{
MessageBox(hwnd,TEXT("注册窗口类失败!"),TEXT("提示"),MB_OK);
return 0;
}
hwnd = CreateWindow(szAppName,
szAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch (uMsg)
{
case WM_CREATE:
PlaySound(TEXT ("HelloWin.wav"), NULL, SND_FILENAME | SND_ASYNC);
return 0;
case WM_SIZE:
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
GetClientRect(hwnd,&rect);
DrawText(hdc,TEXT("赛萌是大笨蛋"),-1,&rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER);
EndPaint(hwnd,&ps);
return 0;
case WM_LBUTTONDOWN:
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}