I'm trying to build a small-exe program using just API commands. I've
borrowed some code that I got in a Delphi forum previously. What I
can't figure out is how to make the tab key move the focus from one
control to the next. Below is code for a sample form with two buttons
on it. I include a WS_TABSTOP setting in the button's CreateWindow
style parameter but pressing the tab key has no effect. What
adjustments to the code below do I need to make?
program InputAPI;
uses
Windows, Messages;
var
WinClass: TWndClassA;
Inst, Handle, Button1, Button2: Integer;
Msg: TMsg;
hFont: Integer;
{ Custom WindowProc function }
function WindowProc(hWnd,uMsg,wParam,lParam: Integer): Integer; stdcall;
begin
Result := DefWindowProc(hWnd,uMsg,wParam,lParam);
{ Checks for messages }
if uMsg = WM_DESTROY then Halt;
end;
begin
{ ** Register Custom WndClass ** }
Inst:=hInstance;
with WinClass do
begin
style:=CS_CLASSDC or CS_PARENTDC;
lpfnWndProc:=@WindowProc;
hInstance:=Inst;
hbrBackground:=color_btnface + 1;
lpszClassname:='Test';
hCursor:=LoadCursor(0,IDC_ARROW);
end; { with }
RegisterClass(WinClass);
{ ** Create Main Window ** }
Handle:=CreateWindowEx(WS_EX_WINDOWEDGE or WS_EX_CONTROLPARENT,'Test',
'TestWindow',WS_VISIBLE or WS_CAPTION or WS_SYSMENU,
300,200,300,100, 0, 0, Inst, nil);
{ ** Create a button ** }
Button1 := CreateWindow('Button', 'Ok', WS_VISIBLE or WS_CHILD or
WS_TABSTOP
or BS_PUSHLIKE or BS_TEXT, 50, 20, 75,
25,handle,
0, Inst, nil);
Button2 := CreateWindow('Button', 'Cancel', WS_VISIBLE or WS_CHILD or
WS_TABSTOP or BS_PUSHLIKE or BS_TEXT, 150,20,
75,
25, handle, 0, Inst, nil);
{ ** Create Font Handle ** }
hFont := CreateFont(-15, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
DEFAULT_PITCH or FF_DONTCARE, 'MS Sans Serif');
{ Change fonts }
if hFont <> 0 then
begin
SendMessage(Button1, WM_SETFONT, hFont, 0);
SendMessage(Button2, WM_SETFONT, hFont, 0);
end;
SetFocus(Button1);
UpdateWindow(Handle);
{ ** Message Loop ** }
while(GetMessage(Msg,Handle,0,0)) do
begin
TranslateMessage(msg);
DispatchMessage(msg);
end;
end.
--
Kent Briggs, kbri...@briggsoft.com
Briggs Softworks, http://www.briggsoft.com