首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >调整OSK.exe窗口大小的VBA

调整OSK.exe窗口大小的VBA
EN

Stack Overflow用户
提问于 2015-05-24 00:25:27
回答 1查看 1.4K关注 0票数 3

我正在开发一个Kiosk类型的应用程序(没有鼠标,没有键盘),用户在Excel电子表格中输入数据。我想让屏幕上的键盘每次被调用时都出现在同一个地方。osk.exe窗口“记住”关闭时的位置,下一次打开时会在相同的位置重新出现,但关闭后,osk返回到默认位置并掩盖表单。

我需要一种方法来设置osk的立场,无论何时开放。下面是我打开osk的代码。

代码语言:javascript
复制
   Dim Shex As Object
   Dim tgtfile As String

   Set Shex = CreateObject("Shell.Application")
   tgtfile = "C:\Windows\System32\osk.exe"
   Shex.Open (tgtfile)

我想知道是否有类似于Shex.Top = 250的东西,或者类似的东西。

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-24 11:39:37

不幸的是,SetWindowPos API与FindWindow API不适用于OSKMainClass("On-Screen Keyboard"),我尝试了各种组合,但它一直失败。好像它没有被当作正常的窗口。

Note:测试了Excel2010 (32位)、Windows8.1 64位(触摸屏是否重要?)的代码。

这是我试过的密码。(,这不起作用,)

代码语言:javascript
复制
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, _
ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Public Const SWP_NOSIZE = &H1
Public Const HWND_TOPMOST = -1

Sub Sample()
    Dim Ret As Long, retval As Long
    Dim Shex As Object

    Set Shex = CreateObject("Shell.Application")
    Shex.Open ("C:\Windows\System32\osk.exe")

    Wait 1

    Ret = FindWindow("OSKMainClass", "On-Screen Keyboard")

    If Ret <> 0 Then
        'Msgbox "On-Screen Keyboard Window Found"
        retval = SetWindowPos(Ret, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE)
        DoEvents

        If retval = False Then MsgBox "Unable to move Window"
    End If
End Sub

Private Sub Wait(ByVal nSec As Long)
    nSec = nSec + Timer
    While nSec > Timer
        DoEvents
    Wend
End Sub

这是另一种实现你想要的东西的方法。我正在模拟鼠标点击来完成这项工作。(这工作)

代码语言:javascript
复制
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Declare Function SetCursorPos Lib "user32" _
(ByVal X As Integer, ByVal Y As Integer) As Long

Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Long, lpRect As RECT) As Long

Private Declare Sub mouse_event Lib "user32.dll" (ByVal dwFlags As Long, _
ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

Private Const MOUSEEVENTF_MOVE = &H1          ' mouse move
Private Const MOUSEEVENTF_LEFTDOWN = &H2      ' left button down
Private Const MOUSEEVENTF_LEFTUP = &H4        ' left button up
Private Const MOUSEEVENTF_ABSOLUTE = &H8000   ' absolute move

Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

Dim pos As RECT


Sub Sample()
    Dim Ret As Long, retval As Long
    Dim Shex As Object

    Set Shex = CreateObject("Shell.Application")
    Shex.Open ("C:\Windows\System32\osk.exe")

    Wait 1

    Ret = FindWindow("OSKMainClass", "On-Screen Keyboard")

    If Ret <> 0 Then
        GetWindowRect Ret, pos

        '~~> Get the co-ordinates of some point in titlebar
        cur_x = pos.Left + 10
        cur_y = pos.Top + 10

        '~~> New Destination (Top Left Corner of Desktop)
        dest_x = 0
        dest_y = 0

        '~~> Move the cursor to a place in titlebar
        SetCursorPos cur_x, cur_y
        Wait 1 '<~~ Wait 1 second

        '~~> Press the left mouse button on the Title Bar
        mouse_event MOUSEEVENTF_LEFTDOWN, cur_x, cur_y, 0, 0

        '~> Set the new destination. Take cursor there
        SetCursorPos dest_x, dest_y

        '~~> Press the left mouse button again to release it
        mouse_event MOUSEEVENTF_LEFTUP, dest_x, dest_y, 0, 0
        Wait 1

        MsgBox "done"

    End If
End Sub

Private Sub Wait(ByVal nSec As Long)
    nSec = nSec + Timer
    While nSec > Timer
        DoEvents
    Wend
End Sub
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30418900

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档