By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,992 Members | 1,346 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,992 IT Pros & Developers. It's quick & easy.

Send Key Commands to modeless dialog box

P: 1
Hi

I am programing in Autocad with VB

Autodesk have not given users access to new note function in Autocad CIVIL3d API. I am trying to work round this by creating notes using the sendkey command in Vb. I can get the add note dialog box to come up ok but it does not have focus as I believe it is a modeless dialog box as it gets focus when you move the mouse cursor over it.

What I am after is a VB eample on how to send key strokes to the modeless dialog. Looking on the web a I think I have to use the
IsDialogMessage() in combination with others.

Any help on getting this rountine to work would be great here is the code I sourced from others and written so far.

I seem to be able to get the window handle and send commands but still nothing happens. All it needs to do in press the tab key 3 times to got tru controls on the form and get to a buttton and press.



'Type to hold the coordinates of the mouse pointer
Private Type POINTAPI
x As Long
y As Long
End Type

'Type to hold the Windows message information
Private Type MSG
hWnd As Long 'the window handle of the app
message As Long 'the type of message (e.g. keydown)
wParam As Long 'the key code
lParam As Long 'not used
time As Long 'time when message posted
pt As POINTAPI 'coordinate of mouse pointer
End Type


Public Declare Function EnableWindow Lib "user32" (ByVal hWnd As Long, ByVal fEnable As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Declare Function showwindow Lib "user32" Alias "ShowWindow" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function IsWindowEnabled Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function IsDialogMessage Lib "user32" (ByVal hWnd As Long, ByRef lpMsg As MSG) As Long


Public Const BM_SETCHECK = &HF1
Public Const BM_GETCHECK = &HF0

Public Const CB_GETCOUNT = &H146
Public Const CB_GETLBTEXT = &H148
Public Const CB_SETCURSEL = &H14E

Public Const GW_HWNDFIRST = 0
Public Const GW_HWNDNEXT = 2
Public Const GW_CHILD = 5

Public Const LB_GETCOUNT = &H18B
Public Const LB_GETTEXT = &H189
Public Const LB_SETCURSEL = &H186

Public Const SW_HIDE = 0
Public Const SW_MAXIMIZE = 3
Public Const SW_MINIMIZE = 6
Public Const SW_NORMAL = 1
Public Const SW_SHOW = 5

Public Const VK_SPACE = &H20

Public Const WM_CHAR = &H102
Public Const WM_CLOSE = &H10
Public Const WM_COMMAND = &H111
Public Const WM_GETTEXT = &HD
Public Const WM_GETTEXTLENGTH = &HE
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_MOVE = &HF012
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public Const WM_SETTEXT = &HC
Public Const WM_SYSCOMMAND = &H112

Sub GetWindowhandle()

Dim hWnd As Long
Dim Messageprocessed As Variant

hWnd = FnFindWindowLike("Add Labels")
MsgBox hWnd

Tabthrucontrolsondialog hWnd


End Sub


Sub Tabthrucontrolsondialog(hWnd As Long)

'Dim x As Long

'x = FindWindow("#32770", vbNullString)
'Call showwindow(x, SW_SHOW)
Call EnableWindow(hWnd, 1)

'check modeless child window enabled and visible
MsgBox IsWindowEnabled(hWnd)
MsgBox IsWindowVisible(hWnd)


'send keyboard commands to modeless dialog box
Dim wMsg As MSG
wMsg.hWnd = hWnd
wMsg.lParam = WM_TAB + WM_TAB + WM_TAB + WM_ENTER
'not sure if able line right?????

' hWnd As Long 'the window handle of the app
' message As Long 'the type of message (e.g. keydown)
' wParam As Long 'the key code
' lParam As Long 'not used
' time As Long 'time when message posted
' pt As POINTAPI 'coordinate of mouse pointer



If IsDialogMessage(hWnd, wMsg) = 0 Then
MsgBox "message not processed"
' 0 not message processed
Else
MsgBox "message processed"
' 1 message processed
End If


Regards

Justin
Jan 8 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.