I have a few forms which needs to alterated based on the users screen resolution.
So what I’m looking for is a small function which I can use to “read” the users screen resolution and based on this input direct the user to the right form.
Something like this:
CASE GetScreenResolution OF
‘1280x1024’ : FORM.RUN(NormalForm);
‘1024x768’ : FORM.RUN(SmallForm);
END;
The easiest solution is to open a form an switch it to full screen, then just read the current screen size in NAV. Of course if NAV is not full screen in windows, it will only report the available space, but that is probably ok anyway.
Why not use the Microsoft SysInfo Control, version 6.0 (if you have XP in X:\WINDOWS\System32\sysinfo.ocx)? Declare GetResolution Datatype::OCX Microsoft SysInfo Control, version 6.0 and then just:
Well, that was a great tip. However, some of you might have a problem to use an OCX as mentioned. Some even might have a problem using the “Common Dialog Management”-OCX.
So, if you have access to “wscript.exe” in the C:\WINDOWS\system32\ directory and VB is installed you can try something like this:
OBJECT Codeunit 77777 77777
{
OBJECT-PROPERTIES
{
Date=02/25/08;
Time=10:00:21 PM;
Modified=Yes;
Version List=#853-wk VBscript; {ignore Version List}
}
PROPERTIES
{
OnRun=BEGIN
GetScreen(x,y);
MESSAGE(‘Screen resolution %1 x %2’,x,y)
END;
This Codeunit will give you access to the “Resolution” without any OCX or any other .NET component. You might have to change the path for your “output script” to the “current user” has access to. If you don’t want to use a codeunit, you can use the code in a report as well.
Well the most elegant solution is of course the system info ocx (by the way the values returned by sysinfo are somewhat odd, for example with my 1024x768 resolution I get 15360 and 11520 for WorkAreaWidth and WorkAreaHeight, respectively which is a factor of 15…), but if you want to use Windows Scripting Host, there is another possibilty and it’s quite interesting because it offers a general way to retrieve the output of a script into Navision without using a file…
Now the content of screenres.vbs is similar to the one above:
For Each objItem in GetObject(“winmgmts:\.\root\cimv2”).ExecQuery(“Select * From Win32_DisplayConfiguration”) WScript.StdOut.WriteLine objItem.PelsWidth & “x” & objItem.PelsHeight Next