gpt4 book ai didi

c++ - 如何使用 WinAPI 制作可编辑的文本框?

转载 作者:行者123 更新时间:2023-11-28 00:42:43 25 4
gpt4 key购买 nike

我刚从 Winforms 切换过来,一切对我来说都太难了。我面临一个又一个问题。下一个,是...

#ifndef ActivationWindow_h
#define ActivationWindow_h

#include <windows.h>

class ActivationWindow
{
static HWND main_wnd;
static HWND lbl_login_desc;
static HWND txt_login;

public:
static void CreateWnd()
{
MSG msg = { 0 };
WNDCLASS wc = { 0 };
wc.lpfnWndProc = WndProc;
wc.hInstance = GetModuleHandle(NULL);
wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
wc.lpszClassName = "actwnd";

if(!RegisterClass(&wc))
return;

if(!(main_wnd = CreateWindow(wc.lpszClassName, "Program activation", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 640, 480, 0, 0, wc.hInstance, NULL)))
return;

lbl_login_desc = CreateWindow("static", "ST_U", WS_CHILD | WS_VISIBLE | WS_TABSTOP, 10, 10, 50, 20, main_wnd, (HMENU)(501), wc.hInstance, NULL);
SetWindowText(lbl_login_desc, "Login: ");

txt_login = CreateWindow("edit", "", WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_LEFT | WS_BORDER, 70, 10, 50, 20, main_wnd, (HMENU)(502), wc.hInstance, NULL);

while(GetMessage(&msg, NULL, 0, 0) > 0)
DispatchMessage( &msg );
}

static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_CLOSE:
PostQuitMessage(0);
break;

default:
return DefWindowProc(hWnd, message, wParam, lParam);
}

return 0;
}
};

HWND ActivationWindow::main_wnd = NULL;
HWND ActivationWindow::lbl_login_desc = NULL;
HWND ActivationWindow::txt_login = NULL;

#endif ActivationWindow_h

当显示窗口时,我无法在 TextBox 中输入任何字符。怎么做?

此外,如果我将鼠标指针移到那个 TextBox,它会变成“I”,如果我将鼠标移到窗口外,鼠标指针仍然是“I”,而不是箭头。我该如何解决?

我看到了一些与此相关的问题,但是那个人告诉他他禁用了 DirectInput 8 并且一切正常。我不知道我在用什么...

最佳答案

您需要在消息循环中调用 TranslateMessage 否则将不会生成 WM_CHAR 消息。

您的光标保持为 I-Beam,因为您没有在窗口类中设置光标。您从哪个引用资料中学到的没有显示将光标设置为 LoadCursor(NULL, IDC_ARROW) 并将图标设置为 LoadIcon(NULL, IDI_APPLICATION) 的基本窗口类注册>?

关于c++ - 如何使用 WinAPI 制作可编辑的文本框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17972978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com