winhello.pp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. {
  2. $Id$
  3. Copyright (c) 1996 by Charlie Calvert
  4. Modifications by Florian Klaempfl
  5. Standard Windows API application written in Object Pascal.
  6. No VCL code included. This is all done on the Windows API
  7. level.
  8. }
  9. {$APPTYPE GUI}
  10. {$MODE DELPHI}
  11. program WinHello;
  12. uses
  13. Strings, Windows;
  14. const
  15. AppName = 'WinHello';
  16. function WindowProc(Window: HWnd; AMessage: UINT; WParam : WPARAM;
  17. LParam: LPARAM): LRESULT; stdcall; export;
  18. var
  19. dc : hdc;
  20. ps : paintstruct;
  21. r : rect;
  22. begin
  23. WindowProc := 0;
  24. case AMessage of
  25. wm_paint:
  26. begin
  27. dc:=BeginPaint(Window,@ps);
  28. GetClientRect(Window,@r);
  29. DrawText(dc,'Hello world by Free Pascal',-1,@r,
  30. DT_SINGLELINE or DT_CENTER or DT_VCENTER);
  31. EndPaint(Window,ps);
  32. Exit;
  33. end;
  34. wm_Destroy:
  35. begin
  36. PostQuitMessage(0);
  37. Exit;
  38. end;
  39. end;
  40. WindowProc := DefWindowProc(Window, AMessage, WParam, LParam);
  41. end;
  42. { Register the Window Class }
  43. function WinRegister: Boolean;
  44. var
  45. WindowClass: WndClass;
  46. begin
  47. WindowClass.Style := cs_hRedraw or cs_vRedraw;
  48. WindowClass.lpfnWndProc := WndProc(@WindowProc);
  49. WindowClass.cbClsExtra := 0;
  50. WindowClass.cbWndExtra := 0;
  51. WindowClass.hInstance := system.MainInstance;
  52. WindowClass.hIcon := LoadIcon(0, idi_Application);
  53. WindowClass.hCursor := LoadCursor(0, idc_Arrow);
  54. WindowClass.hbrBackground := GetStockObject(WHITE_BRUSH);
  55. WindowClass.lpszMenuName := nil;
  56. WindowClass.lpszClassName := AppName;
  57. Result := RegisterClass(WindowClass) <> 0;
  58. end;
  59. { Create the Window Class }
  60. function WinCreate: HWnd;
  61. var
  62. hWindow: HWnd;
  63. begin
  64. hWindow := CreateWindow(AppName, 'Hello world program',
  65. ws_OverlappedWindow, cw_UseDefault, cw_UseDefault,
  66. cw_UseDefault, cw_UseDefault, 0, 0, system.MainInstance, nil);
  67. if hWindow <> 0 then begin
  68. ShowWindow(hWindow, CmdShow);
  69. ShowWindow(hWindow, SW_SHOW);
  70. UpdateWindow(hWindow);
  71. end;
  72. Result := hWindow;
  73. end;
  74. var
  75. AMessage: Msg;
  76. hWindow: HWnd;
  77. begin
  78. if not WinRegister then begin
  79. MessageBox(0, 'Register failed', nil, mb_Ok);
  80. Exit;
  81. end;
  82. hWindow := WinCreate;
  83. if longint(hWindow) = 0 then begin
  84. MessageBox(0, 'WinCreate failed', nil, mb_Ok);
  85. Exit;
  86. end;
  87. while GetMessage(@AMessage, 0, 0, 0) do begin
  88. TranslateMessage(AMessage);
  89. DispatchMessage(AMessage);
  90. end;
  91. Halt(AMessage.wParam);
  92. end.
  93. {
  94. $Log$
  95. Revision 1.3 2002-02-22 13:37:49 pierre
  96. * fix problem if started through cygwin bash
  97. Revision 1.2 2001/09/04 01:08:09 carl
  98. * bugfix of range check errors (bug #1588)
  99. + added win32 types for easier porting to win64
  100. Revision 1.1 2001/05/03 21:39:34 peter
  101. * moved to own module
  102. Revision 1.2 2000/07/13 11:33:10 michael
  103. + removed logs
  104. }