0

Question: I find that the rectangle drawed by Rectangle function(included in WinGDI.h) will not show in windows 7 sysytem(64 bit), but it can display in windows 10. Is there any differences between win7 and win10? And are there other ways to do draw a shape above desktop in win7?

‏Environment: Windows 7 64 bit and Windows 10 64 bit.

Tools: Microsoft Visual Studio, Windows SDK, GDI.

Related C++ code:

HDC hDcWnd = GetDC(GetDesktopWindow());

HPEN hPen = CreatePen(PS_SOLID, 6 ,RGB(30,30,30));
HPEN hOldPen = (HPEN)SelectObject(hDcWnd,hPen);

HBRUSH hBrush = CreateSolidBrush(RGB(0,49,79));
HBRUSH hOldBrush = (HBRUSH)SelectObject(hDcWnd,hBrush);

Rectangle(hDcWnd,x1,y1,x2,y2);

SelectObject(...); //the following code is ignored here
  • Related: [Failed to draw on DesktopWindow](https://stackoverflow.com/questions/37385102/failed-to-draw-on-desktopwindow). – dxiv Nov 16 '20 at 05:52
  • Wow thank you! GetDC(NULL) has worked! But I still don't understand why I can draw in Windows 10 by GetDC(GetDesktopWindow()). Is there any difference between win7 and win10? – Aglaia Chan Nov 16 '20 at 11:47
  • It's not guaranteed to work consistently, but this doesn't mean it's guaranteed to always fail. Could be a difference between your Windows 7 vs. 10, or multi-monitor configurations, or something else entirely. – dxiv Nov 16 '20 at 23:45

0 Answers0