Monitor Screen Resolution from NAV

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;

Do anyone of you know of such a tool??

Without an external component I don’t see any way to do that.

I know, and that’s what I want to know if anyone has…

If have time during this week I will try to make one.
Do you want only screen resolution or something else? .NET 2.0 or 3.x?

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.

One of the problems with that solution is related to Navigation menu. I not give exact screen form size.

The information I’m really interested in is what resolution the users monitor is running. Not really about the size of the NAV application.

Hi Erik,

I hope this helps. Henrik Skydtsgaard’s blog describes how to write a Navision able COM app with .NET here: http://blogs.msdn.com/skydtsgaard/

From the code project, I found out how to get the screen resolution. You can look at that post here: http://www.codeproject.com/KB/cs/csdynamicscrres.aspx

Based on that, I think the following .NET code will work (just taking a stab at adapting the C#, I’m not a .NET programmer):

using System;

public class ScreenResToNav

{

public ()

{

}

public string ScreenResToNav()

{

		public static Screen PrimaryScreen {get;}
		

```
		Screen screen = Screen.PrimaryScreen;
		int S_width=screen.Bounds.Width;
		int S_height=screen.Bounds.Height;
```

 		return( S_width.toString() + "X" + S_height.toString() ) ; 

}

}

using System;

using System.Runtime.InteropServices;

[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]

public interface INavisionScreen

{

string ScreenResToNave();

}

[ClassInterface(ClassInterfaceType.None)]

public class ScreenResToNav : INavisionScreen

{

public NavisionTest()

{

}

public string ScreenResToNav()

{

		public static Screen PrimaryScreen {get;}
		

```
		Screen screen = Screen.PrimaryScreen;
		int S_width=screen.Bounds.Width;
		int S_height=screen.Bounds.Height;
```

 		return( S_width.toString() + "X" + S_height.toString() ) ; 

}

}

Now the .NET component is ready to be used from Navision

Create a codeunit with a global variable of the type Automation and a subtype with this component.

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:

Height := GetResolution.WorkAreaHeight;
Width := GetResolution.WorkAreaWidth;

Tested with 3.60 on XP SP2

Great tip [Y] I didn’t remember using system information control

Thanks Walter,

That’s a great tip! I’ll assign the task to do it in our system to you rigth now!! (PS: Walter is actually working for my project!)

That was not what I was thinking of when I replied to your post[;)]. I will look at the issue list right now.

Can you mark the answer and the threat as “aswered”[:)]. Or do you want to leave some work for your moderators[H].

Very funny! [;)]

Maybe I just wanted to see it implemented before I closed it! [:)]

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;

}
CODE
{
VAR
Files@1000000000 : File;
x@1000000001 : Integer;
y@1000000002 : Integer;

PROCEDURE makescript@1000000000();
BEGIN
//begin make script
Files.CREATE(‘c:/GetResolution.vbs’);
Files.TEXTMODE := TRUE;

Files.WRITE(‘Set objFSO = CreateObject(“Scripting.FileSystemObject”)’);
Files.WRITE(‘Set objFile = objFSO.CreateTextFile(“C:\result.txt”)’);

Files.WRITE(‘strComputer = “.”’);
Files.WRITE(‘Set objWMIService = GetObject(“winmgmts:\” & strComputer & “\root\cimv2”)’);
Files.WRITE(‘Set colItems = objWMIService.ExecQuery _’);
Files.WRITE(’ (“Select * From Win32_DisplayConfiguration”)’);

Files.WRITE(‘For Each objItem in colItems’);
Files.WRITE(‘objFile.WriteLine(objItem.PelsWidth)’);
Files.WRITE(‘objFile.WriteLine(objItem.PelsHeight)’);
Files.WRITE(‘Next’);
Files.WRITE(‘objFile.Close’);
Files.CLOSE;
END;

PROCEDURE GetScreen@1000000002(VAR ScreenWidth@1000000001 : Integer;VAR ScreenHeight@1000000000 : Integer);
VAR
Screentext@1000000003 : Text[30];
BEGIN
makescript;
SLEEP(10) ;
SHELL('C:\WINDOWS\system32\wscript.exe '+‘c:\GetResolution.vbs’);

SLEEP(100) ;

Files.OPEN(‘C:\result.txt’);
Files.TEXTMODE := TRUE;
Files.READ(ScreenWidth);
Files.READ(ScreenHeight);
Files.CLOSE;
END;

BEGIN
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.

Enjoy.

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…

This is the Navision Code:

CREATE(WSHShell); // Automation Server: ‘Windows Script Host Object Model’.WshShell
MESSAGE(WSHShell.Exec(‘cscript /nologo c:\temp\screenres.vbs’).StdOut.ReadLine);

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