[英]How to make editable TextBox with WinAPI?
我刚从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
消息。
您的光标停留在工字梁上,因为您没有在窗口类中设置光标。 您从中学到的参考没有显示将光标设置为LoadCursor(NULL, IDC_ARROW)
并将图标设置为LoadIcon(NULL, IDI_APPLICATION)
的基本窗口类注册?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.