Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #361

Re: Overriding Windows display settings - vb6

From "Mike Williams" <Mike@WhiskyAndCoke.com>
Newsgroups comp.lang.basic.visual.misc
Subject Re: Overriding Windows display settings - vb6
Date 2011-08-12 21:23 +0100
Organization A noiseless patient Spider
Message-ID <j24222$h17$1@dont-email.me> (permalink)
References <62ddb9d6-ee83-4100-887e-73ac27d68979@c29g2000yqd.googlegroups.com>

Show all headers | View raw


"Brigand" <markashall@hotmail.com> wrote in message 
news:62ddb9d6-ee83-4100-887e-73ac27d68979@c29g2000yqd.googlegroups.com...
> Run into a minor problem that I'm not sure if I can fix easily.
> Basically, I am using a form and printing characters at specific
> locations on the form:
> form1.currentx = 10
> form1.currenty = 10
> form1.print "text"
> This works perfectly fine 90% of the time. The problem occurs for
> users who have changed the dpi settings, or turned on some of the
> ease of access settings that make the fonts biggers, or raise the
> contrast or whatever. As far as my program goes, the end result is
> the text no longer appears where I want it to. The relative positions
> of the text are ok, but the drawn graphics do not get
>
> Is there some way to override these settings in your programs, and
> force them to display in a constant font and size??

It looks like some of your intended post is missing there (the bit after the 
'graphics do not get' phrase) but I think I can see what you are saying. The 
very first thing you need to do, before you even consider doing anything 
else, is to make sure that your program is not messed up when it is run on 
Vista and Win7 machines where the user has set a large dpi setting (usually, 
but not always, larger than 120 dpi) and where they have not placed a tick 
in the box 'Use WindowsXP Style DPI Scaling'. In such cases, unless you do 
something about it, Windows will lie to your VB program about the dpi 
setting and it will lie extremely convincingly, affecting not only VB 
properties and methods but also any GDI function you might be using. It will 
tell your VB program that the machine is running at 96 dpi, even though it 
is not! So, your VB code will run and do its stuff just as though there were 
96 dpi on the machine (even though it is not true!) and Windows will draw 
all your program's output into a hidden backbuffer, from where it will then 
stretch it onto the actual display so as to enlarge it to suit the actual 
dpi setting of the machine. This not only produces fuzzy text and other 
things but it can also cause all sorts of other problems.

In order to prevent the above stuff from causing problems you need to make 
sure that your VB program declares itself as being DPI Aware. This will tell 
Windows not to mess about and not to lie to your program about the dpi 
stuff. You also need to make sure that you write your code in such a way 
that it actually is DPI aware of course (that it checks the dpi setting of 
the machine and acts accordingly when it feels the need to do so), but from 
the tone of your post I think you are probably already doing that. There is 
an API function called SetProcessDPIAware which you might come across, but 
this function is in many cases not reliable because (and I think this is the 
case with VB programs) a program caches lots of information about the 
machine's dpi and other settings /before/ the very first line of the actual 
code is executed, so by the time your code calls the SetProcessDPIAware 
function it is already too late. You can overcome this problem by instead 
using a manifest, because Windows acts on the contents of the manifest 
before it even starts running your program code. The manifest needs to 
declare that your program is DPIAware. The manifest can either accompany 
your program as a seperate file, or it can be embedded into your .exe file 
(the latter is the best way in my opinion). There is a program out there 
called MMM which will do this stuff for you (and a lot more) automatically 
(as long as you set it up accordingly). You can download it at:

    http://mmm4vb6.atom5.com/

It is quite a while since I used MMM and the last time I did so I noticed 
that the SetDPIAware section which it embedded into the manifest worked fine 
On Vista but did not work at all on Win7. I posted a comment and a fix about 
this problem on the MMM site some time ago but I have not since been there 
and so I do not know whether their current version has been fixed. 
Basically, my fix was as follows:

1. Replace the line:

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">

. . . with the line:

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" 
xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >

2. Replace the section:

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

. . . with the section:

<asmv3:application>
<asmv3:windowsSettings 
xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>

Anyway, there are various other things I think I should mention regarding 
your apparent quest for text which aligns and sizes and positions correctly 
in relation to other graphics which you are drawing (point sizes versus 
pixel sizes and all sorts of things), but I think it might be wise to leave 
that until you have sorted out the DPI Aware stuff. Post again when you have 
done that.

Mike



 

Back to comp.lang.basic.visual.misc | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Overriding Windows display settings - vb6 Brigand <markashall@hotmail.com> - 2011-08-12 12:01 -0700
  Re: Overriding Windows display settings - vb6 "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-08-12 21:23 +0100
    Re: Overriding Windows display settings - vb6 "Ivar" <ivar.ekstromer000@ntlworld.com> - 2011-08-14 11:33 +0100
      Re: Overriding Windows display settings - vb6 "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-08-14 13:30 +0100
        Re: Overriding Windows display settings - vb6 "Ivar" <ivar.ekstromer000@ntlworld.com> - 2011-08-14 14:06 +0100
          Re: Overriding Windows display settings - vb6 "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-08-14 23:36 +0100
            Re: Overriding Windows display settings - vb6 GS <gs@somewhere.net> - 2011-08-14 20:03 -0400
              Re: Overriding Windows display settings - vb6 "Nobody" <nobody@nobody.com> - 2011-08-15 09:30 -0400
                Re: Overriding Windows display settings - vb6 GS <gs@somewhere.net> - 2011-08-15 10:58 -0400
                Re: Overriding Windows display settings - vb6 Brigand <markashall@hotmail.com> - 2011-08-16 05:42 -0700
                Re: Overriding Windows display settings - vb6 "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-08-16 14:01 +0100
                Re: Overriding Windows display settings - vb6 -mhd <not_real@invalid.com> - 2011-08-16 15:04 -0400
                Re: Overriding Windows display settings - vb6 "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-08-16 22:02 +0100
            Re: Overriding Windows display settings - vb6 Tony Toews <ttoews@telusplanet.net> - 2011-08-19 15:34 -0600
  Re: Overriding Windows display settings - vb6 "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-08-13 15:27 +0100
  Re: Overriding Windows display settings - vb6 Deanna Earley <dee.earley@icode.co.uk> - 2011-08-23 15:05 +0100
    Re: Overriding Windows display settings - vb6 "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-08-26 17:48 +0100
      Re: Overriding Windows display settings - vb6 ralph <nt_consulting64@yahoo.net> - 2011-08-26 22:06 -0500
        Re: Overriding Windows display settings - vb6 -mhd <not_real@invalid.com> - 2011-08-27 11:58 -0400
          Re: Overriding Windows display settings - vb6 Dr J R Stockton <reply1134@merlyn.demon.co.uk> - 2011-08-28 18:48 +0100
      Re: Overriding Windows display settings - vb6 Schmidt <sss@online.de> - 2011-08-27 19:23 +0200
        Re: Overriding Windows display settings - vb6 ralph <nt_consulting64@yahoo.net> - 2011-08-27 16:56 -0500
          Re: Overriding Windows display settings - vb6 Schmidt <sss@online.de> - 2011-08-28 01:33 +0200

csiph-web