Recent

Author Topic: Window rendering error after calling CallWindowProc and DefWindowProc  (Read 2340 times)

Pixelmak

  • New member
  • *
  • Posts: 7
I am trying to get Windows messages via WndCallback in Windows 11. But, after receiving the message, the window is not rendered normally. What am I doing wrong? (Screen in Attachment)



Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode delphi}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Windows;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     procedure Button1Click(Sender: TObject);
  17.     procedure FormCreate(Sender: TObject);
  18.   private
  19.  
  20.   public
  21.  
  22.   end;
  23.  
  24.   function WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; lParam: LParam): LRESULT; stdcall;
  25.  
  26. var
  27.   Form1: TForm1;
  28.   PrevWndProc:windows.WNDPROC;
  29.  
  30. implementation
  31.  
  32. function WndCallback(Ahwnd: HWND; uMsg: UINT; wParam: WParam; lParam: LParam
  33.   ): LRESULT; stdcall;
  34. begin
  35.   result := CallWindowProc(PrevWndProc , Ahwnd, uMsg, WParam, LParam);
  36. end;
  37.  
  38. {$R *.lfm}
  39.  
  40. { TForm1 }
  41.  
  42. procedure TForm1.FormCreate(Sender: TObject);
  43. begin
  44.   PrevWndProc := Windows.WNDPROC(SetWindowLongPtr(Self.Handle, GWL_WNDPROC, PtrUInt(@WndCallback)));
  45. end;
  46.  
  47. procedure TForm1.Button1Click(Sender: TObject);
  48. begin
  49.   writeln('Button clicked');
  50. end;
  51.  
  52. end.
  53.  

Pixelmak

  • New member
  • *
  • Posts: 7
Re: Window rendering error after calling CallWindowProc and DefWindowProc
« Reply #1 on: December 21, 2021, 11:14:27 am »
Oh, I'm sorry. This code works now. I don’t know for what reason this error occurred.

Perhaps the reason was that I used DefWindowProc instead of CallWindowProc

 

TinyPortal © 2005-2018