Recent

Author Topic: WINAPI functions are working but their output remains invisible  (Read 629 times)

Pieter

  • New Member
  • *
  • Posts: 19
I brought a classical Pascal program (no objects) to Lazarus 2.2.2, running on an Intel i5 laptop under Windows 11 Pro. It gets its user input and output by means of a window created by the WINAPI function CreateWindow and related WINAPI functions. In this way, the program can migrate to another OS by replacing these input and output functions. In Lazarus, this seems to work properly, if you trace the program, however, no output is visible. Below, I inserted a small program that illustrates the problem. The console output shows the effect of the SendMessage command but the intended window is completely absent. What did I miss?

Code: Pascal  [Select][+][-]
  1. program SimpleTest3;
  2. {$mode objfpc}{$H+}
  3.  
  4. uses
  5.   Classes, Windows, Messages, SysUtils ;
  6. const
  7.   MyClassName = 'JustAnotherWindow';
  8.   DefFntSize=12;
  9. type
  10.   Tsem =(dflt,dbg,key_prw);
  11. var
  12. {test specif. vars} i: integer;
  13.   mb_Ok: LongWord;
  14.   ic: integer;
  15.   hWindow: HWnd;
  16.   TheFont1: HFont;
  17.   TheColor: DWORD;
  18.  
  19. function WindowProc(Window: HWnd; AMessage, WParam,
  20.                     LParam: Longint): Longint; stdcall; export;
  21.   var
  22.      dc : hdc;
  23.      ps : Tpaintstruct;
  24.      r : rect;
  25.      bres, speckey:boolean;
  26.      si:integer;
  27.      as2:ansistring;
  28.      sem: Tsem;
  29. begin
  30.   WindowProc := 0; ic:=succ(ic); sem:=dbg;
  31.   case AMessage of
  32.     wm_paint:
  33.       begin
  34.          InvalidateRgn(Window,0,false);
  35.          dc:=BeginPaint(Window,ps);
  36.          case sem of
  37.          dflt:;
  38.          dbg:
  39.            begin
  40.              GetClientRect(Window,@r);
  41.              DrawText(dc,'Hello world by Free Pascal',-1,@r,
  42.              DT_SINGLELINE or DT_CENTER or DT_VCENTER);
  43.              writeln('Best wishes from FP')
  44.           end {dbg};
  45.          key_prw:;
  46.          end {case sem};
  47.          EndPaint(Window,ps);
  48.  
  49.          Exit;
  50.       end;
  51.     wm_Destroy:
  52.       begin
  53.         PostQuitMessage(0);
  54.          Exit;
  55.       end;
  56.   end {case};
  57.   WindowProc := DefWindowProc(Window, AMessage, WParam, LParam);
  58. end;
  59.  
  60. { Register the Window Class }
  61. function WinRegister: Boolean;
  62. var
  63.   WindowClass: WndClass;
  64. begin
  65.   WindowClass.Style := cs_hRedraw or cs_vRedraw;
  66.   WindowClass.lpfnWndProc := WndProc(@WindowProc);
  67.   WindowClass.cbClsExtra := 0;
  68.   WindowClass.cbWndExtra := 0;
  69.   WindowClass.hInstance := system.MainInstance;
  70.   WindowClass.hIcon := LoadIcon(0, idi_Application);
  71.   WindowClass.hCursor := LoadCursor(0, idc_Arrow);
  72.   WindowClass.hbrBackground := GetStockObject(WHITE_BRUSH);
  73.   WindowClass.lpszMenuName := pchar('');
  74.   WindowClass.lpszClassName := MyClassName;
  75.  
  76.   {Result} WinRegister := RegisterClass(WindowClass) <> 0;
  77. end;
  78.  
  79. procedure FontSize(var TLF:TLOGFONT;Height:integer; bold:boolean);
  80. begin
  81.   with TLF do
  82.   begin
  83.     lfHeight         := Height;                // Default logical height of font
  84.     lfWidth          := 0;                // Default logical average character width
  85.     lfEscapement     := 0;                // angle of escapement
  86.     lfOrientation    := 0;                // base-line orientation angle
  87.     if bold then lfWeight:=800 else lfWeight:= FW_NORMAL;        // font weight
  88.     lfItalic         := 0;                // italic attribute flag
  89.     lfUnderline      := 0;                // underline attribute flag
  90.     lfStrikeOut      := 0;                // strikeout attribute flag
  91.     lfCharSet        := DEFAULT_CHARSET;  // character set identifier
  92.     lfOutPrecision   := OUT_DEFAULT_PRECIS;  // output precision
  93.     lfClipPrecision  := CLIP_DEFAULT_PRECIS; // clipping precision
  94.     lfQuality        := DEFAULT_QUALITY;     // output quality
  95.     lfPitchAndFamily := DEFAULT_PITCH;    // pitch and family
  96.     Strcopy(lfFaceName,'Courier New');    // pointer to typeface name string
  97.   end;
  98.   {==}
  99. end {FontSize};
  100.  
  101. function WinCreate: HWnd;
  102. var
  103.   hWaux: HWnd; TheLogFont:TLogFont;
  104.  
  105. begin
  106.   hWaux := CreateWindow(
  107.                         MyClassName, {Defined in WinRegister}
  108.                         'aWindow', {Name of window}
  109.                         ws_OverlappedWindow,  {Style}
  110.                         cw_UseDefault, {X}
  111.                         cw_UseDefault, {Y}
  112.                         cw_UseDefault, {width}
  113.                         cw_UseDefault, {heighth}
  114.                         0, {Parent}
  115.                         0, {Menu}
  116.                         system.MainInstance, {hInstance}
  117.                         nil); {lpVOID}
  118.  
  119.   if hWaux <> 0 then
  120.   begin
  121.     {Selectfont;} FontSize(TheLogFont,DefFntSize,false);
  122.      TheColor := GetSysColor(COLOR_WINDOWTEXT);
  123.      TheFont1  := CreateFontIndirect(TheLogFont);
  124.      SendMessage(hWaux,WM_SETFONT,TheFont1,1);
  125.      ShowWindow(hWaux, CmdShow);
  126.      UpdateWindow(hWaux);
  127.  
  128.   end;
  129.  
  130.   {Result} WinCreate := hWaux;
  131. end;
  132.  
  133. Procedure DestroyWindow;
  134. var cont: boolean;
  135. begin
  136.   DeleteObject(TheFont1);
  137.   sendmessage(hWindow,wm_Destroy,0,0);
  138. end {destroywindow};
  139.  
  140. begin
  141.   mb_Ok := 0;
  142.  if Winregister then
  143.      hWindow:=WinCreate;
  144.   sendmessage(hWindow,wm_paint,0,0);
  145.   DestroyWindow;
  146. end.
  147.  
« Last Edit: July 15, 2022, 05:31:52 pm by Pieter »

dseligo

  • Hero Member
  • *****
  • Posts: 707
Re: WINAPI functions are working but their output remains invisible
« Reply #1 on: July 15, 2022, 05:56:30 pm »
I brought a classical Pascal program (no objects) to Lazarus 2.2.2, running on an Intel i5 laptop under Windows 11 Pro. It gets its user input and output by means of a window created by the WINAPI function CreateWindow and related WINAPI functions. In this way, the program can migrate to another OS by replacing these input and output functions.

I can't help you with your code, but if you want to migrate your program to another OS, why don't you just use Lazarus' forms? Then you don't have to change anything in your code. You just compile it in another OS, or you can also crosscompile to another OS.

440bx

  • Hero Member
  • *****
  • Posts: 3014
Re: WINAPI functions are working but their output remains invisible
« Reply #2 on: July 15, 2022, 06:18:23 pm »
Below, I inserted a small program that illustrates the problem. The console output shows the effect of the SendMessage command but the intended window is completely absent. What did I miss?
There are a number of deficiencies in the program you posted.  For instance, calling InvalidateRgn when processing a WM_PAINT is not a good idea because that will generate another WM_PAINT.  Using WM_SETFONT to the window procedure you showed isn't going to cause the window to use that font.  The WM_PAINT handler isn't selecting that font in the WM_PAINT and the message loop ignores the WM_SETFONT.

Those are just some of the deficiencies I see just having a quick look at that code. 

I recommend you look at the code found in the following examples, they are pure Windows API https://forum.lazarus.freepascal.org/index.php/topic,52984.0.html

That will be a good place for you to start.

HTH.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 11902
Re: WINAPI functions are working but their output remains invisible
« Reply #3 on: July 15, 2022, 06:44:17 pm »
Note that this very old code should work in D7 (although I had some issue that I needed to address: too many incorrect @). But I agree about where to put the invalidatergn code. NOT in wm_paint - but it is also harmless-.
But then again, when the code is processing a message.... This is sequential and invalidateXXX just sets a flag and does not force a repaint, it schedules a repaint..
« Last Edit: July 15, 2022, 06:56:37 pm by Thaddy »
Black themes should be banned.

BobDog

  • Sr. Member
  • ****
  • Posts: 327
Re: WINAPI functions are working but their output remains invisible
« Reply #4 on: July 15, 2022, 09:56:49 pm »
I brought a classical Pascal program (no objects) to Lazarus 2.2.2, running on an Intel i5 laptop under Windows 11 Pro. It gets its user input and output by means of a window created by the WINAPI function CreateWindow and related WINAPI functions. In this way, the program can migrate to another OS by replacing these input and output functions. In Lazarus, this seems to work properly, if you trace the program, however, no output is visible. Below, I inserted a small program that illustrates the problem. The console output shows the effect of the SendMessage command but the intended window is completely absent. What did I miss?

Code: Pascal  [Select][+][-]
  1. program SimpleTest3;
  2. {$mode objfpc}{$H+}
  3.  
  4. uses
  5.   Classes, Windows, Messages, SysUtils ;
  6. const
  7.   MyClassName = 'JustAnotherWindow';
  8.   DefFntSize=12;
  9. type
  10.   Tsem =(dflt,dbg,key_prw);
  11. var
  12. {test specif. vars} i: integer;
  13.   mb_Ok: LongWord;
  14.   ic: integer;
  15.   hWindow: HWnd;
  16.   TheFont1: HFont;
  17.   TheColor: DWORD;
  18.  
  19. function WindowProc(Window: HWnd; AMessage, WParam,
  20.                     LParam: Longint): Longint; stdcall; export;
  21.   var
  22.      dc : hdc;
  23.      ps : Tpaintstruct;
  24.      r : rect;
  25.      bres, speckey:boolean;
  26.      si:integer;
  27.      as2:ansistring;
  28.      sem: Tsem;
  29. begin
  30.   WindowProc := 0; ic:=succ(ic); sem:=dbg;
  31.   case AMessage of
  32.     wm_paint:
  33.       begin
  34.          InvalidateRgn(Window,0,false);
  35.          dc:=BeginPaint(Window,ps);
  36.          case sem of
  37.          dflt:;
  38.          dbg:
  39.            begin
  40.              GetClientRect(Window,@r);
  41.              DrawText(dc,'Hello world by Free Pascal',-1,@r,
  42.              DT_SINGLELINE or DT_CENTER or DT_VCENTER);
  43.              writeln('Best wishes from FP')
  44.           end {dbg};
  45.          key_prw:;
  46.          end {case sem};
  47.          EndPaint(Window,ps);
  48.  
  49.          Exit;
  50.       end;
  51.     wm_Destroy:
  52.       begin
  53.         PostQuitMessage(0);
  54.          Exit;
  55.       end;
  56.   end {case};
  57.   WindowProc := DefWindowProc(Window, AMessage, WParam, LParam);
  58. end;
  59.  
  60. { Register the Window Class }
  61. function WinRegister: Boolean;
  62. var
  63.   WindowClass: WndClass;
  64. begin
  65.   WindowClass.Style := cs_hRedraw or cs_vRedraw;
  66.   WindowClass.lpfnWndProc := WndProc(@WindowProc);
  67.   WindowClass.cbClsExtra := 0;
  68.   WindowClass.cbWndExtra := 0;
  69.   WindowClass.hInstance := system.MainInstance;
  70.   WindowClass.hIcon := LoadIcon(0, idi_Application);
  71.   WindowClass.hCursor := LoadCursor(0, idc_Arrow);
  72.   WindowClass.hbrBackground := GetStockObject(WHITE_BRUSH);
  73.   WindowClass.lpszMenuName := pchar('');
  74.   WindowClass.lpszClassName := MyClassName;
  75.  
  76.   {Result} WinRegister := RegisterClass(WindowClass) <> 0;
  77. end;
  78.  
  79. procedure FontSize(var TLF:TLOGFONT;Height:integer; bold:boolean);
  80. begin
  81.   with TLF do
  82.   begin
  83.     lfHeight         := Height;                // Default logical height of font
  84.     lfWidth          := 0;                // Default logical average character width
  85.     lfEscapement     := 0;                // angle of escapement
  86.     lfOrientation    := 0;                // base-line orientation angle
  87.     if bold then lfWeight:=800 else lfWeight:= FW_NORMAL;        // font weight
  88.     lfItalic         := 0;                // italic attribute flag
  89.     lfUnderline      := 0;                // underline attribute flag
  90.     lfStrikeOut      := 0;                // strikeout attribute flag
  91.     lfCharSet        := DEFAULT_CHARSET;  // character set identifier
  92.     lfOutPrecision   := OUT_DEFAULT_PRECIS;  // output precision
  93.     lfClipPrecision  := CLIP_DEFAULT_PRECIS; // clipping precision
  94.     lfQuality        := DEFAULT_QUALITY;     // output quality
  95.     lfPitchAndFamily := DEFAULT_PITCH;    // pitch and family
  96.     Strcopy(lfFaceName,'Courier New');    // pointer to typeface name string
  97.   end;
  98.   {==}
  99. end {FontSize};
  100.  
  101. function WinCreate: HWnd;
  102. var
  103.   hWaux: HWnd; TheLogFont:TLogFont;
  104.  
  105. begin
  106.   hWaux := CreateWindow(
  107.                         MyClassName, {Defined in WinRegister}
  108.                         'aWindow', {Name of window}
  109.                         ws_OverlappedWindow,  {Style}
  110.                         cw_UseDefault, {X}
  111.                         cw_UseDefault, {Y}
  112.                         cw_UseDefault, {width}
  113.                         cw_UseDefault, {heighth}
  114.                         0, {Parent}
  115.                         0, {Menu}
  116.                         system.MainInstance, {hInstance}
  117.                         nil); {lpVOID}
  118.  
  119.   if hWaux <> 0 then
  120.   begin
  121.     {Selectfont;} FontSize(TheLogFont,DefFntSize,false);
  122.      TheColor := GetSysColor(COLOR_WINDOWTEXT);
  123.      TheFont1  := CreateFontIndirect(TheLogFont);
  124.      SendMessage(hWaux,WM_SETFONT,TheFont1,1);
  125.      ShowWindow(hWaux, CmdShow);
  126.      UpdateWindow(hWaux);
  127.  
  128.   end;
  129.  
  130.   {Result} WinCreate := hWaux;
  131. end;
  132.  
  133. Procedure DestroyWindow;
  134. var cont: boolean;
  135. begin
  136.   DeleteObject(TheFont1);
  137.   sendmessage(hWindow,wm_Destroy,0,0);
  138. end {destroywindow};
  139.  
  140. begin
  141.   mb_Ok := 0;
  142.  if Winregister then
  143.      hWindow:=WinCreate;
  144.   sendmessage(hWindow,wm_paint,0,0);
  145.   DestroyWindow;
  146. end.
  147.  
You need a while loop (line 133 ish)
Repeat your code:
Code: Pascal  [Select][+][-]
  1. program SimpleTest3;
  2. {$mode objfpc}{$H+}
  3.  
  4. uses
  5.   Classes, Windows, Messages, SysUtils ;
  6. const
  7.   MyClassName = 'JustAnotherWindow';
  8.   DefFntSize=12;
  9. type
  10.   Tsem =(dflt,dbg,key_prw);
  11. var
  12. {test specif. vars} i: integer;
  13.   mb_Ok: LongWord;
  14.   ic: integer;
  15.   hWindow: HWnd;
  16.   TheFont1: HFont;
  17.   TheColor: DWORD;
  18.  
  19. function WindowProc(Window: HWnd; AMessage, WParam,
  20.                     LParam: Longint): Longint; stdcall; export;
  21.   var
  22.      dc : hdc;
  23.      ps : Tpaintstruct;
  24.      r : rect;
  25.      bres, speckey:boolean;
  26.      si:integer;
  27.      as2:ansistring;
  28.      sem: Tsem;
  29. begin
  30.   WindowProc := 0; ic:=succ(ic); sem:=dbg;
  31.   case AMessage of
  32.     wm_paint:
  33.       begin
  34.          InvalidateRgn(Window,0,false);
  35.          dc:=BeginPaint(Window,ps);
  36.          case sem of
  37.          dflt:;
  38.          dbg:
  39.            begin
  40.              GetClientRect(Window,@r);
  41.              DrawText(dc,'Hello world by Free Pascal',-1,@r,
  42.              DT_SINGLELINE or DT_CENTER or DT_VCENTER);
  43.              writeln('Best wishes from FP')
  44.           end {dbg};
  45.          key_prw:;
  46.          end {case sem};
  47.          EndPaint(Window,ps);
  48.  
  49.          Exit;
  50.       end;
  51.     wm_Destroy:
  52.       begin
  53.         PostQuitMessage(0);
  54.          Exit;
  55.       end;
  56.   end {case};
  57.   WindowProc := DefWindowProc(Window, AMessage, WParam, LParam);
  58. end;
  59.  
  60. { Register the Window Class }
  61. function WinRegister: Boolean;
  62. var
  63.   WindowClass: WndClass;
  64. begin
  65.   WindowClass.Style := cs_hRedraw or cs_vRedraw;
  66.   WindowClass.lpfnWndProc := WndProc(@WindowProc);
  67.   WindowClass.cbClsExtra := 0;
  68.   WindowClass.cbWndExtra := 0;
  69.   WindowClass.hInstance := system.MainInstance;
  70.   WindowClass.hIcon := LoadIcon(0, idi_Application);
  71.   WindowClass.hCursor := LoadCursor(0, idc_Arrow);
  72.   WindowClass.hbrBackground := GetStockObject(WHITE_BRUSH);
  73.   WindowClass.lpszMenuName := pchar('');
  74.   WindowClass.lpszClassName := pchar(MyClassName);
  75.  
  76.   {Result} WinRegister := RegisterClass(WindowClass) <> 0;
  77. end;
  78.  
  79. procedure FontSize(var TLF:TLOGFONT;Height:integer; bold:boolean);
  80. begin
  81.   with TLF do
  82.   begin
  83.     lfHeight         := Height;                // Default logical height of font
  84.     lfWidth          := 0;                // Default logical average character width
  85.     lfEscapement     := 0;                // angle of escapement
  86.     lfOrientation    := 0;                // base-line orientation angle
  87.     if bold then lfWeight:=800 else lfWeight:= FW_NORMAL;        // font weight
  88.     lfItalic         := 0;                // italic attribute flag
  89.     lfUnderline      := 0;                // underline attribute flag
  90.     lfStrikeOut      := 0;                // strikeout attribute flag
  91.     lfCharSet        := DEFAULT_CHARSET;  // character set identifier
  92.     lfOutPrecision   := OUT_DEFAULT_PRECIS;  // output precision
  93.     lfClipPrecision  := CLIP_DEFAULT_PRECIS; // clipping precision
  94.     lfQuality        := DEFAULT_QUALITY;     // output quality
  95.     lfPitchAndFamily := DEFAULT_PITCH;    // pitch and family
  96.     Strcopy(lfFaceName,'Courier New');    // pointer to typeface name string
  97.   end;
  98.   {==}
  99. end {FontSize};
  100.  
  101. function WinCreate: HWnd;
  102. var
  103.   hWaux: HWnd; TheLogFont:TLogFont;
  104.  emsg:msg;
  105. begin
  106.   hWaux := CreateWindow(
  107.                         MyClassName, {Defined in WinRegister}
  108.                         'aWindow', {Name of window}
  109.                         ws_OverlappedWindow,  {Style}
  110.                         cw_UseDefault, {X}
  111.                         cw_UseDefault, {Y}
  112.                         cw_UseDefault, {width}
  113.                         cw_UseDefault, {heighth}
  114.                         0, {Parent}
  115.                         0, {Menu}
  116.                         system.MainInstance, {hInstance}
  117.                         nil); {lpVOID}
  118.  
  119.   if hWaux <> 0 then
  120.   begin
  121.     {Selectfont;} FontSize(TheLogFont,DefFntSize,false);
  122.      TheColor := GetSysColor(COLOR_WINDOWTEXT);
  123.      TheFont1  := CreateFontIndirect(TheLogFont);
  124.      SendMessage(hWaux,WM_SETFONT,TheFont1,1);
  125.      ShowWindow(hWaux, CmdShow);
  126.      UpdateWindow(hWaux);
  127.  
  128.   end;
  129.  
  130.  
  131.  
  132.   {Result} WinCreate := hWaux;
  133. While (GetMessage(@eMsg, 0, 0, 0) <> FALSE) do
  134. begin
  135.     TranslateMessage(@eMsg);
  136.     DispatchMessage(@eMsg);
  137. end;
  138.  
  139.  
  140. end;
  141.  
  142. Procedure DestroyWindow;
  143. var cont: boolean;
  144. begin
  145.   DeleteObject(TheFont1);
  146.   sendmessage(hWindow,wm_Destroy,0,0);
  147. end {destroywindow};
  148.  
  149. begin
  150.   mb_Ok := 0;
  151.  if Winregister then
  152.      hWindow:=WinCreate;
  153.   sendmessage(hWindow,wm_paint,0,0);
  154.   DestroyWindow;
  155. end.
  156.  

Pieter

  • New Member
  • *
  • Posts: 19
Re: WINAPI functions are working but their output remains invisible
« Reply #5 on: July 18, 2022, 09:54:50 am »
Thanks! This is all very useful information to go forward.  :D

Pieter

  • New Member
  • *
  • Posts: 19
Re: WINAPI functions are working but their output remains invisible
« Reply #6 on: July 25, 2022, 12:05:05 pm »
I brought a classical Pascal program (no objects) to Lazarus 2.2.2, running on an Intel i5 laptop under Windows 11 Pro. It gets its user input and output by means of a window created by the WINAPI function CreateWindow and related WINAPI functions. In this way, the program can migrate to another OS by replacing these input and output functions.

I can't help you with your code, but if you want to migrate your program to another OS, why don't you just use Lazarus' forms? Then you don't have to change anything in your code. You just compile it in another OS, or you can also crosscompile to another OS.

Continuing your proposal, I made the following code, i.e. a classical console program including a form that should serve for the input and output.

Code: Pascal  [Select][+][-]
  1. program FrmInCnsl;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}
  7.   cthreads,
  8.   {$ENDIF}
  9.   Classes, Interfaces, // this includes the LCL widgetset
  10.   Forms, Windows, MyUnit1
  11.   { you can add units after this };
  12.  
  13. // {$R *.res}  not necessary?
  14. var
  15.   cont: boolean;
  16. begin
  17.   Application.Initialize;
  18.   writeln('Start');
  19.   Application.CreateForm(TForm1, Form1);
  20.   writeln('Form Created');
  21.   Form1.Show;
  22.   Form1.Canvas.TextOut(1,1,'My Text');
  23.   readln;
  24. end {main program}.
  25.  
  26.  
  27. {*** unit ***}  
  28. unit MyUnit1;
  29.  
  30. {$mode ObjFPC}{$H+}
  31.  
  32. interface
  33.  
  34. uses
  35.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs;
  36.  
  37. type
  38.  
  39.   { TForm1 }
  40.  
  41.   TForm1 = class(TForm)
  42.     procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  43.   private
  44.  
  45.   public
  46.  
  47.   end;
  48.  
  49. var
  50.   Form1: TForm1;
  51.  
  52. implementation
  53.  
  54. {$R *.lfm}
  55.  
  56. { TForm1 }
  57.  
  58. procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState
  59.   );
  60. begin
  61.   writeln('key:', Key:2);
  62. end;
  63.  
  64. end.
  65.    
  66.  


As you can see, output is not a problem but how can I make the form react to keystrokes? The form has the procedure FormKeyDown, which should do this. My problem is how to tell this to the form in a classical pascal program. So, a want a piece of code that transfers control from a classical main program to the form, that then waits for a keystroke. When the keystroke has happened, control should go back to the place in the main program where the form was activated. Could you show me the way?

Thaddy

  • Hero Member
  • *****
  • Posts: 11902
Re: WINAPI functions are working but their output remains invisible
« Reply #7 on: July 25, 2022, 12:51:59 pm »
Under windows add {$apptype console} or even beter {$ifdef mswindows}{$apptype console}{$endif} at the top of your program. That gives you a visible console output and no error 105. Also add a readln at the very last line of your project code.
That can also be ifdeffed, because on most other platforms this is not necessary, at least in the IDE.
« Last Edit: July 25, 2022, 12:56:01 pm by Thaddy »
Black themes should be banned.

Pieter

  • New Member
  • *
  • Posts: 19
Re: WINAPI functions are working but their output remains invisible
« Reply #8 on: July 25, 2022, 01:33:05 pm »
Under windows add {$apptype console} or even beter {$ifdef mswindows}{$apptype console}{$endif} at the top of your program. That gives you a visible console output and no error 105. Also add a readln at the very last line of your project code.
That can also be ifdeffed, because on most other platforms this is not necessary, at least in the IDE.
This is not the problem. I can already see the console, no need for APPTYPE CONSOLE, and readln is already present at the last position. I want to activate the form so that entered key  strokes are displayed in the form

Pieter

  • New Member
  • *
  • Posts: 19
Re: WINAPI functions are working but their output remains invisible
« Reply #9 on: August 02, 2022, 04:37:40 pm »
Below, I inserted a small program that illustrates the problem. The console output shows the effect of the SendMessage command but the intended window is completely absent. What did I miss?
There are a number of deficiencies in the program you posted.  For instance, calling InvalidateRgn when processing a WM_PAINT is not a good idea because that will generate another WM_PAINT.  Using WM_SETFONT to the window procedure you showed isn't going to cause the window to use that font.  The WM_PAINT handler isn't selecting that font in the WM_PAINT and the message loop ignores the WM_SETFONT.

Those are just some of the deficiencies I see just having a quick look at that code. 

I recommend you look at the code found in the following examples, they are pure Windows API https://forum.lazarus.freepascal.org/index.php/topic,52984.0.html

That will be a good place for you to start.

HTH.

Thanks, based on your GetClientRectangle example in https://forum.lazarus.freepascal.org/index.php/topic,52902.msg390865.html#msg390865, I could get my code to work. :D

 

TinyPortal © 2005-2018