Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Writing High-DPI Win32 Applications
Writing High-DPI Win32 Applications [message #34841] Wed, 14 December 2011 10:45 Go to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi,

I recall a thread wondering about the fuzzyness of TheIDE (and others) when scaling the display to. e.g. 150% on Windows Vista or 7. Now I found an article http://msdn.microsoft.com/en-us/library/dd464660.aspx about Writing High-DPI Win32 Applications.

I added ::SetProcessDPIAware(); call in <CtrlCore/Win32GuiA.h> in GUI_APP_MAIN starting at line 36 as shown below, and got rid of the fuzzyness. Plus all Ctrls I used in my application scaled nicely to 150 %. It is important to note that this call should not be done in a DLL, but instead only in the main application process to avoid race condition. Another way could be adding a manifest, but it seemed like a lot of work to me.

Additionally, this call must be done before reading dpi from Windows, since otherwise Windows reports constantly 96 dpi, and prevents the proper scaling of Ctrls, although fuzzyness may still disappear.

#define GUI_APP_MAIN \
\
void GuiMainFn_();\
\
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdShow) \
{ \
	::SetProcessDPIAware();\
	UPP::Ctrl::InitWin32(hInstance); \
	UPP::coreCmdLine__() = UPP::SplitCmdLine__(UPP::FromSystemCharset(lpCmdLine)); \
	UPP::AppInitEnvironment__(); \
	GuiMainFn_(); \
	UPP::Ctrl::CloseTopCtrls(); \
	UPP::UsrLog("---------- About to delete this log..."); \
	UPP::DeleteUsrLog(); \
	UPP::Ctrl::ExitWin32(); \
	UPP::AppExit__(); \
	return UPP::GetExitCode(); \
} \
\
void GuiMainFn_()


I do not know, if this breaks anything in your applications, but it seems to me UPP handles this nicely.

Could this be merged?

Best regards,

Tom
Re: Writing High-DPI Win32 Applications [message #34845 is a reply to message #34841] Wed, 14 December 2011 11:51 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
For some reason, TheIDE (ide/idewin.cpp) needs the following code instead of the previous solution to work:

static bool dpi_awareness_initializer=::SetProcessDPIAware();

#ifdef flagMAIN
GUI_APP_MAIN
#else
void AppMain___()
#endif


So I guess the universally proper place to put ::SetProcessDPIAware(); is not quite clear to me -- yet...

It needs to be before getting DPI in UPP but not called when we are building dlls.

Best regards,

Tom

Re: Writing High-DPI Win32 Applications [message #34846 is a reply to message #34845] Wed, 14 December 2011 14:24 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tom1 wrote on Wed, 14 December 2011 05:51

For some reason, TheIDE (ide/idewin.cpp) needs the following code instead of the previous solution to work:

static bool dpi_awareness_initializer=::SetProcessDPIAware();

#ifdef flagMAIN
GUI_APP_MAIN
#else
void AppMain___()
#endif


So I guess the universally proper place to put ::SetProcessDPIAware(); is not quite clear to me -- yet...

It needs to be before getting DPI in UPP but not called when we are building dlls.

Best regards,

Tom




Good find, thank you, adding to RM to investigate...
Re: Writing High-DPI Win32 Applications [message #34847 is a reply to message #34846] Wed, 14 December 2011 14:47 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi,

There is yet another related issue of small and large icon sizes covered in http://msdn.microsoft.com/en-us/library/ms701681%28v=VS.85%2 9.aspx .

So, if anybody ever wonders why icons do not scale well in upp applications, there's the answer. The TopWindow::Icon() should be called with properly sized icons depending on DPI to prevent icon raster rescaling.

Best regards,

Tom
Re: Writing High-DPI Win32 Applications [message #34882 is a reply to message #34847] Fri, 16 December 2011 09:31 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Further findings: SetProcessDPIAware(); cannot be called when running in Windows XP, so this will require Vista or higher...

Will come back with further information.

// Tom
Re: Writing High-DPI Win32 Applications [message #34888 is a reply to message #34882] Fri, 16 December 2011 10:38 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
OK, now I have tried to embed a manifest and it seems to work on both Windows XP x32 and Windows 7 x64:

Here's how: First I created a file in the main package directory called manifest.xml:

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
	<asmv3:application>
		<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
			<dpiAware>true</dpiAware>
		</asmv3:windowsSettings>
	</asmv3:application>
</assembly>


Then added a Custom build steps :: Commands:

mt.exe -manifest manifest.xml -outputresource:$(OUTPATH);1


// Tom

[EDIT]

Testing this solution was successful on Windows 2000 Professional, Windows XP Professional x32, Windows Vista Business x64 and Windows 7 Professional x64.

[Updated on: Fri, 16 December 2011 11:21]

Report message to a moderator

Re: Writing High-DPI Win32 Applications [message #39979 is a reply to message #34888] Wed, 22 May 2013 07:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
A little bit late, but... SetProcessDPIAware now used.

As for icon sizes, ide icon designer is already able to export any number of icon sizes into .ico file, so this should be already covered (you just have to provide more icons...).

Mirek
Re: Writing High-DPI Win32 Applications [message #39991 is a reply to message #39979] Thu, 23 May 2013 09:42 Go to previous message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Better late than never! I'll take a look at it some time later; Now my hands are full of work.

Thanks,

Tom

Previous Topic: Compile U++
Next Topic: Is U++ compatible with VC++ Express 2012?
Goto Forum:
  


Current Time: Thu Mar 28 16:19:02 CET 2024

Total time taken to generate the page: 0.01444 seconds