2011-06-10 31 views
1

我在ArcMap中添加SDE要素類,在添加之前,必須單擊「連接詳細信息」窗口上的ok按鈕。有沒有辦法按代碼點擊ok按鈕?我想也許這可以通過使用窗口通知代碼(例如下面的代碼)來完成,但是我沒有看到按鈕單擊的任何選項Ok或取消。也許它可以通過「Windows.Forms.DialogResult.Ok」以某種方式完成或通過獲得ok按鈕的焦點?窗口 - 通過代碼單擊確定按鈕

感謝

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long 
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long 
Const WM_CLOSE = &H10 

'Close SDE connection details dialog 
      Dim WinWnd As Long, Ret As String 
      'Ask for a Window title 
      Ret = "Connection Details" 
      If Ret = "" Then Exit Sub 
      'Search the window 
      WinWnd = FindWindow(vbNullString, Ret) 
      'If WinWnd = 0 Then Messagebox.show "Couldn't find the window ...": Exit Sub 
      'Post a message to the window to close itself 
      PostMessage WinWnd, WM_CLOSE, 0&, 0& 

回答

2

有幾個方法可以做到這一點,例如:

  1. 你可以找到OK按鈕位置(FindWindowExGetWindowRect),設置光標位置(SetCursorPosition)並點擊(mouse_event)或者將焦點設置在按鈕上並按下回車鍵(keyb_event)。

  2. 發送BM_CLICK消息到窗口消息轉換器與OK按鈕ID

我建議你用第二個方法去:

<Runtime.InteropServices.DllImport("user32.dll", SetLastError:=True, CharSet:=Runtime.InteropServices.CharSet.Auto)> _ 
Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr 
End Function 

Public BM_CLICK As Integer = &HF5 

SendMessage(`OK BUTTON HANDLE`, BM_CLICK, 0, 0) 

你可以找到按鈕,FindWindowEx

+0

如果在間諜++窗口有一個把手,但按鈕沒有手柄手柄或者不會像小孩一樣出現?如何發送點擊或按代碼中的按鈕? – Razcer 2011-08-18 15:25:05

+0

你能指定'OK BUTTON HANDLE'是什麼嗎?那些背部蜱是否應該像那樣使用?但它不適合我。 – Xosofox 2014-10-10 08:37:01

+0

@Xosofox'OK BUTTON HANDLE'(包括反引號)必須用按鈕手柄進行更換。正如我已經解釋的那樣,你可以通過'FindWindow()'得到它。 – fardjad 2014-10-10 08:44:03