gpt4 book ai didi

vb.net - 窗口 - 按代码单击确定按钮

转载 作者:行者123 更新时间:2023-11-30 23:49:02 25 4
gpt4 key购买 nike

我正在向 ArcMap 添加一个 SDE 要素类,在添加之前,我必须单击 好的 “连接详细信息”窗口上的按钮。有没有办法点击好的 按代码按钮?我在想也许可以通过使用 Window 通知代码(例如下面的代码)来完成,但是我没有看到任何用于单击按钮的选项 好的 或取消。也许它可以通过“Windows.Forms.DialogResult.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&

最佳答案

我可以想到两种方法:

  • 您可以找到 好的 按钮位置(使用 FindWindowExGetWindowRect ),将光标放在按钮上( SetCursorPosition )并模拟鼠标单击( mouse_event 。)或者您可以将焦点设置在按钮上并模拟按下 输入 键(使用 keyb_event )。
  • 发送 BM_CLICK消息到 OK 按钮的句柄。

  • 我个人更喜欢第二种方法:
    <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); // The button handle can be found with FindWindowEx

    关于vb.net - 窗口 - 按代码单击确定按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6310731/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com