|
I have checked it, found few things that are not in compliance with my article.
1. First of all, you should have set explicit font for the dialog. Close your development studio and open test_setdpi.rc in notepad. Run notepad and open test_setdpi.rc
2. Press Ctrl-F (for find) and type in "DIALOG DISCARDABLE"
3. Here are the parts that match: (two of them in your case)
------------
IDD_ABOUTBOX DIALOG DISCARDABLE 0, 0, 235, 55
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About test_setdpi"
FONT 8, "MS Sans Serif"
------------
And another part:
------------
IDD_DIALOG_TEST DIALOG DISCARDABLE 0, 0, 352, 156
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "Microsoft Sans Serif"
------------
About box might be of little importance, but let's change it also.
4. Now we are doing hand editing to this. As I said in the article, DIALOG resource entries do not work. Only DIALOGEX do. So you change the lines to appear like:
---------------
IDD_ABOUTBOX DIALOGEX DISCARDABLE 0, 0, 235, 55
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About test_setdpi"
FONT 8, "Microsoft Sans Serif"
---------------
IDD_ABOUTBOX DIALOGEX DISCARDABLE 0, 0, 235, 55
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About test_setdpi"
FONT 8, "Microsoft Sans Serif"
---------------
Pay attention - I have changed DIALOG to DIALOGEX, added DS_SETFONT as additional flag right after STYLE, and changed font name to Microsoft Sans Serif. (for my own projects I normally use Tahoma font)
5. Save the file from Notepad
6. Recompile all, run. If something doesn't work - go back to this file and check that all options are intact.
Thanks,
George.
http://www.yohng.com/
|
|
|
|
|
Hey folks,
the reason why the code doesn't work in Windows 98 is because it uses unicode versions of functions and datatypes (CreateFontW, wcslen e.g.) which are not available in Win 98 since it does not support unicode.
I got the code running in Win98 using the Microsoft Layer for Unicode(MSLU). That layer translates unicode api calls when the appliction is run under Win95/98/Me. For detailed information on MSLU and how to get and implement it, see:
http://msdn.microsoft.com/msdnmag/issues/01/10/MSLU/default.aspx
Attention: The unicows.lib file that comes with the latest Platform SDK was built with MS VC++ 7 and is not fully compatible with VC++ 6.
Workaround: Don't use the /DEGUG flag in VC++6, use VC++7 of course or use a alternative unicows.lib from http://libunicows.sourceforge.net. This .lib file can be used with a bunch of other compilers too and, what's nice also, you don't need to download the huge Platform SDK from Microsoft in order to get the lib file.
Hope that helps.
Regards,
Arno
|
|
|
|
|
Arno, it works, thanks a lot !
|
|
|
|
|
Hi,
I tried this code with ActiveX controls(I am using Microsoft Slider Control 6.0(SP4)). Its not working. remaining things are working fine.. Also this code not working in Windows98. Any one, can help me to correct this..
Thanks,
Vallikumar
|
|
|
|
|
Dear George,
I hope, your codes are very useful for beginner programmers like me.. I developed one dialog based MFC project in VC++ 6.0 and using Win2000 OS. I implemented your codes inside that, like what you said above..
First I had two errors..
1. error C2065: 'DWORD_PTR' : undeclared identifier
2. error C2065: 'IMAKEINTRESOURCE' : undeclared identifier
For 'DWORD_PTR' error, I declared like this..
typedef unsigned long DWORD_PTR;
and For 'IMAKEINTRESOURCE' error, I changed IMAKEINTRESOURCE to
MAKEINTRESOURCE.
Then the project is running without any error.. But the Font dpi working only for main Dialog window. All other child dialogs are not working properly..
For example.. I call one child dialog box from main dialog. In side the subdilaog's OnInitDialog(), I called this function...
dpi.Attach(AfxFindResourceHandle(MAKEINTRESOURCE(IDD), RT_DIALOG),m_hWnd,IDD,192.0);
but the sub dialog window not resized properly and the size is smaller than origanal of it..
Can you clear my doubts please..
Thanks,
Vallikumar A
|
|
|
|
|
Check that child dialog has Tahoma set as dialog font.
http://www.yohng.com/
|
|
|
|
|
Thanks for your immediate response..
Yes, I used Tohoma as dialog font for all dialogs. I tested with simple MFC application with two dialogs. But having the same problem.. main dialog only working properly and the second one child dialog having problem..
please, Can you (any one) try this with simple MFC dialog applications with more than one dialogs...
Thanks,
Vallikumar A
|
|
|
|
|
Oh well, a problem could be that your dialog is non-modal.
For non-modal dialog, OnInitDialog may not be called....
Try handling OnShow event and moving code there.
For modal dialogs, it should work in OnInitDialog
http://www.yohng.com/
|
|
|
|
|
Dear Yohng,
Thanks for your kind help..
Now its working fine.. I use only modal dialogs.. I enabled the ToolWindow in Dialog properties. After this its Ok..
Once again thanks...
Vallikumar A
|
|
|
|
|
This article is very usefull for me..But i could not run this project in VC++..If some one could help me to make this
workspace as .dsw then i will be greatful to him/her.
Thanks every body .
Ashif.
|
|
|
|
|
This article is very usefull for me..But i could not run this project in VC++..If some one could help me to make this
workspace as .dsw then i will be greatful to him/her.
Thanks every body .
Ashif.
|
|
|
|
|
You don't need to re-compile the example, as executable is included.
To use it in your application, just add setdpi.cpp and setdpi.h into your project
VC++ may want you also to add this line in the beginning of setdpi.cpp:
#include <stdafx.h>
Once you add the file into your project, it should compile fine. It even compiles fine with GNU compiler.
Follow the instructions and modify your forms/dialogs as stated in the article - and they will preserve their size.
http://www.yohng.com/
|
|
|
|
|
Hi,
do you have any idea how to change the dialog size to cover the full screen
no matter what screen-resolution the user is actualy using.
Thanks
Mario
|
|
|
|
|
Hello, Mario!
The font has horizontal and vertical resolutions.
If the modes are uniform (e.g., 640x480, 800x600, 1024x768, 1280x960), then the scaling will be uniform too, and you can design dialog for say 800x600 at 96DPI, and then use
DPI = 96.0 * ScreenWidth / 800;
where ScreenWidth is of a new resolution.
But I doubt that you want exactly this, as all the fonts will scale and will look unnaturally large for larger resolutions (same when you scale a macromedia flash movie).
(Message dialogs, pulled onto full screen in this way normally scare users to death, especially with red text).
I believe, you are looking more for a proper layout engine, than a font scaling procedure. Unfortunately, such libraries as MFC and ATL/WTL do not provide a sane way to layout controls.
This CodeProject article looks interesting:
http://www.codeproject.com/wtl/HtmLayout.asp
I believe there are simplier and free solutions.
Thanks,
George.
http://www.yohng.com/
|
|
|
|
|
Hi George,
>If the modes are uniform (e.g., 640x480, 800x600, 1024x768, 1280x960), then the scaling will be uniform too, and you can >design dialog for say 800x600 at 96DPI, and then use
>DPI = 96.0 * ScreenWidth / 800;
>where ScreenWidth is of a new resolution.
That's exactly what I'am doing now, but having the problem you mention.
Actualy I'am writing a calculator program for schools and diabled people,
and especialy people with eye problem love to have large fonts. What I
try do to is to give them the possibility to change the dialog window to
there special needs.
>same when you scale a macromedia flash movie
They use vector fonts, would be great to have vector dialogs, that would give
us great value. I've heard Longhorn will have such a new graphic interface!
Have a look what I'am doing now, works for most of the possible cases. Well
suppose large, small, medium font, 5 different Windows versions and dozens
of resolutions, and you know what I'am talking about.
-----
Thank you for your support
Mario
void CDeskCalcDlg::OnMenuSizefull()
{
RECT wndRect, trayRect;
GetClientRect(&wndRect);
m_Dpi.Attach(AfxFindResourceHandle(MAKEINTRESOURCE(IDD), RT_DIALOG),m_hWnd,IDD, 72);
GetClientRect(&wndRect);
// Screen resolution
double screenWidth = GetSystemMetrics(SM_CXSCREEN);
double screenHeight = GetSystemMetrics(SM_CYSCREEN);
int wndWidth, wndHeight;
wndWidth = wndRect.right;// - wndRect.left;
wndHeight = wndRect.bottom;// - wndRect.top;
// Find the taskbar
CWnd* pWnd = FindWindow(_T("Shell_TrayWnd"), _T(""));
if(pWnd) {
pWnd->GetWindowRect(&trayRect);
screenHeight = screenHeight - 4*(trayRect.bottom - trayRect.top);
}
double fac;
double facx = (double)(screenWidth/(double)wndWidth);
double facy = (double)(screenHeight/(double)wndHeight);
if(facx > facy) fac = facy;
else fac = facx;
fac = m_Dpi.getDpi()*fac + 1;
m_Dpi.Attach(AfxFindResourceHandle(MAKEINTRESOURCE(IDD), RT_DIALOG),m_hWnd,IDD, fac);
v_adjustFonts();
m_ex.drawTape();
m_Option_Size = (int)fac;
SetButtons(m_Option_Buttons);
}
|
|
|
|
|
Why don't have effect in windows98
|
|
|
|
|
I don't know
I didn't test on win98, but it's supposed to work everywhere.
Probably someone will send me a solution, so that I could update the article.
Thanks,
George.
http://www.yohng.com/
|
|
|
|
|
I like your code, it works fine with Win2000 and newer but not with Win98. I’ve tried to fix this, but i can’t get it to work. If anybody solves this problem, please let me know.
Thanks
Mario
|
|
|
|
|
No news about this issue? What a pitty. Would like to use the code in win98, too. I installed Microsoft Sans Serif font (from win2k) on the win98 machine since it's not included in the win98 default fonts, but didn't help. Does that mean it's not a problem of the font? Any ideas?
Regards,
Arno
|
|
|
|
|
Very nice technique!! I've been looking for a solution to this problem like this. The only problem I now have is: I'm using Borland C++. I want to call the Attach, but I do not know where to get the Dialig resource ID from. I've only come this far:
// returns the HINSTANCE of the resource module associated with the executable
// use the global FindResourceHInstance function to obtain the handle of the current resource module
int res_instance = FindResourceHInstance((int)HInstance);
if (res_instance!=0) {
}
Do you perhaps know how to get the Form resource ID's in Borland? How do I use your technique in Borland C++?
I really think this is very good.
|
|
|
|
|
Hello, HeinrichJF...
I'm not too sure if it would be helpful for Borland VCL sources, as they use different resource format.
Though, if you are using legacy borland win32 with standard windows resources, you can always look into RC file to find out dialog ID, as per standard it is normally declared in Resource.h file also
Thanks,
George.
http://www.yohng.com/
|
|
|
|
|
Did you ever stop to think that not everybody is a moron? There are users who actually take their time and setup their display's resolution properly. Then a "smart" programmer comes along and decides they know better and creates an application that's unusable.
|
|
|
|
|
Hello Jerry,
Sorry, I don't exactly understand what do you say (exhausted after a long night ), but I'll try to answer anyway.
Sometimes the software is already designed, and it's a serious problem to port it to the large-fonts-mode and to correct all the wrecked dialog resources and bitmaps.
It is true that everything should be designed properly from the very beginning, but I have seen many applications that are not.
A normal non-moron end-user would rather want applications to look smaller than totally wrecked. So here's a good opportunity for developers to fix it quick, until they get some time for a redesign.
P.S.: Well, if I were Microsoft, I would build some sane layout mechanism into MFC, that would solve this problem in a more gentle way.
Thanks,
George.
http://www.yohng.com/
|
|
|
|
|
You are seriously out of line here.
As you are so enlightened why do you know share with us all the method of designing properly.
I know of no current easier way to implement this without this code without resorting to resizing the dialog and all controls size and positions in OnInitDialog() function.
When the DPI of windows get changed, the dialog becomes totally screwed.
So share the knowledge or shut up.
cheers
NicW
|
|
|
|
|
I happen to agree with the grandparent. As a former tester at Microsoft for Office, I feel that I have some ground to stand here with my position.
Yes, dialog layout is hard. We actually invented our own layout system in Office to address changing text size, not only with DPI related issues, but also for adjusting the text for different translations. Imagine trying to get 33 different languages to look right in a dialog while simultaneously supporting different DPI settings and font sizes.
As a developer myself, I can equally understand the frustration that other developers feel. My advice is, build all your dialogs to support 120 DPI/Large Fonts at a minimum. Things will scale down to fit generally better than they scale up.
The worst thing you can do is force the user to size a dialog so that it is fixed at a 96 DPI while the rest of their system is 120 DPI. Large fonts is a setting for the visually impared, and by following this, you are creating a program that breaks accessability. Similarly, high DPI is a setting released with Windows Me that further improves readability for high resolution/high density devices; specifically some laptops where their LCD screens have a surface that far exceeds the density of most CRTs.
I believe Avalon, or rather Windows Presentation Foundation[^] will help make this easier, especially as with XAML you can easily define flow panels to reflow text and other UI elements on the fly. In the mean time, users that select a high DPI setting expect some of their apps to act in odd ways. It's better they act odd and that the user can read them than they act sanely and are unreadable... although I think I could safely argue that an app that doesn't follow the system settings for DPI seems pretty bizzare to the end user too.
|
|
|
|
|