Author Topic: DPI awareness problem  (Read 173 times)

minor28

  • Member
  • **
  • Posts: 121
DPI awareness problem
« on: February 11, 2020, 12:10:14 AM »
Years ago I wrote a color picker app (attached) based on ChooseColor and a template. Running this app on a screen with resolution higher than 1920x1080 the GetPixel doesn't work from the capture button. But everything else is working as it should. The whole app is scaled to fit the resolution.

I managed to get the picker to work by adding this to the manifest.
Code: [Select]
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
true/pm
</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
PerMonitorV2, PerMonitor
</dpiAwareness>
</windowsSettings>

The templete contains two additional dialogs with system colors and web colors. These dialogs are created at initiation action of the template. Code for system colors dialog is attached. The size of the two dialogs are OK. Each dialog contains a number of static control for color and color name. These static controls are not scaled with the new manifest.

I have tried to scale up the controls using GetDpiForWindow but no success.

Does anyone have a suggestion how to solve this problem?

minor28

  • Member
  • **
  • Posts: 121
Re: DPI awareness problem
« Reply #1 on: February 14, 2020, 08:10:36 PM »
At last I found a solution. I removed the <windowsSettings> in manifest. Then the whole app, childwindows included, is scaled to current dpi. this was the starting point of the problem.

The capture button sets a windows hook (WM_MOUSE_LL) posting a message (WM_MOUSEHOOK) to the template dialog. This i what I did.

Code: [Select]
ThreadDpiAwarenessContext proc dpiContext

invoke GetModuleHandle,offset szUse32
invoke GetProcAddress,eax,offset szSetThreadDpiAwarenessContext
push dpiContext
call eax

ret
ThreadDpiAwarenessContext endp

.elseif uMsg==WM_MOUSEHOOK
invoke ThreadDpiAwarenessContext,DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
;Pic color
invoke GetCursorPos,addr lpPoint

invoke GetDC,0
push eax
invoke GetPixel,eax,lpPoint.x,lpPoint.y

invoke SetRGBValues,eax
invoke SetOutputColors
invoke FindWebColors,hGroupBox2,0

pop eax
invoke ReleaseDC,0,eax

   

AW

  • Member
  • *****
  • Posts: 2549
  • Let's Make ASM Great Again!
Re: DPI awareness problem
« Reply #2 on: February 14, 2020, 10:49:43 PM »
You have not provided a complete test setup, expecting others to do it for you - this was expecting a bit too much.
So, it was great you found the solution yourself.   :badgrin:

minor28

  • Member
  • **
  • Posts: 121
Re: DPI awareness problem
« Reply #3 on: February 15, 2020, 12:49:47 AM »
I did not provid a complete test setup because I didn't expect others to do the coding for me. I attached the app so you could see the problem. Someone may have had a similar problem and I was just asking for advice on how to approach the problem.

If this was not clear from my post, I apologize.

AW

  • Member
  • *****
  • Posts: 2549
  • Let's Make ASM Great Again!
Re: DPI awareness problem
« Reply #4 on: February 15, 2020, 01:04:04 AM »
You don't have to apologize, I was explaining to you the reason nobody bothered to answer, have a nice day.