0

我刚从 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 中输入任何字符。怎么做?

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

我看到一些关于此的问题,但那个人告诉他禁用了 DirectInput 8,一切都解决了。我不知道我用的是什么...

4

1 回答 1

3

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

您的光标保持为 I-Beam,因为您没有在窗口类中设置光标。您从中学到的什么参考没有显示将光标设置为LoadCursor(NULL, IDC_ARROW)并将图标设置为的基本窗口类注册LoadIcon(NULL, IDI_APPLICATION)

于 2013-07-31T14:36:30.633 回答