diff --git a/lcl/interfaces/qt/qtwinapi.inc b/lcl/interfaces/qt/qtwinapi.inc index 151fd5c16c..c3f5f3222c 100644 --- a/lcl/interfaces/qt/qtwinapi.inc +++ b/lcl/interfaces/qt/qtwinapi.inc @@ -2268,18 +2268,14 @@ begin WriteLn('Trace:> [WinAPI GetDC] hWnd: ', dbghex(hWnd)); {$endif} - Widget := TQtWidget(hWnd); - - if Widget <> nil then + if QtWidgetSet.IsValidHandle(hWnd) then begin + Widget := TQtWidget(hWnd); Result := Widget.Context; if Result = 0 then Result := HDC(QtDefaultContext); - end - else - begin + end else Result := HDC(QtScreenContext); - end; {$ifdef VerboseQtWinAPI} WriteLn('Trace:< [WinAPI GetDC] Result: ', dbghex(Result));