#include <windows.h>#include <stdio.h>//回调函数LRESULT CALLBACK WinSunProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);//入口函数int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){WNDCLASS wndcls;wndcls.cbClsExtra = 0;wndcls.cbWndExtra = 0;wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);wndcls.hCursor = LoadCursor(NULL, IDC_HAND);wndcls.hIcon = LoadIcon(NULL, IDI_APPLICATION);wndcls.hInstance = hInstance;wndcls.lpfnWndProc = WinSunProc;wndcls.lpszClassName = TEXT("weixin2003");wndcls.lpszMenuName = NULL;wndcls.style = CS_HREDRAW | CS_VREDRAW;//垂直从化,水平从化!RegisterClass(&wndcls);//注册一个窗口类!HWND hwnd;//创建一个窗口hwnd = CreateWindow(TEXT("weixin2003"), TEXT("北京维新科学技术培训中心"), WS_OVERLAPPEDWINDOW, 50, 50, 800, 600, NULL, NULL, hInstance, NULL);ShowWindow(hwnd, SW_NORMAL);//显示一个窗口!UpdateWindow(hwnd);//更新一个窗口//消息循环!MSG msg;while (GetMessage(&msg, NULL, 0, 0))//接收一切的消息!{TranslateMessage(&msg);DispatchMessage(&msg);}return 0;}LRESULT CALLBACK WinSunProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){switch(uMsg){case WM_CHAR:char szChar[20];sprintf(szChar, "char is %d", wParam);MessageBox(hwnd, szChar, TEXT("weixin"), 0);break;case WM_PAINT:HDC hDC;PAINTSTRUCT ps; hDC = BeginPaint(hwnd, &ps);TextOut(hDC, 0, 0, TEXT("维新培训"), strlen("维新培训"));EndPaint(hwnd, &ps);break;case WM_CLOSE:if (IDYES == MessageBox(hwnd, TEXT("是否真的结束?"), TEXT("weixin"), MB_YESNO)){DestroyWindow(hwnd);}break;case WM_LBUTTONDOWN:MessageBox(hwnd, TEXT("mouse clicked"), TEXT("weixin"), 0);HDC hdc;hdc = GetDC(hwnd);TextOut(hdc, 0, 50, TEXT("计算机编程语言培训"), strlen("计算机编程语言培训"));ReleaseDC(hwnd, hdc);break;case WM_DESTROY:PostQuitMessage(0);break;default:return DefWindowProc(hwnd, uMsg, wParam, lParam);}return 0;}
第一课主要是讲解window运行原理,根据如何设计一个窗口,创建窗口,注册窗口,显示窗口,更新窗口,消息循环这一条线索来编程的,如果你可以安装这一条线索来写你的代码就不会很难的!