winhello.pp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. UpdateWindow(hWindow);
  70. end;
  71. Result := hWindow;
  72. end;
  73. var
  74. AMessage: Msg;
  75. hWindow: HWnd;
  76. begin
  77. if not WinRegister then begin
  78. MessageBox(0, 'Register failed', nil, mb_Ok);
  79. Exit;
  80. end;
  81. hWindow := WinCreate;
  82. if longint(hWindow) = 0 then begin
  83. MessageBox(0, 'WinCreate failed', nil, mb_Ok);
  84. Exit;
  85. end;
  86. while GetMessage(@AMessage, 0, 0, 0) do begin
  87. TranslateMessage(AMessage);
  88. DispatchMessage(AMessage);
  89. end;
  90. Halt(AMessage.wParam);
  91. end.
  92. {
  93. $Log$
  94. Revision 1.2 2001-09-04 01:08:09 carl
  95. * bugfix of range check errors (bug #1588)
  96. + added win32 types for easier porting to win64
  97. Revision 1.1 2001/05/03 21:39:34 peter
  98. * moved to own module
  99. Revision 1.2 2000/07/13 11:33:10 michael
  100. + removed logs
  101. }