0
我刚刚从Winforms切换,一切对我来说都很难。我面临着一个又一个问题。下一个,是...如何用WinAPI制作可编辑的TextBox?
#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中输入任何字符。怎么做?另外,如果我将鼠标指针移动到该文本框,它将变成“I”,如果我将鼠标移动到窗口,鼠标指针仍然是“I”,而不是箭头。 我该如何解决这个问题?
我看到一些关于这方面的问题,但是那个人告诉他禁用了DirectInput 8并且一切都解决了。我不知道我在用什么...
请问你能说哪里?有很多地方... – Kosmos
我确实说过...在消息循环里面。 'while(GetMessage ...'part is the message loop。 – Joel
我的意思是在哪里xactly?我可以在DispatchMessage之前调用它(&msg);,之后或WndProc内部)在很多情况下或默认情况下...我真的不明白它是如何工作的 – Kosmos