Board index » delphi » WinMain (API) function - can't find the Delphi Unit

WinMain (API) function - can't find the Delphi Unit

I want to write a Delphi Project without any VLC-Component, so
I removed the Unit and started to write in the project code.

To create a main window, win32 help file reads, use the WinMain function:
_____________________________________________________________
program Wind;

uses Messages, Windows, Sysutils;

var p: PChar

begin
  WinMain(HInstance,  0, p , SW_SHOWMAXIMIZED);
end.
_______________________________________________________________
......But the WinMain command doesn't exist or isn't found!

Q.: In which Unit is this function included?
Q.: What shall I do to create a main window myself?

DOMI :-)
--
______________________________________
Visit the coolTOOL site at
http://ycom.or.at/~schnitzer
for Delphi and DirectX Infos and Examples
DOMI :-)

 

Re:WinMain (API) function - can't find the Delphi Unit


Quote
Dominik Schnitzer wrote:

> I want to write a Delphi Project without any VLC-Component, so
> I removed the Unit and started to write in the project code.

> To create a main window, win32 help file reads, use the WinMain function:
> _____________________________________________________________
> program Wind;

> uses Messages, Windows, Sysutils;

> var p: PChar

> begin
>   WinMain(HInstance,  0, p , SW_SHOWMAXIMIZED);
> end.
> _______________________________________________________________
> ......But the WinMain command doesn't exist or isn't found!

> Q.: In which Unit is this function included?
> Q.: What shall I do to create a main window myself?

> DOMI :-)
> --
> ______________________________________
> Visit the coolTOOL site at
> http://ycom.or.at/~schnitzer
> for Delphi and DirectX Infos and Examples
> DOMI :-)

The following code snippet demonstrates creating a
traditional generic windows application.

The code also demonstrates coding techniques
for creating applications that are portable
between compilers and operating systems.

The following Borland Pascal based languages
can be used to compile the project:

* Turbo Pascal For Windows
* Borland Pascal
* Delphi 1
* Delphi 2

program Generic;

{$D Generic}

{$C MOVEABLE PRELOAD PERMANENT}

(*

To compile for 16 bit Windows:
Place the following resource script in a text file
named GEN16.RC, and compile with the Borland Resource
Compiler located in Delphi's BIN Directory "BRCC.EXE",
or any Windows Resource Editor.

To compile for 32 bit Windows:
Place the following resource script in a text file
named GEN32.RC, and compile with the Borland Resource
Compiler located in Delphi's BIN Directory "BRCC32.EXE",
or any 32 bit Windows Resource Editor.

GENERIC MENU
BEGIN
  POPUP "&Help"
  BEGIN
  MENUITEM "&About Generic...", 100
 END
END

ABOUTBOX DIALOG 10, 35, 144, 88
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About Generic"
FONT 8, "System"
BEGIN
  CONTROL "&OK", 1, "BUTTON", BS_PUSHBUTTON | WS_CHILD | WS_VISIBLE |
WS_TABSTOP, 53, 66, 38, 15
  CONTROL "Generic Application", 102, "STATIC", SS_CENTER | WS_CHILD |
WS_VISIBLE, 35, 20, 75, 9
  CONTROL "Delphi Demo", 103, "STATIC", SS_CENTER | WS_CHILD |
WS_VISIBLE, 30, 10, 85, 10
  CONTROL "Copyright \251 1996", 104, "STATIC", SS_CENTER | WS_CHILD |
WS_VISIBLE, 35, 39, 71, 10
  CONTROL "Borland International", 105, "STATIC", SS_CENTER | WS_CHILD |
WS_VISIBLE, 37, 49, 70, 10
END

*)

{$IFDEF Win32}
  {$R GEN32.RES}
  uses
    Windows, Messages;
  type
    TwMsg = Longint;
    TwParam = Longint;
    TlParam = Longint;
{$ELSE}
  {$R GEN16.RES}
  uses
{$IFDEF VER15}
    WinTypes, WinProcs, Win31;
{$ELSE}
{$IFDEF VER70}
    WinTypes, WinProcs, Win31;
{$ELSE}
    WinTypes, WinProcs, Messages;
{$ENDIF}
{$ENDIF}
  type
    TwMsg = Word;
    TwParam = Word;
    TlParam = Longint;
{$ENDIF}

const
  APPNAME = 'GENERIC';
  CLASSNAME = 'GENERICCLASS';
  IDM_ABOUT = 100;

function About(Dialog: HWnd;
               Msg: TwMsg;
               WParam: TwParam;
               LParam: TlParam): Longbool
              {$IFDEF Win32} stdcall; {$ELSE} ; export; {$ENDIF}
begin
  About := True;
  case Msg of
    wm_Command:
      if (WParam = id_Ok) or (WParam = id_Cancel) then begin
        EndDialog(Dialog, WParam);
        Exit;
      end;
  end;
  About := False;
end;

function WindowProc(Window: HWnd;
                    Msg: TwMsg;
                    WParam: TwParam;
                    LParam: TlParam): Longint
                    {$IFDEF Win32} stdcall; {$ELSE} ; export; {$ENDIF}
var
  AboutProc: TFarProc;
begin
  WindowProc := 0;
  case Msg of
    WM_COMMAND:
    if WParam = IDM_ABOUT then begin
      AboutProc := MakeProcInstance(@About, HInstance);
      DialogBox(HInstance, 'AboutBox', Window, AboutProc);
      FreeProcInstance(AboutProc);
      Exit;
    end;
    WM_DESTROY: begin
      PostQuitMessage(0);
      Exit;
    end;
  end;
  WindowProc := DefWindowProc(Window, Msg, WParam, LParam);
end;

procedure WinMain;
var
  WindowClass: TWndClass;
  Window: HWnd;
  Msg: TMsg;
begin
  if hPrevInst = 0 then begin
    WindowClass.Style         := CS_BYTEALIGNWINDOW;
    WindowClass.lpfnWndProc   := @WindowProc;
    WindowClass.cbClsExtra    := 0;
    WindowClass.cbWndExtra    := 0;
    WindowClass.hInstance     := hInstance;
    WindowClass.hIcon         := LoadIcon(0, IDI_APPLICATION);
    WindowClass.hCursor       := LoadCursor(0, IDC_ARROW);
    WindowClass.hbrBackground := GetStockObject(WHITE_BRUSH);
    WindowClass.lpszMenuName  := APPNAME;
    WindowClass.lpszClassName := CLASSNAME;
    if not Bool(RegisterClass(WindowClass)) then begin
      Messagebox(0,
                 'RegisterClass Failed!',
                 APPNAME,
                 MB_OK);
      halt;
    end;
  end;
  Window := CreateWindow(CLASSNAME,
                         APPNAME,
                         WS_OVERLAPPEDWINDOW,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         CW_USEDEFAULT,
                         0,
                         0,
                         hInstance,
                         nil);
  ShowWindow(Window, CmdShow);
  UpdateWindow(Window);
  while GetMessage(Msg, 0, 0, 0) do begin
    TranslateMessage(Msg);
    DispatchMessage(Msg);
  end;
  halt(Msg.wParam);
end;

{WinMain}
begin
  WinMain;
end.

Joe
--
Joe C. Hecht
(Borland Delphi Developer Support)
Join the Delphi Online Discussion Forum at
http://www.borland.com/techsupport/delphi/

Other Threads