zoukankan      html  css  js  c++  java
  • win32 inputbox

    #define ID_INPUTEDIT 1001
    #define ID_OK 1002
    
    LRESULT CALLBACK inputBoxWndProc(HWND wndHandle, UINT message, WPARAM wParam, LPARAM lParam)
    {    
        static char **result = 0;
        static HWND inputLabelHandle = 0;
        static HWND inputHandle = 0;    
        
        switch (message)
        {
        case WM_NCCREATE:
            result = ((CREATESTRUCT *)lParam)->lpCreateParams;        
            break;
        
        case WM_CLOSE:
        case WM_DESTROY:    
            PostQuitMessage(0);
            break;
        
        case WM_COMMAND:    
            int notifyCode = HIWORD(wParam);    
            int controlId = LOWORD(wParam);    
            HWND controlHandle = (HWND)lParam;    
            
            switch (controlId)
            {
            case ID_INPUTEDIT:    
                inputHandle = controlHandle;
                break;
                
            case ID_OK:
                *result = malloc(256);
                GetWindowText(inputHandle, *result, 256);
                PostQuitMessage(0);
                break;
            }
            break;
        }
        
        return DefWindowProc(wndHandle, message, wParam, lParam);
    }
     
    char *inputbox(char *hint)
    {
    #define X 5
    #define OKBUTTON_WIDTH 75
    #define INPUTEDIT_WIDTH (width0 - OKBUTTON_WIDTH)
    #define INPUTEDIT_Y 29
    #define HINT_HEIGHT 24
    #define CHAR_WIDTH 8
        HWND dialogHandle, inputLabelHandle, inputHandle, okButtonHandle;
        char *result;
        WNDCLASS wndClass;
        int hint_width = strlen(hint) * CHAR_WIDTH,
            width0 = hint_width + OKBUTTON_WIDTH,
            height = HINT_HEIGHT + INPUTEDIT_Y + 50;
        MSG msg;
        
        ZeroMemory(&wndClass, sizeof wndClass);
        wndClass.hCursor = LoadCursor(0, IDC_ARROW);
    //    WndClass.hIcon = LoadIcon(0, IDI_APPLICATION);
    //    wndClass.cbSize = sizeof wndClass;
        wndClass.style = CS_HREDRAW | CS_VREDRAW;
        wndClass.lpfnWndProc = inputBoxWndProc;
        wndClass.hbrBackground = (HBRUSH)COLOR_WINDOWFRAME;
        wndClass.lpszClassName = "InputBox";
        wndClass.hInstance = GetModuleHandle(0);
    
        RegisterClass(&wndClass);
        
        dialogHandle = CreateWindow(
            wndClass.lpszClassName, "Bilibili弹幕反查用户工具", WS_OVERLAPPEDWINDOW,
            100, 100, width0 + 50, height,
            0, 0, wndClass.hInstance, &result);
    
        inputLabelHandle = CreateWindow(
            "STATIC", hint, WS_CHILD | WS_VISIBLE,
            X, 5, hint_width, HINT_HEIGHT,
            dialogHandle, 0, wndClass.hInstance, 0);
    
        inputHandle = CreateWindow(
            "EDIT", "", WS_BORDER | WS_CHILD | WS_VISIBLE,
            X, INPUTEDIT_Y, INPUTEDIT_WIDTH, 24,
            dialogHandle, (HMENU)ID_INPUTEDIT, wndClass.hInstance, 0);
    
        okButtonHandle = CreateWindow(
            "BUTTON", "确定", WS_CHILD | WS_VISIBLE,
            X + INPUTEDIT_WIDTH + 5, INPUTEDIT_Y, OKBUTTON_WIDTH, 24,
            dialogHandle, (HMENU)ID_OK, wndClass.hInstance, 0);
        
        if(dialogHandle == 0)
            return 0;
     
        // 在桌面显示窗口
        ShowWindow(dialogHandle, SW_SHOWNORMAL);
     
        // 刷新窗口客户区
        UpdateWindow(dialogHandle);
     
        do
        {        
            if (GetMessage(&msg, 0, 0, 0))    
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        } while (msg.message != WM_QUIT);
     
        return result;
    }
     
  • 相关阅读:
    网络基础
    模块和包的介绍与使用
    PHP 接口输出 图片
    Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the
    dedeCMS 两个站共用同一个数据库 图片路径统一
    写入文件_调试方法
    Mysql触发器 使用示例
    部署GitLab遇到的问题记录
    防火墙对nginx服务器有影响
    更新yum源并重建缓存
  • 原文地址:https://www.cnblogs.com/ageane/p/inputbox.html
Copyright © 2011-2022 走看看