views:

82

answers:

3

Working with Visual Studio 6 (VC++ 6.0) I'm using an ActiveX datepicker control which I fail to show expanded by default (3006216). Alternatively I'm trying to send a keyboard message (F4) to my window to open up the control, but nothing happens when I do so...

// try 1: use the standard window handle
LRESULT result = ::SendMessage(m_hWnd,VK_F4, 0, 0);
// try 2: use just use the SendMessage
result = SendMessage(VK_F4);

result is always 0 - what can I do to test/verify the message sending?

Thanks in acvance a lot...

Olli

A: 

VK_F4 is a key code, not a window message. Try this:

::SendMessage(m_hWnd, WM_KEYDOWN, VK_F4, 0);
::SendMessage(m_hWnd, WM_KEYUP, VK_F4, 0);
Nick D
Hm, thanks for your help. Unfortunately nothing has changed in the window's behaviour, sorry!
Olli
@Olli, check my edit. I didn't test the code, maybe a `WM_KEYDOWN` is also required.
Nick D
@ Nick D: no improvement - any more ideas...?
Olli
A: 

Check out: "You can't simulate keyboard input with PostMessage"

humbagumba
Thanks for the hint!
Olli
A: 

Okay - there's two approaches on this issue (thanks for all the help, guys!):

First: Use "::SendMessage" with correct message AND correct handle:

::SendMessage(m_wndDatePicker.m_hWnd, WM_KEYDOWN, VK_F4, 0);

Alternatively use "SendInput":

// important: set focus to control first    
m_wndDatePicker.SetFocus(); 

INPUT *key;

key = new INPUT;
key->type = INPUT_KEYBOARD;
key->ki.wVk = VK_F4;
key->ki.dwFlags = 0;
key->ki.time = 0;
key->ki.wScan = 0;
key->ki.dwExtraInfo = 0;

SendInput(1,key,sizeof(INPUT));
Olli