Author: Tomas Rutkauskas
I would like to control the pageup event of a TListBox by
listbox1keydown(self,vk_next,[]); , but it produces an error message. Why?
Answer:
Calling the onKeyDown event handler directly accomplishes nothing. To make the
control scroll you have to send either the key or a scroll message to the control
itself. For the key that would take the following form:
1
2 procedure PostKey(hWindow: HWND; key: Word);
3 begin
4 if IsWindow(hWindow) then
5 begin
6 PostMessage(hWindow, WM_KEYDOWN, key, MakeLong(0, MapVirtualKey(key, 0)));
7 PostMessage(hWindow, WM_KEYUP, key, MakeLong(0, MapVirtualKey(key, 0) or
8 $C0000000));
9 end;
10 end;
11
12 PostKey(listbox.handle, VK_NEXT);
Since PostKey puts the messages into the message loop they will not get processed
unless your code falls back to the message loop or calls
Application.ProcessMessages. You could replace the PostMessage with a SendMessage
in this case since the key yields no character.
Sending a scroll message directly would look like this:
13
14 listbox.perform(WM_VSCROLL, SB_PAGEDOWN, 0);
15 listbox.perform(WM_VSCROLL, SB_ENDSCROLL, 0);
|