Wednesday, June 25, 2008

Detecting Classic Start Menu or Start Menu

On some of our regression tests, we need to check that all shortcuts that our product created under Windows Start Menu is working. One of the challenge this one presents is that user can set it to either "Classic Start Menu" or the new XP style Start Menu. Since our organization likes to use Visual Tests, I was looking for a way to detect what is the current style of Start Menu, hence the script below was born:

'Refs
'http://www.themssforum.com/VisualBasic/SHGetSetSetting-SHELLFLAGSTATESHELLSTATE/
'http://msdn.microsoft.com/en-us/library/bb762200(VS.85).aspx
'http://msdn.microsoft.com/en-us/library/bb759788(VS.85).aspx

Option
Explicit
Private
Declare Sub SHGetSetSettings Lib "shell32" _
(ByRef lpSS As Byte, ByVal dwMask As Long, ByVal bSet As Long)
Const SSF_STARTPANELON =
&H200000

Public Function IsXpMenuStyleOn() As
Long
   
'SHELLSTATE is 36 byte structure
    IsXpMenuStyleOn =
0
    
    Dim Buf(0 To 35) As
Byte
    
    SHGetSetSettings Buf(0), SSF_STARTPANELON,
0
    If Buf(28) = 2
Then
        IsXpMenuStyleOn =
1
   
Else
        IsXpMenuStyleOn =
0
    End
If
End
Function

 

You can put this in Common project under Shared Module or Module. For my case I saved it to Module asset named DesktopUtilities. Now to use this, create a test script that looks like the following:

Sub Main()
    Include
"Common.DesktopUtilities"
        
    bXpStyleOn = DesktopUtilities.IsXpMenuStyleOn()
End Sub

 

Note that you need to define bXpStyleOn as TP output variable, and then you need to get the return value into a Visual Test variable. Once you know what is the current Window Menu Style you can create a decision logic to run different Visual Test script depending on the returned value.

 

Happy Test Partner coding !!!

 

~ts

No comments: