首页 > 解决方案 > WIN32API C++ 我在编写文本框时遇到问题。无法正确显示文字

问题描述

我是 win32 编程的新手,我只有 13 岁。我试图制作一个文本框,但是在键入它时会导致文本在单击该字段时不可见。有时它会影响菜单。我不知道为什么。

#include <windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
void AddMenus(HWND hwnd);
HWND TextBox;
HMENU hmenu;
#define FIRST 1

int WINAPI wWinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPTSTR args, int ncmdshow) {
    WNDCLASSW wc = {};
    wc.hInstance = hinstance;
    wc.lpfnWndProc = WindowProc;
    wc.hCursor = NULL, IDC_ARROW;
    wc.lpszClassName = L"wnd_class";
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);

    RegisterClassW(&wc);

    MSG msg;

    CreateWindowW(L"wnd_class", L"EXPONOS", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 100, 100, 1000, 500, NULL, NULL, NULL, NULL);

    while (GetMessage(&msg, NULL, NULL, NULL)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);

    }

}

LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    switch (uMsg) {
    case WM_COMMAND:
        switch (wParam) {
        case FIRST:
            MessageBeep(MB_OK);
            MessageBox(NULL, L"EXPONOS GUI 1.0 UNDER CONSTRUCTION\nCopyright (C) Name 2021", L"About", MB_OK);
        }
    case WM_CREATE:
        AddMenus(hwnd);   //I choose NULL becuase if I use L"" it causes the frame to lag
        TextBox = CreateWindowW(L"Edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 0, 0, 500, 500, hwnd, NULL, NULL, NULL);
        break;
    case WM_DESTROY:
        PostQuitMessage(NULL);
        break;
    }
    return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}

标签: c++user-interfacewinapi

解决方案


推荐阅读