|
楼主 |
发表于 2016-11-23 12:27:15
|
显示全部楼层
- /*
- 利用随机RGB颜色布满客户区
- */
- #include <windows.h>
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
- {
- WNDCLASS wndclass;
- HWND hwnd;
- MSG msg;
- static TCHAR szAppName[] = TEXT("随机点设置");
- //对wndclass的参数赋值
- wndclass.style = CS_HREDRAW | CS_VREDRAW;
- wndclass.lpfnWndProc = WndProc;
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = 0;
- wndclass.hInstance = hInstance;
- wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
- wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
- wndclass.lpszMenuName = NULL;
- wndclass.lpszClassName = szAppName;
- //注册wndclass类
- RegisterClass(&wndclass);
- hwnd = CreateWindow(szAppName, TEXT("hellowin"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
- ShowWindow(hwnd, iCmdShow);
- UpdateWindow(hwnd);
- while (GetMessage(&msg, hwnd, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return (msg.wParam);
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- PAINTSTRUCT ps;
- HDC hdc;
- switch (message)
- {
- case WM_PAINT:
- //MessageBox(hwnd, TEXT("TEST"), TEXT("TEST"), MB_OKCANCEL);
- hdc = BeginPaint(hwnd, &ps);
- TextOut(hdc, 10, 10, TEXT("12345"), 5);
- EndPaint(hwnd, &ps);
- return 0;
- case WM_DESTROY:
- PostQuitMessage(0);
- return 0;
- default:
- return DefWindowProc(hwnd, message, wParam, lParam);
- }
- return 0;
- }
复制代码 |
|