Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2001-01

Need Windows Dialog Help

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Krall Ed-P27726

Hi.

I have an application that I first built (years ago) with Borland Pascal and the Object Windows Library. I am trying to convert it to Free Pascal. I am NOT an expert in the Windows API, and programming is not my main job....

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.

I have Windows Help, but could really use a sample program.

Thanks in advance.

Ed

 ________________________________________________________ | Edward J. Krall             |     | | Motorola - IISG             | (480)441-0026            | | ISSPD Secure Products       | (480)441-8377 - Fax      | | Mail Stop R1209             | PageNet: (602)779-8373   | | 8220 East Roosevelt Road    |          (800)6-PageMe   | | Scottsdale, AZ 85252-1417   |   | |_____________________________|__________________________|

Matt Emson

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
Show quoted text 5 lines
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.
Jo
to Matt Emson
program testa; uses Windows, messages, sysutils;

....

I tried to compile it under FPC/Win32: the messages unit doesn't exist with FPC, but the program compiles when you remove it from the uses clause -->

program testa;
uses
   Windows, sysutils;
....

Best Regards.
IoDream (as Joel THIEFFRY).

______________________________________________________________________________ ifrance.com, l'email gratuit le plus complet de l'Internet ! vos emails depuis un navigateur, en POP3, sur Minitel, sur le WAP... http://www.ifrance.com/_reloc/email.emailif

Marco van de Voort
to Jo
Show quoted text 12 lines
> program testa; > uses > Windows, messages, sysutils; .... I tried to compile it under FPC/Win32: the messages unit doesn't exist with FPC, but the program compiles when you remove it from the uses clause --> program testa; uses Windows, sysutils;

IIRC, the Delphi 4 messages unit compiles under FPC.