Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hooking a menu 1

Status
Not open for further replies.

Supra

Programmer
Joined
Dec 6, 2000
Messages
422
Location
US
Hello folks! I'm working on a front-end for Microsoft Internet Explorer which incorporates tabbed browsing and Direct Document Object Model Editing. Anyway, I've run into a strange problem with the code I'm using to hook the Favorites menu. The Favorites menu works flawlessly, but when I click the ComboBox I'm using as an address bar, the application crashes immediately. This happens in debug mode and as a stand-alone EXE. When I comment out the code to hook the menu, everything works fine, except I cannot open my Favorites. Here's the code I am using to hook my Favorites menu:
Code:
    ProcRet& = GetWindowLong(Main.HwND, GWL_WNDPROC)
    Call SetWindowLong(Main.HwND, GWL_WNDPROC, AddressOf MenuProc)
And here is the MenuProc function:
Code:
Public Function MenuProc(ByVal HwND As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If wMsg& = WM_CLOSE Then
        Call SetWindowLong(HwND&, GWL_WNDPROC, ProcRet)
    ElseIf wMsg& = WM_COMMAND Then
        If wParam& >= 1000 Then
            Main.Web(Controller(Main.Tabs.SelectedItem.index)).Navigate FavoriteLinks(wParam - 1000)
        End If
    End If
MenuProc = CallWindowProc(ProcRet&, HwND&, wMsg&, wParam&, lParam&)
End Function
I am going insane trying to figure out why this hook would interfere with anything on the form, let alone a ComboBox!? Any help with this problem will be extremely appreciated :)
 
Because, for reasons I'm not going to go into here, the combobox sends a number of its notifications (e.g. CBN_DROPDOWN and CBN_CLOSEUP) to it's parent window. And it sends these notifications via WM_COMMAND. Additionally, the specific notification value is held in the high-order word of wParam, which means its lowest possible value would be 65536.

In other words, whenever you click on (or release)that dropddown arrow on the combobox, you are getting a WM_COMMAND message, with a wParam containing a value greater than 1000...which means that you are inappropriately triggering you Navigate function.

Given the above information, you should be able to figure out an appropriate solution.
 
I beat you to it but you are you absolutely correct. I spit out wParam to the debug window and clicked the combo box - sure enough, wParam was over 65536 which my code found perfectly acceptable. I've limited the Favorites count to 1000 links so this won't be a problem anymore. Thanks for the excellent information strong. You definitely get a star from me :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top