News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

DPI awareness problem

Started by minor28, February 11, 2020, 12:10:14 AM

Previous topic - Next topic

minor28

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.

<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

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.


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

   

aw27

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

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.

aw27

You don't have to apologize, I was explaining to you the reason nobody bothered to answer, have a nice day.