Warning: file_get_contents(https://whois.pconline.com.cn/jsLabel.jsp?ip=127.0.0.1) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 503 Service Temporarily Unavailable in D:\wwwroot\huidong\wwwroot\function.inc.php on line 884
win32应用程序模版 - huidong

huidong

首页 | 会员登录 | 关于争取 2022 寒假做出汇东网 Ver3.0.0 !
搜索文章


win32 入口

int WINAPI WinMain(HINSTANCE hThisInst,
    HINSTANCE hPrevInst,
    LPSTR lpszCmdLine,
    int nCmdShow)
{

---

#include <windows.h>

#define IDC_EDIT 100
#define IDC_BTN 101


LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    static HINSTANCE hInstance = GetModuleHandle(0);
    static HWND hEdit;
    static HWND hBtn;

    switch (msg)
    {
    case WM_CREATE:

            // 创建一个输入框,一个按钮
            hEdit = CreateWindow(L"edit", L"Edit at here.",
                WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER,
                130, 50, 200, 20,
                hwnd, (HMENU)IDC_EDIT, hInstance, NULL);
            
            hBtn = CreateWindow(L"button", L"Click Me!",
                WS_CHILD | WS_VISIBLE | ES_LEFT | WS_BORDER,
                330, 50, 100, 20,
                hwnd, (HMENU)IDC_BTN, hInstance, NULL);

        break;

    case WM_COMMAND:

        switch (LOWORD(wParam))
        {

            // 按下按钮
        case IDC_BTN:

            if (true)
            {
                wchar_t str[128] = { 0 };

                // 得到输入框文本
                GetWindowText(hEdit, str, 512);
                MessageBox(hwnd, str, L"your input", MB_OK);
            }

            break;
        }

        break;
    
    case WM_CLOSE:
        DestroyWindow(hwnd);
        PostQuitMessage(NULL);
        exit(0);
        break;
    }

    return DefWindowProc(hwnd, msg, wParam, lParam);
}

// 快速新建窗口
void initwindow(int w, int h, int mode, LRESULT(_stdcall* WindowProcess)(HWND, UINT, WPARAM, LPARAM), LPCTSTR strWndTitle)
{
    // 窗口类
    WNDCLASSEX WndClassEx;
    MSG Msg;

    // 隐藏cmd
    if (mode == 0)
        ShowWindow(GetConsoleWindow(), SW_HIDE);

    // 填写结构体
    WndClassEx.cbSize = sizeof(WNDCLASSEX);
    WndClassEx.style = CS_VREDRAW | CS_HREDRAW;
    WndClassEx.lpfnWndProc = WindowProcess;
    WndClassEx.cbClsExtra = 0;
    WndClassEx.cbWndExtra = 0;
    WndClassEx.hInstance = GetModuleHandle(0);
    WndClassEx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    WndClassEx.hCursor = LoadCursor(NULL, IDC_ARROW);
    WndClassEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    WndClassEx.lpszMenuName = NULL;
    WndClassEx.lpszClassName = strWndTitle;
    WndClassEx.hIconSm = NULL;

    // 注册窗口类
    RegisterClassEx(&WndClassEx);

    // 创建窗口
    HWND hWnd = CreateWindowEx(WS_EX_WINDOWEDGE, strWndTitle, strWndTitle, WS_OVERLAPPEDWINDOW, 200, 200, w, h, NULL, NULL, GetModuleHandle(0), NULL);

    // 显示窗口
    ShowWindow(hWnd, SW_SHOWNORMAL);

    // 更新窗口
    UpdateWindow(hWnd);

    // 循环获得消息
    while (GetMessage(&Msg, NULL, NULL, NULL))
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
}


int main()
{
    initwindow(640, 480, 0, WndProc, L"mywnd");
    return 0;
}




返回首页


Copyright (C) 2018-2024 huidong