Click here to Skip to main content
15,887,240 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
This is a very strange problem. I have an embedded WebBrowser control, and sometimes, depending on my previous action, the keyboard shortcuts for selected menu items (like "Alt-F" to pull down the File menu) do not work. Other times, they do.

When I run Spy++, I can see that the window that is receiving the keypress is different when it does work and when it doesn't work, resulting in a completely different set of behavior (if it does work, all sorts of happy WM_PAINT messages appear and the menu appears.)

Both windows belong to "Windows Explorer Server", the only difference is that when the shortcut keys don't work, the location of the window's top-left corner is negative.

The questions are, how do I get keyboard shortcuts to consistently work? Anyone experience this before? I suppose I could try setting the focus to the "real" Windows Explorer Server window, but I haven't tried that yet.

Here's a trace for a failure:

<008166> 000D04AA P WM_SYSKEYDOWN nVirtKey:'F' cRepeat:1 ScanCode:21 fExtended:0 fAltDown:1 fRepeat:0 fUp:0
<008167> 000808B8 P message:0x8002 [User-defined:WM_APP+2] wParam:00000000 lParam:00000000
<008168> 000D04AA P WM_SYSCHAR chCharCode:'102' (102) cRepeat:1 ScanCode:21 fExtended:0 fAltDown:1 fRepeat:0 fUp:0
<008169> 00380370 S WM_GETTEXTLENGTH
<008170> 00380370 R WM_GETTEXTLENGTH cch:4
<008171> 00380370 S WM_GETTEXT cchTextMax:10 lpszText:0046DB0C
<008172> 00380370 R WM_GETTEXT cchCopied:4 lpszText:0046C8F8 ("Ýc²V")
<008173> 001507A4 S WM_GETTEXTLENGTH
<008174> 001507A4 R WM_GETTEXTLENGTH cch:6
<008175> 001507A4 S WM_GETTEXT cchTextMax:14 lpszText:0046DB08
<008176> 001507A4 R WM_GETTEXT cchCopied:6 lpszText:0046C8F4 ("")
<008177> 000908A0 S WM_GETTEXTLENGTH
<008178> 000908A0 R WM_GETTEXTLENGTH cch:4
<008179> 000908A0 S WM_GETTEXT cchTextMax:10 lpszText:0046DB0C
<008180> 000908A0 R WM_GETTEXT cchCopied:4 lpszText:0046C8F8 ("Ýc²V")
<008181> 0019078C S WM_GETTEXTLENGTH
<008182> 0019078C R WM_GETTEXTLENGTH cch:5
<008183> 0019078C S WM_GETTEXT cchTextMax:12 lpszText:0046DB0C
<008184> 0019078C R WM_GETTEXT cchCopied:5 lpszText:0046C8F8 ("Ýc²V")
<008185> 000D04AA S WM_SYSCOMMAND uCmdType:SC_KEYMENU xPos:102 yPos:0 (used mnemonic)
<008186> 00120924 S WM_ENTERMENULOOP fIsTrackPopupMenu:False
<008187> 00120924 R WM_ENTERMENULOOP
<008188> 00120924 S WM_SETCURSOR hwnd:00120924 nHittest:HTCAPTION wMouseMsg:0000
<008189> 00120924 R WM_SETCURSOR fHaltProcessing:False
<008190> 00120924 S WM_INITMENU hmenuInit:118E0043
<008191> 00120924 R WM_INITMENU
<008192> 00120924 S WM_MENUCHAR chUser:'f' (102) fuFlag:MF_SYSMENU hmenu:118E0043
<008193> 00120924 R WM_MENUCHAR fAction:0 (discard character and beep)
<008194> 00120924 S WM_CAPTURECHANGED hwndNewCapture:00000000
<008195> 00120924 R WM_CAPTURECHANGED
<008196> 00120924 S WM_MENUSELECT uItem:0 fuFlags:FFFF (menu was closed) hmenu:00000000
<008197> 00120924 R WM_MENUSELECT
<008198> 00120924 S WM_EXITMENULOOP fIsTrackPopupMenu:False
<008199> 00120924 R WM_EXITMENULOOP


and here's a trace for success:

<016831> 001507F8 P WM_SYSKEYDOWN nVirtKey:'F' cRepeat:1 ScanCode:21 fExtended:0 fAltDown:1 fRepeat:0 fUp:0
<016832> 000808B8 P message:0x8002 [User-defined:WM_APP+2] wParam:00000000 lParam:00000000
<016833> 001507F8 P WM_SYSCHAR chCharCode:'102' (102) cRepeat:1 ScanCode:21 fExtended:0 fAltDown:1 fRepeat:0 fUp:0
<016834> 00380370 S WM_GETTEXTLENGTH
<016835> 00380370 R WM_GETTEXTLENGTH cch:4
<016836> 00380370 S WM_GETTEXT cchTextMax:10 lpszText:0046DB0C
<016837> 00380370 R WM_GETTEXT cchCopied:4 lpszText:0046C8F8 pstr:0145DD80
<016838> 001507A4 S WM_GETTEXTLENGTH
<016839> 001507A4 R WM_GETTEXTLENGTH cch:6
<016840> 001507A4 S WM_GETTEXT cchTextMax:14 lpszText:0046DB08
<016841> 001507A4 R WM_GETTEXT cchCopied:6 lpszText:0046C8F4 ("")
<016842> 000908A0 S WM_GETTEXTLENGTH
<016843> 000908A0 R WM_GETTEXTLENGTH cch:4
<016844> 000908A0 S WM_GETTEXT cchTextMax:10 lpszText:0046DB0C
<016845> 000908A0 R WM_GETTEXT cchCopied:4 lpszText:0046C8F8 pstr:0145DD80
<016846> 0019078C S WM_GETTEXTLENGTH
<016847> 0019078C R WM_GETTEXTLENGTH cch:5
<016848> 0019078C S WM_GETTEXT cchTextMax:12 lpszText:0046DB0C
<016849> 0019078C R WM_GETTEXT cchCopied:5 lpszText:0046C8F8 ("@")
<016850> 002F01EC S WM_PAINT hdc:00000000
<016851> 002F01EC S WM_ERASEBKGND hdc:F7010D72
<016852> 002F01EC R WM_ERASEBKGND fErased:True
<016853> 002F01EC S WM_GETTEXTLENGTH
<016854> 002F01EC R WM_GETTEXTLENGTH cch:0
<016855> 002F01EC S WM_GETTEXT cchTextMax:2 lpszText:0046D6E4
<016856> 002F01EC R WM_GETTEXT cchCopied:0 lpszText:0046C4D0 ("")
<016857> 002F01EC S WM_GETTEXTLENGTH
<016858> 002F01EC R WM_GETTEXTLENGTH cch:0
<016859> 002F01EC S WM_GETTEXT cchTextMax:2 lpszText:0046D6E4
<016860> 002F01EC R WM_GETTEXT cchCopied:0 lpszText:0046C4D0 ("")
<016861> 002F01EC R WM_PAINT
<016862> 001307C6 S WM_GETTEXTLENGTH
<016863> 001307C6 R WM_GETTEXTLENGTH cch:0
<016864> 001307C6 S WM_GETTEXT cchTextMax:2 lpszText:0046DA9C
<016865> 001307C6 R WM_GETTEXT cchCopied:0 lpszText:0046C888 ("")
<016866> 001D04DE S WM_GETMINMAXINFO lpmmi:0046E660
<016867> 001D04DE R WM_GETMINMAXINFO lpmmi:0046E450
<016868> 001D04DE S WM_NCCREATE lpcs:0046E654
<016869> 001D04DE R WM_NCCREATE fContinue:True
<016870> 001D04DE S WM_NCCALCSIZE fCalcValidRects:False lpncsp:0046E640
<016871> 001D04DE R WM_NCCALCSIZE fuValidRect:0000 lpncsp:0046E408
<016872> 001D04DE S WM_CREATE lpcs:0046E654
<016873> 001D04DE R WM_CREATE fContinue:0 (continue creation)
<016874> 001307C6 S WM_SHOWWINDOW fShow:True fuStatus:0 (ShowWindow was called)
<016875> 001307C6 R WM_SHOWWINDOW
<016876> 001307C6 S WM_WINDOWPOSCHANGING lpwp:0046EBA0
<016877> 001307C6 R WM_WINDOWPOSCHANGING
<016878> 001307C6 S WM_NCPAINT hrgn:00000001
<016879> 001307C6 R WM_NCPAINT
<016880> 001307C6 S WM_ERASEBKGND hdc:47010F2A
<016881> 001307C6 R WM_ERASEBKGND fErased:True
<016882> 002D0826 S WM_NCCREATE lpcs:0046EB8C
<016883> 002D0826 S WM_NCCALCSIZE fCalcValidRects:False lpncsp:0046EB78
<016884> 002D0826 S WM_CREATE lpcs:0046EB8C
<016885> 002D0826 S WM_SIZE fwSizeType:SIZE_RESTORED nWidth:0 nHeight:0
<016886> 002D0826 S WM_MOVE xPos:0 yPos:0
<016887> 002D0826 S WM_WINDOWPOSCHANGING lpwp:0046EBA0
<016888> 002D0826 S WM_WINDOWPOSCHANGED lpwp:0046EBA0
<016889> 001307C6 S WM_WINDOWPOSCHANGED lpwp:0046EBA0
<016890> 001307C6 R WM_WINDOWPOSCHANGED
<016891> 001307C6 S WM_WINDOWPOSCHANGING lpwp:0046EC14
<016892> 001307C6 R WM_WINDOWPOSCHANGING
<016893> 000D08F0 S WM_WINDOWPOSCHANGING lpwp:0046EC14
<016894> 000D08F0 R WM_WINDOWPOSCHANGING
<016895> 002C0800 S WM_WINDOWPOSCHANGING lpwp:0046EC14
<016896> 002C0800 R WM_WINDOWPOSCHANGING
<016897> 00070578 S WM_WINDOWPOSCHANGING lpwp:0046EC14
<016898> 00070578 S message:0x043B [User-defined:WM_USER+59] wParam:00000000 lParam:02BB57C4
<016899> 00070578 R message:0x043B [User-defined:WM_USER+59] lResult:00000000
<016900> 00070578 R WM_WINDOWPOSCHANGING
<016901> 0013026E S WM_WINDOWPOSCHANGING lpwp:0046EC14
<016902> 0013026E S message:0x043B [User-defined:WM_USER+59] wParam:00000000 lParam:02BB58CC
<016903> 0013026E R message:0x043B [User-defined:WM_USER+59] lResult:00000000
<016904> 0013026E R WM_WINDOWPOSCHANGING
<016905> 000D07E6 S WM_WINDOWPOSCHANGING lpwp:0046EC14
<016906> 000D07E6 S message:0x043B [User-defined:WM_USER+59] wParam:00000000 lParam:02BB59D4
<016907> 000D07E6 R message:0x043B [User-defined:WM_USER+59] lResult:00000000
<016908> 000D07E6 R WM_WINDOWPOSCHANGING
<016909> 000B0832 S WM_WINDOWPOSCHANGING lpwp:0046EC14
<016910> 000B0832 S message:0x043B [User-defined:WM_USER+59] wParam:00000000 lParam:02BB5ADC
<016911> 000B0832 R message:0x043B [User-defined:WM_USER+59] lResult:00000000
<016912> 000B0832 R WM_WINDOWPOSCHANGING
<016913> 004F034E S WM_WINDOWPOSCHANGING lpwp:0046EC14
<016914> 004F034E S message:0x043B [User-defined:WM_USER+59] wParam:00000000 lParam:02BB5BE4
<016915> 004F034E R message:0x043B [User-defined:WM_USER+59] lResult:00000000
<016916> 004F034E R WM_WINDOWPOSCHANGING
<016917> 00120924 S WM_WINDOWPOSCHANGING lpwp:0046EC14
<016918> 00120924 R WM_WINDOWPOSCHANGING
<016919> 001307C6 S WM_NCPAINT hrgn:00000001
<016920> 001307C6 R WM_NCPAINT
<016921> 001307C6 S WM_ERASEBKGND hdc:F7010D72
<016922> 001307C6 R WM_ERASEBKGND fErased:True
<016923> 002D0826 S WM_WINDOWPOSCHANGING lpwp:0046EC14
<016924> 002D0826 S WM_WINDOWPOSCHANGED lpwp:0046EC14
<016925> 001307C6 S WM_WINDOWPOSCHANGED lpwp:0046EC14
<016926> 001307C6 R WM_WINDOWPOSCHANGED
<016927> 001307C6 S WM_PAINT hdc:00000000
<016928> 001307C6 S WM_ERASEBKGND hdc:47010F2A
<016929> 001307C6 R WM_ERASEBKGND fErased:True
<016930> 001307C6 S WM_GETTEXTLENGTH
<016931> 001307C6 R WM_GETTEXTLENGTH cch:0
<016932> 001307C6 S WM_GETTEXT cchTextMax:2 lpszText:0046D5F8
<016933> 001307C6 R WM_GETTEXT cchCopied:0 lpszText:0046C3E4 ("ì/")
<016934> 001307C6 S WM_GETTEXTLENGTH
<016935> 001307C6 R WM_GETTEXTLENGTH cch:0
<016936> 001307C6 S WM_GETTEXT cchTextMax:2 lpszText:0046D5F8
<016937> 001307C6 R WM_GETTEXT cchCopied:0 lpszText:0046C3E4 ("ì/")
<016938> 001307C6 R WM_PAINT
<016939> 001507F8 S WM_NCHITTEST xPos:583 yPos:422
<016940> 001507F8 R WM_NCHITTEST nHittest:HTCLIENT
<016941> 001507F8 S WM_NCHITTEST xPos:583 yPos:422
<016942> 001507F8 R WM_NCHITTEST nHittest:HTCLIENT
<016943> 001507F8 S WM_SETCURSOR hwnd:001507F8 nHittest:HTCLIENT wMouseMsg:WM_MOUSEMOVE
<016944> 001507F8 R WM_SETCURSOR fHaltProcessing:False
<016945> 001507F8 P WM_MOUSEMOVE fwKeys:0000 xPos:240 yPos:200
<016946> 001507F8 P WM_SYSKEYUP nVirtKey:'F' cRepeat:1 ScanCode:21 fExtended:0 fAltDown:1 fRepeat:1 fUp:1


Marc
Posted
Comments
fjdiewornncalwe 4-Apr-13 15:53pm    
Is it possible that the focused control is gobbling up those commands instead of letting them pipe up the chain? If so, do you need to catch the event in the offending control(s) and pipe it up manually?

1 solution

C#
//if your control not focused
if (!controlInstance.Focused)
{
    //make it focused
    controlInstance.Focus();
    //menu code here
    //{code}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900