簡體   English   中英

如何使用WinAPI制作可編輯的TextBox?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM