Kosmo零
Kosmo零

Reputation: 4151

How to make editable TextBox with WinAPI?

I just switched from Winforms and everything looks so hard for me. I facing one problem after another. The next one, is...

#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

When window is shown, I can't type any characters into TextBox. How to do it?

Also, if I move mouse pointer to that TextBox it becomes "I", if I move mouse out to the window, the mouse pointer is still "I", instead of arrow. how do I fix that?

I see some questions regarding that, but the guy telling he disabled DirectInput 8 and everything worked out. i don't know what I using...

Upvotes: 0

Views: 1838

Answers (1)

Joel
Joel

Reputation: 1145

You need to call TranslateMessage in your message loop or WM_CHAR messages won't be generated.

Your cursor stays an I-Beam because you aren't setting the cursor in your window class. What reference are you learning from that doesn't show the basic window class registration that sets the cursor to LoadCursor(NULL, IDC_ARROW) and the icon to LoadIcon(NULL, IDI_APPLICATION)?

Upvotes: 3

Related Questions