Source language: Translate to:

VBScript For Getting Available Desktop Resolutions

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

VBScript For Getting Available Desktop Resolutions

Postby Cuttlas » Wed Mar 14, 2012 9:05 am

Hi

I'm looking for a vb script which can list all available desktop resolutions,
can anyone help please? :oops:
User avatar
Cuttlas
 
Posts: 60
Joined: Wed Dec 07, 2011 10:45 am

Postby Tony Kroos » Wed Mar 14, 2012 9:40 am

Code: Select all
{NeoBook Function}
Version=5,70
Language=VBScript
Comment=GetVideoResolutions
{End}
On Error Resume Next

dim i, objWMIService, colItems, objItem
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from CIM_VideoControllerResolution")
For Each objItem in colItems
i=i+1
nbSetVar "[Resolution"&i&"]",objItem.HorizontalResolution & "x" & objItem.VerticalResolution _
& "x" & objItem.NumberOfColors & "@" & objItem.RefreshRate
Next

Set colItems = Nothing
Set objWMIService = Nothing


save as file and call "file", you'll get an array of possible resolutions for your video hardware.
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Postby Cuttlas » Wed Mar 14, 2012 10:07 am

Hi tony

Very very nice script, thanks for it :oops: Great Man :)

But there is a problem, I want to list every resolution only one time:

For example it is like this now:

720x480x4294967296@56
720x480x4294967296@60
720x480x4294967296@72

I want to see it only one time in simple mode, like this:

720x480

Can you edit thee script please? :oops:
User avatar
Cuttlas
 
Posts: 60
Joined: Wed Dec 07, 2011 10:45 am

Postby Tony Kroos » Wed Mar 14, 2012 10:30 pm

Note that possible video modes for your monitor and video hardware are different things. Your video card can support any of them, but monitor may not support some modes properly.

Code: Select all
{NeoBook Function}
Version=5,70
Language=VBScript
Comment=GetVideoResolutions
{End}
On Error Resume Next

Dim strRes, strMode, objWMIService, colItems, objItem
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * from CIM_VideoControllerResolution")
For Each objItem in colItems
    strMode = objItem.HorizontalResolution & "x" & objItem.VerticalResolution
    If InStr(strRes,strMode) = 0 Then strRes = strRes & strMode & "|"
Next
nbSetVar "[Resolutions]",strRes

Set colItems = Nothing
Set objWMIService = Nothing


Use strParse to get an array
Code: Select all
StrParse "[Resolutions]" "|" "[Resolutions]" "[n]"
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Postby Cuttlas » Wed Mar 14, 2012 10:37 pm

Hi Tony

You are great in VB Scripting :oops: Thanks for you nice script. Really I was looking for it for a long time :shock:

Thanks again


Now another question :shock:

I have a menu item with the name "Resolutions". I want to add output resolutions of above vb script as sub menus into that menu item.

Is this possible Tony? :oops:
User avatar
Cuttlas
 
Posts: 60
Joined: Wed Dec 07, 2011 10:45 am

Postby Tony Kroos » Wed Mar 14, 2012 10:48 pm

Yes you can, but... you cannot add a new submenu item at runtime. You may prepare a set (15-20 items) of hidden submenu items, then set submenu caption and show it (ShowMenuItem) at runtime. Do you need an example?
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Postby Cuttlas » Wed Mar 14, 2012 10:58 pm

I was thinking about the way you told, but:

1- I can not rename sub menus in run-time.
2- I want to test this publication on several PC and resolutions are different.
So one may have 9 ones, the one 25 ones. What is the maximum number of resolutions? do you know tony? :oops:
User avatar
Cuttlas
 
Posts: 60
Joined: Wed Dec 07, 2011 10:45 am

Postby Tony Kroos » Wed Mar 14, 2012 11:03 pm

Of course no ) but I think, let's say, 30 should be enough )

1- I can not rename sub menus in run-time.

Are you sure? There is a variable for submenu caption somewhere in Project Properties->Main Menu dialog.
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Postby Cuttlas » Wed Mar 14, 2012 11:12 pm

Tony Kroos wrote:Are you sure? There is a variable for submenu caption somewhere in Project Properties->Main Menu dialog.


I have test it now, it seems it is not rename-able.

So if you know a way please tell me :oops:

If there is no way, I think I should use list-boxes instead 8)
User avatar
Cuttlas
 
Posts: 60
Joined: Wed Dec 07, 2011 10:45 am

Postby Tony Kroos » Wed Mar 14, 2012 11:20 pm

I have test it now, it seems it is not rename-able.

No, it works fine at runtime!

Image

.Set submenu caption
SetVar "[MenuItem]" "640x480"

.Show submenu item (by ID)
ShowMenuItem "MenuItem1"
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Postby Cuttlas » Wed Mar 14, 2012 11:25 pm

I have test it again, but again nothing:

SetVar "[MenuItem]" "Cuttlas"

It only store "Cuttlas" in [MenuItem] variable, it does not rename it :(

So Did you test it yourself? Did it worked? :oops:
User avatar
Cuttlas
 
Posts: 60
Joined: Wed Dec 07, 2011 10:45 am

Postby Tony Kroos » Wed Mar 14, 2012 11:30 pm

Yes and it works fine ) It's a variable so when you change it, then caption must be changed too.
--
or you want to rename a variable, why? you don't need that.
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Postby Cuttlas » Wed Mar 14, 2012 11:40 pm

I have used this code:


SetVar "[MenuItem]" "Cuttlas"
ShowMenuItem "MenuItem1"

As you can see in the picture, the "Cuttlas" is stored in [MenuItem], but its name is the same as before.

Image

So do you think where is the problem can be?
User avatar
Cuttlas
 
Posts: 60
Joined: Wed Dec 07, 2011 10:45 am

Postby Tony Kroos » Thu Mar 15, 2012 12:05 am

ok, please provide a sample pub with this problem
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Postby Cuttlas » Thu Mar 15, 2012 12:28 am

Hi Tony, OK

here it is:

Code: Select all
NBW Publication Source File
(C)1993-2011 NeoSoft Corp.
Title=Untitled NeoBook Publication
Language=US
NeoBookVer=5.70
ScreenColors=16777216
ScreenWidth=320
ScreenHeight=200
BkndColor=0
ScreenAutoSize=Yes
LinkColor=16711680
WindowStyle=0
WindowOrder=0
WindowPos=0
WindowProps=95
BiDiMode=0
UseUpdateTimer=Yes
ReturnTime=60
ShapeTransColor=536870912
CompileType=0
MediaType=0
FilesIncluded=1
FontsIncluded=2
CopyExternalFiles=No
SetupMedia=3
SetupInstDir=C:\MyProgram
SetupTitle=Setup
SetupColors=16711680|0|65535
VersionMajor=1
VersionMinor=0
VersionRelease=0
VersionBuild=0
ReqExLevel=1
CustomFontName=Arial
CustomFontSize=9
CustomFontStyle=0
CustomCharset=1
CacheSize=30
ExtractOp=132
L_OK=OK
L_CANCEL=Cancel
L_YES=Yes
L_NO=No
L_CLOSE=Close
L_ERRORTITLE=Error
L_FINDTITLE=Find
L_FINDPROMPT=Find &What
L_FINDFIRST=&Find First
L_FINDNEXT=Find &Next
L_FINDERROR=Search text not found.
L_PWORDTITLE=Password required
L_PWORDMSG=Before continuing, you must first|enter the correct password.
L_PWORDPROMPT=&Password:
L_PWORDERROR=That's not the right password!
L_MEDIAERROR=In order to play this type of file you must install|the appropriate multimedia hardware and/or|software.
L_INTERNETERROR=Unable to locate Internet Browser software.
L_ABORTFUNCTION=Do you want to cancel this function?
L_EXTRACTERROR=This file could not be extracted and cannot be played.
L_INSTDIRPROMPT=Please enter the drive and directory where you would like this program to be installed. To accept the default drive and directory, simply press Enter.
L_INSTFOLDERPROMPT=Do you wish to create a program folder?
L_INSTRUNPROMPT=Do you want to run
L_INSTDISKPROMPT=Please insert disk #
L_INSTDISKERROR=That's not the correct disk, try again.
L_INSTGENERROR=The installation has terminated.
L_INSTEXITPROMPT=Do you really want to cancel the installation?
L_INSTWINTITLE=Setup
L_INSTPROGTITLE=Extracting Files...
L_SENDEMAIL=Sending Mail...
L_MAILSERVER=Please enter the name of your outgoing email server:
L_COPY=Copy to Clipboard
L_SELECTALL=Select All
L_DONWLOADFILE=Downloading: %s
L_PLEASEWAIT=Please wait...
MenuBegin
MenuName=MenuHeading1
MenuText=Main
MenuState=3
MenuKey=0
MenuBegin
MenuName=MenuItem1
MenuText=Cuttlas
MenuState=3
MenuKey=0
MenuBegin
MenuName=MenuItem2
MenuText=MenuItem
MenuState=3
MenuKey=0
MenuEnd
MenuEnd
MenuEnd
TrayMenuBegin
MenuName=TrayOpen
MenuText=Open
MenuState=3
MenuKey=0
MenuAction=SetVar "[WindowState]" "Normal"
MenuName=TrayExit
MenuText=Exit
MenuState=3
MenuKey=0
MenuAction=Exit "" ""
MenuEnd
MasterPage
NewPage=New Page
PageStyle=0
PageColor=16777215
PageGradient1=16711680
PageGradient2=255
PageGradientDir=1
WallpaperStyle=0
ObjectType=3
Name=PushButton1
X=40
Y=40
W=232
H=104
Anchor=0
Text=Change The Submenu's Caption
Align=2
ImageStyle=0
XPTheme=Yes
ObjAction=SetVar "[MenuItem]" "NeoBook"
LineColor=0
LineWidth=1
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=10
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2


Just save itin a file and rename it to name.pub :oops:
excuse me I did not find any way to attach it :(

And can you please reply the PM Tony? :oops: :oops:
User avatar
Cuttlas
 
Posts: 60
Joined: Wed Dec 07, 2011 10:45 am

Next

Return to NeoBook Functions - VBScript & JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest