Forum > Windows
WINAPI functions are working but their output remains invisible
Pieter:
Thanks! This is all very useful information to go forward. :D
Pieter:
--- Quote from: dseligo on July 15, 2022, 05:56:30 pm ---
--- Quote from: Pieter on July 15, 2022, 05:30:06 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.
--- End quote ---
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.
--- End quote ---
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 [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program FrmInCnsl; {$mode objfpc}{$H+} uses {$IFDEF UNIX} cthreads, {$ENDIF} Classes, Interfaces, // this includes the LCL widgetset Forms, Windows, MyUnit1 { you can add units after this }; // {$R *.res} not necessary?var cont: boolean;begin Application.Initialize; writeln('Start'); Application.CreateForm(TForm1, Form1); writeln('Form Created'); Form1.Show; Form1.Canvas.TextOut(1,1,'My Text'); readln;end {main program}. {*** unit ***} unit MyUnit1; {$mode ObjFPC}{$H+} interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs; type { TForm1 } TForm1 = class(TForm) procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); private public end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState );begin writeln('key:', Key:2);end; end.
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:
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.
Pieter:
--- Quote from: Thaddy 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.
--- End quote ---
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:
--- Quote from: 440bx on July 15, 2022, 06:18:23 pm ---
--- Quote from: Pieter on July 15, 2022, 05:30:06 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?
--- End quote ---
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.
--- End quote ---
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
Navigation
[0] Message Index
[*] Previous page