View Issue Details

IDProjectCategoryView StatusLast Update
0036574PatchesWidgetsetpublic2020-04-01 06:26
ReporterYuriy Sydorov Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionreopened 
Product Version2.1 (SVN) 
Summary0036574: [patch] CustomDrawn: Fixed crash on startup
DescriptionThe patch implements basic versions of EnumDisplayMonitors() and GetMonitorInfo(). It prevents crash on startup.
TagsNo tags attached.
Fixed in Revisionr62599, r62600
LazTarget-
WidgetsetCustomDrawn
Attached Files

Relationships

related to 0036460 closedJuha Manninen Lazarus CustomDraw widgetset for Windows target, crash on start 
related to 0031738 closedJuha Manninen Lazarus customdrawn: Patch to implement EnumDisplayMonitors and GetMonitorInfo for CD_X11 and CD_win32 

Activities

Yuriy Sydorov

2020-01-14 17:20

developer  

customdrawn_monitor.patch (4,105 bytes)   
Index: lcl/interfaces/customdrawn/customdrawnwinapi.inc
===================================================================
--- lcl/interfaces/customdrawn/customdrawnwinapi.inc	(revision 62551)
+++ lcl/interfaces/customdrawn/customdrawnwinapi.inc	(working copy)
@@ -1508,22 +1508,13 @@
   System.EnterCriticalsection(ACritSec^);
 end;
 
-(*function TQtWidgetSet.EnumDisplayMonitors(hdc: HDC; lprcClip: PRect;
+function TCDWidgetSet.EnumDisplayMonitors(hdc: HDC; lprcClip: PRect;
   lpfnEnum: MonitorEnumProc; dwData: LPARAM): LongBool;
-var
-  i: integer;
-  Desktop: QDesktopWidgetH;
 begin
-  Desktop := QApplication_desktop();
-  Result := True;
-  for i := 0 to QDesktopWidget_numScreens(Desktop) - 1 do
-  begin
-    Result := Result and lpfnEnum(i + 1, 0, nil, dwData);
-    if not Result then break;
-  end;
+  Result := lpfnEnum(1, 0, nil, dwData);
 end;
 
-
+(*
 function CharsetToQtCharSet(const ALCLCharset: Byte): QFontDatabaseWritingSystem;
 begin
   Result := QFontDatabaseAny;
@@ -2909,25 +2900,16 @@
   else
     Result := 0;
 end;
-
-function TQtWidgetSet.GetMonitorInfo(Monitor: HMONITOR; lpmi: PMonitorInfo): Boolean;
-var
-  Desktop: QDesktopWidgetH;
+*)
+function TCDWidgetSet.GetMonitorInfo(Monitor: HMONITOR; lpmi: PMonitorInfo): Boolean;
 begin
-  Result := (lpmi <> nil) and (lpmi^.cbSize >= SizeOf(TMonitorInfo)) or (Monitor = 0);
+  Result := (lpmi <> nil) and (lpmi^.cbSize >= SizeOf(TMonitorInfo)) or (Monitor <> 1);
   if not Result then Exit;
-  Desktop := QApplication_desktop();
-  Dec(Monitor);
-  Result := (Monitor >= 0) and (Monitor < PtrUInt(QDesktopWidget_numScreens(Desktop)));
-  if not Result then Exit;
-  QDesktopWidget_screenGeometry(Desktop, @lpmi^.rcMonitor, Monitor);
-  QDesktopWidget_availableGeometry(Desktop, @lpmi^.rcWork, Monitor);
-  if PtrUInt(QDesktopWidget_primaryScreen(Desktop)) = Monitor then
-    lpmi^.dwFlags := MONITORINFOF_PRIMARY
-  else
-    lpmi^.dwFlags := 0;
+  lpmi^.rcMonitor:=Types.Rect(0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
+  lpmi^.rcWork:=lpmi^.rcMonitor;
+  lpmi^.dwFlags := MONITORINFOF_PRIMARY
 end;
-
+(*
 {------------------------------------------------------------------------------
   Method:  TQtWidgetSet.GetDeviceSize
   Params:  none
Index: lcl/interfaces/customdrawn/customdrawnwinapih.inc
===================================================================
--- lcl/interfaces/customdrawn/customdrawnwinapih.inc	(revision 62551)
+++ lcl/interfaces/customdrawn/customdrawnwinapih.inc	(working copy)
@@ -83,7 +83,7 @@
 function EnableWindow(hWnd: HWND; bEnable: Boolean): Boolean; override;
 function EndPaint(Handle: hwnd; var PS: TPaintStruct): Integer; override;*)
 procedure EnterCriticalSection(var CritSection: TCriticalSection); override;
-//function EnumDisplayMonitors(hdc: HDC; lprcClip: PRect; lpfnEnum: MonitorEnumProc; dwData: LPARAM): LongBool; override;
+function EnumDisplayMonitors(hdc: HDC; lprcClip: PRect; lpfnEnum: MonitorEnumProc; dwData: LPARAM): LongBool; override;
 function EnumFontFamiliesEx(DC: HDC; lpLogFont: PLogFont; Callback: FontEnumExProc; Lparam: LParam; Flags: dword): longint; override;
 //function ExcludeClipRect(dc: hdc; Left, Top, Right, Bottom : Integer) : Integer; override;
 function ExtCreatePen(dwPenStyle, dwWidth: DWord; const lplb: TLogBrush; dwStyleCount: DWord; lpStyle: PDWord): HPEN; override;
@@ -118,9 +118,9 @@
 function GetFocus: HWND; override;
 (*function GetForegroundWindow: HWND; override;*)
 function GetKeyState(nVirtKey: Integer): Smallint; override;
-(*function GetMapMode(DC: HDC): Integer; override;
+//function GetMapMode(DC: HDC): Integer; override;
 function GetMonitorInfo(Monitor: HMONITOR; lpmi: PMonitorInfo): Boolean; override;
-function GetObject(GDIObj: HGDIOBJ; BufSize: Integer; Buf: Pointer): Integer; override;*)
+//function GetObject(GDIObj: HGDIOBJ; BufSize: Integer; Buf: Pointer): Integer; override;
 function GetParent(Handle : HWND): HWND; override;
 function GetProp(Handle : hwnd; Str : PChar): Pointer; override;
 function GetRgnBox(RGN : HRGN; lpRect : PRect) : Longint; override;
customdrawn_monitor.patch (4,105 bytes)   

Juha Manninen

2020-01-30 18:14

developer   ~0120809

Applied, thanks.

Yuriy Sydorov

2020-01-30 18:42

developer   ~0120810

Thank for applying the patch. I've found a minor issue in the sanity check in the original patch and applied additional patch. Please apply it too.

Yuriy Sydorov

2020-01-30 18:42

developer   ~0120811

Additional patch.
customdrawn_monitor2.patch (727 bytes)   
Index: lcl/interfaces/customdrawn/customdrawnwinapi.inc
===================================================================
--- lcl/interfaces/customdrawn/customdrawnwinapi.inc	(revision 62599)
+++ lcl/interfaces/customdrawn/customdrawnwinapi.inc	(working copy)
@@ -2903,7 +2903,7 @@
 *)
 function TCDWidgetSet.GetMonitorInfo(Monitor: HMONITOR; lpmi: PMonitorInfo): Boolean;
 begin
-  Result := (lpmi <> nil) and (lpmi^.cbSize >= SizeOf(TMonitorInfo)) or (Monitor <> 1);
+  Result := (lpmi <> nil) and (lpmi^.cbSize >= SizeOf(TMonitorInfo)) and (Monitor = 1);
   if not Result then Exit;
   lpmi^.rcMonitor:=Types.Rect(0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
   lpmi^.rcWork:=lpmi^.rcMonitor;
customdrawn_monitor2.patch (727 bytes)   

Anton Kavalenka

2020-01-31 09:25

reporter   ~0120817

See 0031738

Juha Manninen

2020-01-31 10:53

developer   ~0120821

I applied the 2. patch. Thanks.

Anton Kavalenka

2020-01-31 12:25

reporter   ~0120825

@Juha Manninen
0031738 brings more functionality and make GetMonitorInfo working in Customdrawn

Yuriy Sydorov

2020-01-31 12:57

developer   ~0120826

Thanks!

Anton Kavalenka, my patch adds a basic implementation of monitor info functions for all platforms. You need to rebase your patch to the current code state in order to add the complete implementation for win32 and QT, but leave the basic implementation for other platforms.

Issue History

Date Modified Username Field Change
2020-01-14 17:20 Yuriy Sydorov New Issue
2020-01-14 17:20 Yuriy Sydorov File Added: customdrawn_monitor.patch
2020-01-14 17:22 Yuriy Sydorov Product Version => 2.1 (SVN)
2020-01-14 17:22 Yuriy Sydorov LazTarget => -
2020-01-14 17:22 Yuriy Sydorov Widgetset CustomDrawn => CustomDrawn
2020-01-30 18:12 Juha Manninen Assigned To => Juha Manninen
2020-01-30 18:12 Juha Manninen Status new => assigned
2020-01-30 18:14 Juha Manninen Status assigned => resolved
2020-01-30 18:14 Juha Manninen Resolution open => fixed
2020-01-30 18:14 Juha Manninen Fixed in Revision => r62599
2020-01-30 18:14 Juha Manninen Widgetset CustomDrawn => CustomDrawn
2020-01-30 18:14 Juha Manninen Note Added: 0120809
2020-01-30 18:42 Yuriy Sydorov Status resolved => assigned
2020-01-30 18:42 Yuriy Sydorov Resolution fixed => reopened
2020-01-30 18:42 Yuriy Sydorov Note Added: 0120810
2020-01-30 18:42 Yuriy Sydorov File Added: customdrawn_monitor2.patch
2020-01-30 18:42 Yuriy Sydorov Note Added: 0120811
2020-01-31 09:25 Anton Kavalenka Note Added: 0120817
2020-01-31 10:53 Juha Manninen Status assigned => resolved
2020-01-31 10:53 Juha Manninen Fixed in Revision r62599 => r62599, r62600
2020-01-31 10:53 Juha Manninen Widgetset CustomDrawn => CustomDrawn
2020-01-31 10:53 Juha Manninen Note Added: 0120821
2020-01-31 12:25 Anton Kavalenka Note Added: 0120825
2020-01-31 12:57 Yuriy Sydorov Status resolved => closed
2020-01-31 12:57 Yuriy Sydorov Note Added: 0120826
2020-02-17 13:41 Juha Manninen Relationship added related to 0036460
2020-04-01 06:26 Juha Manninen Relationship added related to 0031738