Question

I created an up-down control by the following code.

HWND hEdit, hUpDown;

hEdit = CreateWindowExW(WS_EX_CLIENTEDGE,
                        L"EDIT",
                        Content.c_str(),
                        ES_LEFT | WS_VISIBLE | WS_CHILD,
                        600,
                        260,
                        100,
                        25,
                        hWndParent,
                        NULL,
                        hInstance,
                        NULL);

INITCOMMONCONTROLSEX iccx;
iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
iccx.dwICC  = ICC_UPDOWN_CLASS;
InitCommonControlsEx(&iccx);

hUpDown = CreateWindowExW(  0,
                            UPDOWN_CLASSW,
                            L"",
                            UDS_ARROWKEYS | UDS_ALIGNRIGHT | WS_VISIBLE | WS_CHILD,
                            0,
                            0,
                            0,
                            0,
                            hWndParent,
                            NULL,
                            hInstance,
                            NULL);

SendMessageW(hUpDown, UDM_SETBUDDY,   (WPARAM) hEdit, (LPARAM) NULL);
SendMessageW(hUpDown, UDM_SETRANGE32, (WPARAM) 0,     (LPARAM) 100);
Sleep(5000);
SendMessageW(hUpDown, UDM_SETPOS32,   (WPARAM) NULL,  (LPARAM) 20);
Sleep(5000);
SendMessageW(hUpDown, UDM_SETPOS32,   (WPARAM) NULL,  (LPARAM) 60);

I checked the return values of the SendMessageW() functions. They terminate successfully by returning the previous position value as documented.

The created up-down control looks normal:
the created up-down control

The problem is, sending the UDM_SETPOS32 message, clicking the up and down arrows and pressing the up and down keys on the keyboard have no effect. I can't change the contents of the edit control (the buddy window of the up-down control) without directly typing something into it. It just stays empty.

I am able to type anything in it manually by using keyboard:
example text input

How do I change the position/value of this up-down control by pressing keyboard arrow keys, by clicking the arrows in the GUI and by sending UDM_SETPOS32 in the code? What am I missing in my code?

Was it helpful?

Solution

Use the style UDS_SETBUDDYINT to the up-down control while creating it.

From MSDN documentation:

UDS_SETBUDDYINT
Causes the up-down control to set the text of the buddy window (using the WM_SETTEXT message) when the position changes. The text consists of the position formatted as a decimal or hexadecimal string.

Change the creation code of the up-down control like this by adding the UDS_SETBUDDYINT style:

hUpDown = CreateWindowExW(  0,
                            UPDOWN_CLASSW,
                            L"",
                            UDS_SETBUDDYINT | UDS_ARROWKEYS | UDS_ALIGNRIGHT | WS_VISIBLE | WS_CHILD,
                            0,
                            0,
                            0,
                            0,
                            hWndParent,
                            NULL,
                            hInstance,
                            NULL);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top