WM_DISPLAYCHANGE // recognize a different screen resolution lazarus / 34-Windows ---------------------------------------------------------------------- RAW · 2018-02-10 06:57 Maybe this is useful for anybody....  This is working for me... EDIT: Instead of "ShowMessage" I use now "Color" in this example... As GetMem mentioned "ShowMessage" is a bad idea inside a WndProc. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i UNIT Unit1;{$MODE OBJFPC}{$H+}{$J-} Interface USES  Windows, Classes, Forms, Dialogs;  TYPE  TForm1 = Class(TForm)   Procedure FormCreate (Sender: TObject);   Procedure FormClick  (Sender: TObject);     PRIVATE     oldProc: Windows.WndProc;  End;  VAR  Form1: TForm1; Implementation{$R *.LFM}  Function WndCallback  (MyWND: HWND; uMSG: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; StdCall; Begin  If (uMSG = WM_DISPLAYCHANGE)  Then Form1.Color:= RGB(0, 80, 255);   Result:= CallWindowProc(Form1.oldProc, MyWND, uMSG, wParam, lParam); End;  Procedure TForm1.FormCreate(Sender: TObject); Begin  oldProc:= Windows.WndProc(GetWindowLongPtr(Handle, GWL_WNDPROC));  SetWindowLongPtr(Handle, GWL_WNDPROC, PtrInt(@WndCallback)); End;  Procedure TForm1.FormClick(Sender: TObject); Begin  Color:= RGB(0, 187, 0); End; END. // not working for me... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit unit1;{$mode objfpc}{$H+} interface uses Windows, Classes, SysUtils, Forms, Dialogs; type  TForm1 = class(TForm)  private   procedure WMDisplayChange(var msg: TMessage); message WM_DISPLAYCHANGE;  end; var  Form1: TForm1; implementation {$R *.lfm} procedure TForm1.WMDisplayChange(var msg: TMessage);begin showmessage('Display Changed');end; end. WndProc (standard way) isn't working for me either... ---------------------------------------------------------------------- balazsszekely · 2018-02-10 07:39 @RAW The ShowMessage inside WndCallback is wrong, I mean fundamentally wrong. You cannot block the message chain with a function like ShowMessage. I know you put it there only for testing purposes, still be careful with blocking functions. ---------------------------------------------------------------------- RAW · 2018-02-10 08:05 @GetMem Yeah, I added some info lines regarding this... Thanks... ---------------------------------------------------------------------- taazz · 2018-02-10 09:39 Quote from: RAW on February 10, 2018, 07:57:47 am // not working for me... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit unit1;{$mode objfpc}{$H+} interface uses Windows, Classes, SysUtils, Forms, Dialogs; type  TForm1 = class(TForm)  private   procedure WMDisplayChange(var msg: TMessage); message WM_DISPLAYCHANGE;  end; var  Form1: TForm1; implementation {$R *.lfm} procedure TForm1.WMDisplayChange(var msg: TMessage);begin showmessage('Display Changed');end; end. WndProc (standard way) isn't working for me either... that is because the default handler filters unsupported messages out from the internal message loop. You should use the getwindowlong (look the default handler proc for info) to get the attached wincontrol instead of relying on a global variable that might or might not be valid. ---------------------------------------------------------------------- RAW · 2018-02-11 20:16 @taazz Thanks for the info... What do you mean? Something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Procedure TForm1.FormCreate(Sender: TObject); Begin  oldProc:= Windows.WndProc(GetWindowLongPtr(Handle, GWL_WNDPROC));  SetWindowLongPtr(Handle, GWL_WNDPROC, PtrInt(@WndCallback)); End; ... is working good too...  But I heard it's better to use this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  TYPE  TSubClassProc = Function   (hWnd: HWND; uMSG: UINT; wParam: WPARAM; lParam: LPARAM;    uIDSubclass: UINT_PTR; dwRefData: DWORD_PTR): LRESULT; StdCall; ........................  Function SetWindowSubclass  (hWnd: HWND; pfnSubclass: TSubClassProc; uIDSubclass: UINT_PTR;   dwRefData: DWORD_PTR): BOOL; StdCall; External 'ComCtl32.dll';  Function RemoveWindowSubclass  (hWnd: HWND; pfnSubclass: TSubClassProc; uIDSubclass: UINT_PTR): BOOL;   StdCall; External 'ComCtl32.dll';  Function DefSubclassProc  (hWnd: HWND; uMSG: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT;   StdCall; External 'ComCtl32.dll';  I'm working on it... ---------------------------------------------------------------------- taazz · 2018-02-11 20:40 Quote from: RAW on February 11, 2018, 09:16:47 pm@taazz Thanks for the info... What do you mean? Something like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Procedure TForm1.FormCreate(Sender: TObject); Begin  oldProc:= Windows.WndProc(GetWindowLongPtr(Handle, GWL_WNDPROC));  SetWindowLongPtr(Handle, GWL_WNDPROC, PtrInt(@WndCallback)); End; No I mean Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i UNIT Unit1;{$MODE OBJFPC}{$H+}{$J-} Interface USES  Windows, Classes, Forms, Dialogs;  TYPE  TForm1 = Class(TForm)  Procedure FormCreate (Sender: TObject);   PRIVATE    PrevWndProc: Windows.WNDPROC;  End;  VAR  Form1: TForm1; Implementation{$R *.LFM}  Function WndCallback (MyHWND: HWND; uMSG: UINT; wParam: WParam; lParam: LParam): LRESULT; StdCall;var  WindowInfo: PWin32WindowInfo;Begin  WindowInfo := GetWin32WindowInfo(Window); //<---- step one  If (uMSG = WM_DISPLAYCHANGE)  Then ShowMessage('Display Changed') // only for testing purposes...  Else Form1.Color:= RGB(0, 170, 0);  // don't use this in real world apps, take                                      // a look at the following post from GetMem   if WindowInfo^.WinControl is TForm1 then //Eliminate form1 global variable for safer handling.  Result:= CallWindowProc(TForm1(WindowInfo^.WinControl).PrevWndProc, MyHWND, uMSG, WParam, LParam); End;  Procedure TForm1.FormCreate(Sender: TObject); Begin  PrevWndProc:= Windows.WNDPROC  (SetWindowLongPtr(Handle, GWL_WNDPROC, PtrInt(@WndCallback))); End; END. Take a closer look on WindowProc in the file win32callback.inc it has all the information you need.