• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 797
  • Last Modified:

Disable 'File' menu when displaying a help file

I have developed a VB6 program that employs user rights which can completely lock down the system so that the user cannot do anything but run our program.  The only part I haven't been able to lock down is removing or disabling the 'File' menu when a help file is being displayed.  I need to disable or remove the File -> Open feature because at that point the user have full access to the drive and can right click on files and delete or edit them.  Does anyone have any ideas?

Currently I call the help file with the following line:

ShellExecute hWnd, "open", SafeAppPath("Alarm Center Help.hlp"), vbNullString, vbNullString, SW_NORMAL

But I have also tried using the CommonDialog object, but they both open it the same way with the same interface.
0
codeconqueror
Asked:
codeconqueror
  • 7
  • 3
  • 3
  • +3
2 Solutions
 
Jaime OlivaresCommented:
If your help page is short maybe you can use a pop-up window:
http://support.microsoft.com/default.aspx?scid=kb;en-us;210166
0
 
codeconquerorAuthor Commented:
No, it's a full help file with lots and lots of screen shots and info on the entire program.  The help file itself is over 15 megs.  It's the one that pops up when the user presses F1.  But thanks for the suggestion, I might be able to use that elsewhere.  :)
0
 
softplusCommented:
How about  file permissions :)

Or, if your help is HTML-based, just add your own help window with a webbrowser control (+ add you own search, but that's not tough).

or, what you wanted:
- Get the help-viewers windows Hwnd
- Do something like this: http://www.devx.com/vb2themax/Tip/19229 to remove the File Menu (you'll have to play around to find which one it is)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
[ fanpages ]IT Services ConsultantCommented:
Hi,

How is your Help file created?

I recall that in Win 3.11 days you could add/remove & change menu items, but it's been over 10 years since I've created Help files, I'm not sure if the principle is still the same now!?!

Please look here, but ignore me if this is no longer applicable.

(I feel old)

http://www.mischel.com/winhelp/undoc1.html

BFN,

fp.
0
 
codeconquerorAuthor Commented:
I'll have to look into what softplus recommended with removing the File Menu, I tried to get the hwnd of the help window earlier without any luck, but I thinks that's my best bet.  I'll have to play around with that a little more.

To answer fanpages:  The help file is loaded using Microsoft Windows Help and the help file is created using RoboHelp (an old version) so I don't have any options to remove menu items or anything like that.  At least not that I know of but I will check on that.

Thanks for the suggestions so far, I'll post back with my results tomorrow.  If anyone else has any other ideas, please speak up.  :)
0
 
grayeCommented:
I can see two solutions...

1) change your help file to a Compiled HTML (a .chm) file.   I looks a lot more modern, and doesn't even have a menu bar at all!
     or
2) after the help is showing, use the Window's APIs to find the handle to the application, get the handle to the menu, disable the menu

I've got an example of disabling a menu in C++ and VB.Net (the example is not exactly what you're after, but it demonstrates the concepts)... interested?
0
 
[ fanpages ]IT Services ConsultantCommented:
RoboHelp 2000 supports the disabiling of menus:
http://www.helpstuff.com/HelpCornerArchives/02-2000/hc2-00.htm

Which version are you using?

BFN,

fp.
0
 
Eduard GherguCommented:
You can use WaitForSingleObject and OpenProcess API functions instead of ShellExecute.
In this way you'll know exactly when the user will close the help application.
So, you can do in the following way:

1. Disable the File menu
2. Call the help file
3. Enable the File menu.

For a good example, you can have a look at:
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=34927&lngWId=1
0
 
[ fanpages ]IT Services ConsultantCommented:
...Once the help application is closed, why bother to re-enable the File menu?
0
 
codeconquerorAuthor Commented:
Well so far I have managed to convert the .HLP file to a .CHM file, but then I get the 'Jump to URL' option and access to the internet options and haven't found a way to disable them.  I also tried decompiling the .HLP file and edit it with RoboHelp and tried to disable the File menu there, but couldn't figure out how.  I'm going to try to disable it by trying to get it's hWnd.  I'll repost later as to my success or failure.
0
 
codeconquerorAuthor Commented:
No luck so far.  Here's the code I've started working with:

<CODE>
Option Explicit
Option Compare Text

Private Declare Function GetMenu Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, ByVal nPos As Long) As Long
Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpString As Any) As Long
Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hwnd As Long) As Long

Private Const MF_BYPOSITION = &H400&
Private Const MF_REMOVE = &H1000&
Private Const INFINITE = &HFFFF

Public Function WaitShell(ByVal sCommand As String, Optional ByVal bWaitUntilDone As Boolean = True, Optional ByVal bJustReturnhWnd As Boolean = False) As Long
'**** Executes the specified command with the option to wait until that process terminates
20          Dim lId As Long
30          Dim lHandle As Long
40          Dim lRetVal As Long
50          lId = Shell(sCommand, vbHide)
            If bJustReturnhWnd Or bWaitUntilDone Then
60              lHandle = OpenProcess(&H100000, True, lId)
            End If
            If bJustReturnhWnd Then
                WaitShell = lHandle
            ElseIf bWaitUntilDone Then
70              lRetVal = WaitForSingleObject(lHandle, INFINITE)
            End If
End Function

Public Function RemoveFileMenuFromHelp(ByVal lhWnd As Long)
    Dim lLoop As Long
    Dim hSysMenu As Long, nCnt As Long
    ' Get handle to our form's system menu
    ' (Restore, Maximize, Move, close etc.)
    hSysMenu = GetSystemMenu(lhWnd, False)

    If hSysMenu > 0 Then
        ' Get System menu's menu count
        nCnt = GetMenuItemCount(hSysMenu)
        If nCnt Then
            ' Menu count is based on 0 (0, 1, 2, 3...)
            For lLoop = (cnt - 1) To 0 Step -1
                RemoveMenu hSysMenu, lLoop, MF_BYPOSITION Or MF_REMOVE
            Next
            DrawMenuBar lhWnd
            ' Force caption bar's refresh. Disabling X button
        End If
    End If

End Function
</CODE>

I can successfully get the hWnd of the open help window, but I can't figure out how to access the hWnd of the menu much less do anything with it.  The line:
hSysMenu = GetSystemMenu(lhWnd, False)
always returns a 0.  Anyone have any ideas?
0
 
codeconquerorAuthor Commented:
Anyone?  Anyone at all?  :)
0
 
grayeCommented:
The SystemMenu is not what you're after... (that's the normal Restore, Move, Size, Min, Max, Close that is associated with the title bar's icon).  

You need the "normal" menu bar... which you could find by iterating through all of the child windows of the main window.
0
 
codeconquerorAuthor Commented:
Don't suppose you have any sample code or could point me to some so I have a general idea of what I'm looking to do?
0
 
grayeCommented:
Hey, you're 99.44% there... all you have to do is use GetMenu and GetSubMenu instead of GetSystemMenu...  The rest of your example is great.  I'd consider using EnableMenuItem instead of RemoveMenu

Here is a simple VB.Net example that just shows how to list the menu structure of a running window

        Dim hWnd, hMenu, hSub As IntPtr
        Dim buf As String
        Dim i, j, l As Integer

        hWnd = FindWindow(Nothing, "YOUR WINDOW TEXT HERE")
        hMenu = GetMenu(hWnd)

        buf = Space(256)
        For i = 0 To GetMenuItemCount(hMenu) - 1
            l = GetMenuString(hMenu, i, buf, 255, MF_BYPOSITION)
            Debug.WriteLine(buf.Substring(0, l))
            ' get the submenu
            hSub = GetSubMenu(hMenu, i)
            For j = 0 To GetMenuItemCount(hSub) - 1
                l = GetMenuString(hSub, j, buf, 255, MF_BYPOSITION)
                Debug.WriteLine("      " & buf.Substring(0, l))
            Next
        Next
0
 
Eduard GherguCommented:
Hello!
If you made the conversion to .chm format, the life is easier now! You can create a custom help viewer using WebBrowser ActiveX control.
You can make reference to your default topic using a statement like this one:

WebBrowser1.Navigate2 "mk:@MSITStore:C:\WINNT\Help\windows.chm::/default.htm"

where instead of C":\WINNT\Help\windows.chm" you'll put your file path and name, of course...
It's up to you to create a menu or not, a toolbar or not etc.

See also:http://msdn.microsoft.com/workshop/browser/webbrowser/reference/methods/navigate2.asp
0
 
codeconquerorAuthor Commented:
Thanks for graye and ghergu, you both gave me great ways to overcome the problem and all is working perfectly now.  I'll split the points between you.  To everyone else, thanks a bunch for your help it was greatly appreciated.  Have a great day all.  :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 7
  • 3
  • 3
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now