home *** CD-ROM | disk | FTP | other *** search
/ PC Format Collection 48 / SENT14D.ISO / tech / delphi / disk15 / generic.pak / GENERIC.DPR next >
Encoding:
Text File  |  1995-08-24  |  2.1 KB  |  104 lines

  1. program Generic;
  2.  
  3. {$R GENERIC}
  4.  
  5. uses WinTypes, WinProcs, Messages;
  6.  
  7. const
  8.   AppName = 'Generic';
  9.  
  10. const
  11.   idm_About = 100;
  12.  
  13. function About(Dialog: HWnd; Message, WParam: Word;
  14.   LParam: Longint): Bool; export;
  15. begin
  16.   About := True;
  17.   case Message of
  18.     wm_InitDialog:
  19.       Exit;
  20.     wm_Command:
  21.       if (WParam = id_Ok) or (WParam = id_Cancel) then
  22.       begin
  23.         EndDialog(Dialog, 1);
  24.         Exit;
  25.       end;
  26.   end;
  27.   About := False;
  28. end;
  29.  
  30. function WindowProc(Window: HWnd; Message, WParam: Word;
  31.   LParam: Longint): Longint; export;
  32. var
  33.   AboutProc: TFarProc;
  34. begin
  35.   WindowProc := 0;
  36.   case Message of
  37.     wm_Command:
  38.       if WParam = idm_About then
  39.       begin
  40.         AboutProc := MakeProcInstance(@About, HInstance);
  41.         DialogBox(HInstance, 'AboutBox', Window, AboutProc);
  42.         FreeProcInstance(AboutProc);
  43.         Exit;
  44.       end;
  45.     wm_Destroy:
  46.       begin
  47.         PostQuitMessage(0);
  48.         Exit;
  49.       end;
  50.   end;
  51.   WindowProc := DefWindowProc(Window, Message, WParam, LParam);
  52. end;
  53.  
  54. procedure WinMain;
  55. var
  56.   Window: HWnd;
  57.   Message: TMsg;
  58. const
  59.   WindowClass: TWndClass = (
  60.     style: 0;
  61.     lpfnWndProc: @WindowProc;
  62.     cbClsExtra: 0;
  63.     cbWndExtra: 0;
  64.     hInstance: 0;
  65.     hIcon: 0;
  66.     hCursor: 0;
  67.     hbrBackground: 0;
  68.     lpszMenuName: AppName;
  69.     lpszClassName: AppName);
  70. begin
  71.   if HPrevInst = 0 then
  72.   begin
  73.     WindowClass.hInstance := HInstance;
  74.     WindowClass.hIcon := LoadIcon(0, idi_Application);
  75.     WindowClass.hCursor := LoadCursor(0, idc_Arrow);
  76.     WindowClass.hbrBackground := GetStockObject(white_Brush);
  77.     if not RegisterClass(WindowClass) then Halt(255);
  78.   end;
  79.   Window := CreateWindow(
  80.     AppName,
  81.     'Delphi Generic',
  82.     ws_OverlappedWindow,
  83.     cw_UseDefault,
  84.     cw_UseDefault,
  85.     cw_UseDefault,
  86.     cw_UseDefault,
  87.     0,
  88.     0,
  89.     HInstance,
  90.     nil);
  91.   ShowWindow(Window, CmdShow);
  92.   UpdateWindow(Window);
  93.   while GetMessage(Message, 0, 0, 0) do
  94.   begin
  95.     TranslateMessage(Message);
  96.     DispatchMessage(Message);
  97.   end;
  98.   Halt(Message.wParam);
  99. end;
  100.  
  101. begin
  102.   WinMain;
  103. end.
  104.