zoukankan      html  css  js  c++  java
  • Win32编程

    只有代码:

    #include <windows.h>
    
    HINSTANCE hinst;
    
    LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        switch (uMsg)
        {
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
            break;
        case WM_LBUTTONDOWN:
            MessageBox(hWnd, L"ONDragon", L"ONDragon", MB_OK);
            break;
        default:
            return DefWindowProc(hWnd, uMsg, wParam, lParam);
        }
        return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int lpCmdShow)
    {
        //定义窗口类
        WNDCLASSEX wcx;
    
        hinst = hInstance;
        MSG msg;
        BOOL getMessage;
    
        wcx.lpszClassName = L"MainClass";
        wcx.cbSize = sizeof(wcx);
        wcx.style = CS_HREDRAW | CS_VREDRAW;
        wcx.hInstance = hinst;
        wcx.lpfnWndProc = MainWndProc;
        wcx.cbClsExtra = 0;
        wcx.cbWndExtra = 0;
        wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
        wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
        wcx.lpszMenuName = NULL;
        wcx.hIconSm = (HICON)LoadImage( hInstance,
                                        MAKEINTRESOURCE(5),
                                        IMAGE_ICON,
                                        GetSystemMetrics(SM_CXSMICON),
                                        GetSystemMetrics(SM_CYSMICON),
                                        LR_DEFAULTCOLOR);
        //注册窗口类
        if (!RegisterClassEx(&wcx))
        {
            return 0;
        }
        //使用窗口类创建窗口
        HWND hWnd = CreateWindow(   L"MainClass",
                                    L"ONDragon",
                                    WS_OVERLAPPEDWINDOW,
                                    CW_USEDEFAULT,
                                    CW_USEDEFAULT,
                                    CW_USEDEFAULT,
                                    CW_USEDEFAULT,
                                    NULL,
                                    NULL,
                                    hinst,
                                    NULL);
        if (!hWnd)
        {
            return 0;
        }
        //显示窗口
        ShowWindow(hWnd,lpCmdShow);
        //立即显示窗口
        UpdateWindow(hWnd);
        while ( 0 != (getMessage = GetMessage(&msg,NULL,0,0)))
        {
            //传递个回调函数MainProc
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        return 0;
    }

    通过资源方式:

    #include <windows.h>
    #include "resource.h"
    
    INT_PTR CALLBACK MainProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
        BOOL ret = TRUE;
        switch (uMsg)
        {
        case WM_CLOSE:
            EndDialog(hDlg, 0);
            break;
        case WM_DESTROY:
            PostQuitMessage(0);
            break;
        case WM_LBUTTONDOWN:
            MessageBox(hDlg, L"ONDragon", L"ONDragon", MB_OK);
            break;
        case WM_COMMAND:
            switch (LOWORD(wParam))
            {
            case IDC_BUTTON1:
                MessageBox(hDlg, L"ONDragon", L"ONDragon", MB_OK);
                break;
            default:
                break;
            }
        default:
            return DefWindowProc(hDlg, uMsg, wParam, lParam);
        }
    
    
        return ret;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
    {
    
        DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, MainProc);
    
        return 0;
    }

  • 相关阅读:
    HDU 1548 A strange lift (Dijkstra)
    HDU 1217 Arbitrage (Floyd)
    HDU 1385 Minimum Transport Cost (Dijstra 最短路)
    考研总结 2016-12-31 20:10 219人阅读 评论(21) 收藏
    归并排序 2016-12-30 20:17 208人阅读 评论(21) 收藏
    docker安装 2016-11-06 19:14 299人阅读 评论(31) 收藏
    Docker初步了解 2016-10-30 20:46 279人阅读 评论(31) 收藏
    [自考]感想 2016-10-23 20:28 261人阅读 评论(32) 收藏
    [自考]C++中一些特殊用法 2016-10-16 22:12 318人阅读 评论(30) 收藏
    Fitnesse批量读取变量信息,并保存到用例执行上下文中
  • 原文地址:https://www.cnblogs.com/DeeLMind/p/6882129.html
Copyright © 2011-2022 走看看