• C++ 一键关闭屏幕


    Demo下载地址:http://pan.baidu.com/s/1vN4wF

    #include <windows.h>
    #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);
    }
  • 相关阅读:
    Python爬取优质高清壁纸网站:彼岸
    xpath爬取喜马拉雅糗事播报音频地址
    Pyquery爬取豆瓣电影Top250
    pipenv虚拟环境
    pip报No module named 'pip'错怎么处理?
    SVN的使用
    测试报告
    软件测试分类
    测试模型
    软件开发过程模型
  • 原文地址:https://www.cnblogs.com/calm2012/p/3464909.html
Copyright © 2020-2023  润新知