Ok thanks, I seem to have some issues with the SendMessage function using
the UDM_GETBUDDY message, is there anything obvious I am doing wrong in my
code? (I'm using csharp)
public const UInt32 WM_USER = 0x0400;
public const UInt32 EM_SETSEL = 0x00B1;
public const UInt32 UDM_GETBUDDY = (WM_USER+106);
[DllImport("coredll.dll", SetLastError=true)]
private extern static IntPtr GetCapture();
[DllImport("coredll.dll", EntryPoint="SendMessage", SetLastError=true)]
private extern static IntPtr SendMessage(IntPtr hWnd, UInt32 nMsg, Int32
wParam,
Int32 lParam);
private void SelectText( NumericUpDown ctrl )
{
ctrl.Capture = true;
IntPtr hWndCtrl = GetCapture();
ctrl.Capture = false;
IntPtr hWndBuddy = SendMessage(hWndCtrl, UDM_GETBUDDY, 0, 0);
SendMessage(hWndBuddy, EM_SETSEL, 0, -1); // Select all text
}
The problem seem to start with the GetCapture function. The result from it
doesn't match the m_hwn value of the NumUpDown control, when I take a
"QuickLook". The fact I am using an IntPtr could the reason for this.
Atleast GetCapture returns a valid value.
The second problem is that SendMessage with UDM_GETBUDDY returns 0. I am not
sure I have done a correct implementation of SendMessage wrapper...
thanks,
Peter
PS 0 and -1 in SendMessage with EM_SETSEL means selecting all text according
to the SDK docs. DS
Alex Feinman said:
Numeric Up/Down control is a combination of two controls. There is a real
edit control inside it. Try getting its hWnd (as usually Capture/GetCapture)
and then sending it UDM_GETBUDDY to obtain hWnd of the edit control. Then
you can send it EM_SETSEL. Haven't tried it myself, but it should work