[fpc-pascal]Need Windows Dialog Help
Matt Emson
memsom at interalpha.co.uk
Fri Jan 5 13:47:20 CET 2001
If you want to create a dialog (i.e. traditional windows dialog) you'll need
to create a resource file containing the windows resource information.. I believe
it is possible to do this programatically, but I don't know how easy it is to
do so. There is then a load of win32 API that handles the creation and displaying
of Dialogs. (take a look at CreateDialog for a starter..)
If you mean just a traditional main window.. Have a look at the examples that
come with Borland Pascal/ Turbo pascal for windows (if you still have them.)
Failing that, CreateWindow and CreateWindowEX are good starting points. If you
can read C code, there are some resources out there..
You can probably also just create another window.. in the same way as below.
Hope that helps (and isn't off at a tangent)
Matt
//Cut here
/////////////////////////////////////////////////////////////
program testa;
uses
Windows, messages, sysutils;
var
C: TWndCLass;
Handle: HWND;
Msg: TMsg;
const
AppName: array[0..10] of Char = 'My App';
function WindProc(HWnd: HWND; Msg: UINT;
wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
WindProc := 0;
case Msg of
WM_DESTROY:
begin
PostQuitMessage(0);
WindProc := 1;
end
else
WindProc := DefWindowProc(HWnd,Msg,WParam,LParam);
end;
end;
begin
with C do begin
style := CS_VREDRAW or CS_HREDRAW;
{$IFDEF FPC}
lpfnWndProc := WndProc(@WindProc); //must do this in FPC (well you did
//in V1.00)
{$ELSE}
lpfnWndProc := @WindProc; //Delphi 5 uses the standard pascal
//windows model
{$ENDIF}
cbClsExtra := 0;
cbWndExtra := 0;
C.hInstance := HInstance;
hIcon := LoadIcon(HInstance,IDI_APPLICATION);
hCursor := LoadCursor(HInstance,IDC_ARROW);
hbrBackground := GetStockObject(LTGRAY_BRUSH);
lpszMenuName := nil;
lpszClassName:= @AppName;
end;
RegisterClass(C);
Handle := CreateWindow(@AppName,'Whatever...',
WS_OVERLAPPEDWINDOW or WS_TABSTOP,
LongInt(CW_USEDEFAULT), LongInt(CW_USEDEFAULT), 160, 180,
0,0,HInstance,nil);
//show window..
ShowWindow(Handle,SW_NORMAL);
UpdateWindow(Handle);
//AddButton(Handle);
while GetMessage(Msg,0,0,0) do begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end.
////////////////////////////////////////////////////////
//Cut here
> If anyone has a small program example of dialog box processing,
>I would appreciate getting it. All I want to do is present
>to the Windows user a box where he or she can enter a text
>string. (This string will be used as a search key.) The
>box should contain OK and CANCEL buttons.
More information about the fpc-pascal
mailing list