代码没有给出注释太过表面,看不懂,只把代码copy了不知道其中原理。 以下是第一次的代码,写了一点注释,还是很多不懂,请给多一点注释好吗?
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance, // handle to current instance // 句柄 to 当前的实例 HINSTANCE hPrevInstance, // handle to previous instance // 句柄 to 前一个实例 LPSTR lpCmdLine, // long pointer to command line // Cmd = command -> 命令
int nCmdShow) //确定程序窗口的显示方式,如最大化,最小化,隐藏等
// #define WINAPI __stdcall // #define APIENTRY WINAPI // => APIENTRY = WINAPI { HWND hwnd; MSG Msg; WNDCLASS wndclass; char lpszClassName [] = "Windows"; char lpszTitle [] = "Windows Demo";
wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0;
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); //GetStockObject函数检索预定义的备用笔、刷子、字体或者调色板的句柄 //函数原型: HGDIOBJ GetStockObject(int fnObject);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); //函数原型: HCURSOR LoadCursor(HINSTANCE hlnstance, LPCTSTR lpCursorName);
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); //函数原型: HICON Loadlcon(HINSTANCE hlnstance, LPCTSTR lplconName);
wndclass.hInstance = hInstance; wndclass.lpfnWndProc = WndProc; wndclass.lpszClassName = lpszClassName; wndclass.lpszMenuName = NULL; wndclass.style = 0;
if(!RegisterClass(&wndclass)) { return 0; }
hwnd = CreateWindow(lpszClassName, lpszTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, nCmdShow); //函数原型: BOOL ShowWindow(HWND hWnd,int nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0)) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; }
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch(message) { case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, message, wParam, lParam); } return 0; }
[此贴子已经被作者于2004-10-03 11:50:10编辑过]