Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way
Hi,
I have a problem in Calling Vb6 ActiveX form Dll Inside .NET Form result in Tab order work in reverse way ,and it can't go inside Frame control.
I have found Microsoft kb 233263 article that telling about that issue and denoted that solution will be the message pump(Loop) needs to call the IsDialogMessage API.
Actually i have saw many case but its .Net dll called from VB6 (my oppisite case) but i was unable to convert that code to Fix message Loop throught calling IsDialogMessage for Tab key from VB6 ,they calling that keybord hook ,but I have Developed that Code down , and the result is that it try to fix message loop it did reversed the tab order if i run this form from Vb6 but i cant see any effect when i call the vb6 Dll from .NET.
What could be the problem !!!!!!!!!
Private Const HC_ACTION = 0
Public Const WM_NULL = &H0
Public Const PM_REMOVE = &H1
Public Const WM_KEYFIRST = &H100
Public Const WM_KEYLAST = &H108
Public Const WH_GETMESSAGE = 3
Public hHook As Long
Public hWindH As Long
Public Declare Function SetWindowsHookEx Lib "user32" _
Alias "SetWindowsHookExA" (ByVal idHook As Long, _
ByVal lpfn As Long, _
ByVal hmod As Long, _
ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" _
(ByVal hHook As Long) As Long
Private Declare Function CallNextHookEx Lib "user32" _
(ByVal hHook As Long, _
ByVal nCode As Long, _
ByVal wParam As Long, _
ByRef lParam As Msg) As Long
Public Declare Function IsDialogMessage Lib "user32" _
Alias "IsDialogMessageA" _
(ByVal hDlg As Long, _
lpMsg As Msg) As Long
Private Type KBDLLHOOKSTRUCT
vkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Type Msg
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
ptX As Long
ptY As Long
End Type
Public Sub HookKeyboard(ByVal FormHwd As Long)
hHook = SetWindowsHookEx(WH_GETMESSAGE, AddressOf GetMsgProc, _
0&, App.ThreadID)
hWindH = FormHwd
Call CheckHooked
End Sub
Public Function GetMsgProc(ByVal uCode As Long, ByVal wParam As Long, lParam As Msg) As Long
If wParam = PM_REMOVE Then
Select Case uCode
Case HC_ACTION
If lParam.message >= WM_KEYFIRST And lParam.message <= WM_KEYLAST Then
If IsDialogMessage(hWindH, lParam) Then
Debug.Print "Tab hooked and Call IsDialogMessage"
lParam.message = WM_NULL
lParam.wParam = 0
lParam.lParam = 0
End If
End If
End Select
End If
GetMsgProc = CallNextHookEx(hHook, uCode, wParam, lParam)
End Function
'----------------------------------------------------------------------------
Public Sub UnhookKeyboard()
If (Hooked) Then
Call UnhookWindowsHookEx(hHook)
End If
End Sub
Public Sub CheckHooked()
If (Hooked) Then
Debug.Print "Keyboard hooked"
Else
Debug.Print "Keyboard hook failed: " & err.LastDllError
End If
End Sub
Private Function Hooked()
Hooked = hHook <> 0
End Function
Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way
Here we do call the HookKeyboard with a handel to window that start hook the tab key press ,
My Form is called modeless from Activex DLL into .NET by using Showwindow() API call.
but its not attached to .NEt parent form as it appears in task bar as a separate thread.
Microsoft kb 233263 article that telling that issue for Dialog Modelees and denoted that solution will be the message pump(Loop) needs to call the IsDialogMessage API.
the code below i developed should do fix message loop that work but it dose not do any thing when i call the VB6 form Inside VB.NET .
When i try to call a Vb6 form inside VB6 project it give the same behave (tab order work in reverse and can't access frame control ) as happning in VB.NET without my code.
here is listing ,
if somthing not clear let me know please :
Code:
Private Sub Form_Load()
HookKeyboard (Me.hwnd)
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnhookKeyboard
End Sub
'---------------------------------------------KeyboardHandler.bas--------------------------------------------------
'Define const
Private Const HC_ACTION = 0
Public Const WM_NULL = &H0
Public Const PM_REMOVE = &H1
Public Const WM_KEYFIRST = &H100
Public Const WM_KEYLAST = &H108
Public Const WH_GETMESSAGE = 3
Public hHook As Long
Public hWindH As Long
Public Declare Function SetWindowsHookEx Lib "user32" _
Alias "SetWindowsHookExA" (ByVal idHook As Long, _
ByVal lpfn As Long, _
ByVal hmod As Long, _
ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" _
(ByVal hHook As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(pDest As Any, _
pSource As Any, _
ByVal cb As Long)
Private Declare Function CallNextHookEx Lib "user32" _
(ByVal hHook As Long, _
ByVal nCode As Long, _
ByVal wParam As Long, _
ByRef lParam As Msg) As Long
Public Declare Function IsDialogMessage Lib "user32" _
Alias "IsDialogMessageA" _
(ByVal hDlg As Long, _
lpMsg As Msg) As Long
Type Msg
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
ptX As Long
ptY As Long
End Type
Public Sub HookKeyboard(ByVal FormHwd As Long)
'Start hooking
hHook = SetWindowsHookEx(WH_GETMESSAGE, AddressOf GetMsgProc, _
0&, App.ThreadID)
hWindH = FormHwd
Call CheckHooked
End Sub
Public Function GetMsgProc(ByVal uCode As Long, ByVal wParam As Long, lParam As Msg) As Long
If wParam = PM_REMOVE Then
Select Case uCode
Case HC_ACTION
If lParam.message >= WM_KEYFIRST And lParam.message <= WM_KEYLAST Then
If IsDialogMessage(hWindH, lParam) Then
Debug.Print "Tab hooked and Call IsDialogMessage"
lParam.message = WM_NULL
lParam.wParam = 0
lParam.lParam = 0
End If
End If
End Select
End If
GetMsgProc = CallNextHookEx(hHook, uCode, wParam, lParam)
End Function
Public Sub UnhookKeyboard()
If (Hooked) Then
Call UnhookWindowsHookEx(hHook)
End If
End Sub
Public Sub CheckHooked()
If (Hooked) Then
Debug.Print "Keyboard hooked"
Else
Debug.Print "Keyboard hook failed: " & err.LastDllError
End If
End Sub
Private Function Hooked()
Hooked = hHook <> 0
End Function
Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way
Remove any unwanted dll or refrence's and comment code to make the form just showing to see how tab order behave , actually those dll was registerd at our server but i belive that you don't need them.
Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way
I’m using showwindow() API call because it’s the only way to show modeless Form into .NET ,if you tried yourself to use the Show () function from Vb6 it will give you error similer to that “Non-modal forms cannot be displayed in this host application from an ActiveX DLL, ActiveX Control, or Property Page."”
Refer to that : https://connect.microsoft.com/Visual...&wa=wsignin1.0
Microsoft kb 233263 article telling that issue for Dialog Modeless and denoted that solution will be the message pump(Loop) needs to call the IsDialogMessage API. http://support.microsoft.com/kb/233263
When a modeless dialog box is launched from a dynamic-link library (DLL), the TAB key and the arrow keys do not move the focus from control to control as you would expect.
For a modeless dialog box to process a TAB key, the message pump needs to call the IsDialogMessage API.
To work around this problem, you can use a WH_GETMESSAGE hook to capture the keystroke messages and call the IsDialogMessage API. If IsDialogMessage returns TRUE, then do not pass the message on to the message pump. Set the hook when handling WM_INITDIALOG and unset it when handling the WM_DESTROY message.
That’s why I tried to work around the problem using hooking as Microsoft set that as a solution for the problem.
-It’s a requirement in my Application to show all my forms as a modeless so I cannot use (Form1.Show vbModal) .
Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way
Could you please elaborate on how to use sendkeys in this scenario. In .net app,I attached sendkeys class and on form_keyup event called sendkeys.send("tab"). But it did not work. Please help me with its use in my scenario.
Thanks
Re: Calling Vb6 Activex form Dll from .NET made Tab order work in reverse way
Get the handle or title of a control, and set it to that. Did you try the samples he included? I had to set the second flag to FALSE to send to Notepad, after I modified the title to find to "Untitled - Notpad"
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.