Demo下载地址:
#include#include "resource.h"LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter );int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ // 延时防止双击exe关闭屏幕后,又打开屏幕。关闭屏幕的消息,先于系统的双击消息; Sleep(200); ::SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM)2); static TCHAR szAppName[] = TEXT("HelloWin"); WNDCLASS wndClass; wndClass.style = CS_HREDRAW | CS_VREDRAW; wndClass.lpfnWndProc = WindowProc; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hInstance = hInstance; wndClass.hIcon = LoadIcon(hInstance, (char*)IDI_ICON1); wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndClass.lpszMenuName = NULL; wndClass.lpszClassName = szAppName; if (!RegisterClass(&wndClass)) { MessageBox(NULL, TEXT("注册窗口失败!"), TEXT(""), 0); return 0; } HWND hWnd = CreateWindow(szAppName, TEXT("Hello Program"), WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, hInstance, NULL); ::SendMessage(hWnd, WM_DESTROY, 0, NULL); return 0;}LRESULT CALLBACK WindowProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ){ HDC hdc; PAINTSTRUCT ps; RECT rect; switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, uMsg, wParam, lParam);}