ShellExecute Me.hwnd, "open", "calc.exe", "", "", 1怎么指定打开计算器显示的位置?若计算器已打开,再次单击又会再打开一个,怎么才可以在已打开情况下,不打开另一个?

解决方案 »

  1.   

    ShellExecute 做不到你说的功能,你可以运行 CALC 前做一下检查,如已运行,就不再执行
      

  2.   

    Option ExplicitPrivate Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End TypePrivate Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hWnd As Long, _
                                ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
                                ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long, _
                                ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
    Private Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT) As LongPrivate Sub MoveWindowTo(ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long)
        Dim Rec As RECT
        If hWnd <> 0 Then
            GetWindowRect hWnd, Rec
            MoveWindow hWnd, X, Y, Rec.Right - Rec.Left, Rec.Bottom - Rec.Top, 1
        End If
    End SubPrivate Sub tmrAfterLoadCalc_Timer()
        Dim WinWnd As Long
        WinWnd = FindWindow(vbNullString, "计算器")
        If WinWnd <> 0 Then
            tmrAfterLoadCalc.Enabled = False
            MoveWindowTo WinWnd, 200, 200
        End If
    End SubPrivate Sub Command1_Click()
        Dim WinWnd As Long
        WinWnd = FindWindow(vbNullString, "计算器")
        If WinWnd <> 0 Then
            MoveWindowTo WinWnd, 200, 200
        Else
            ShellExecute Me.hWnd, "open", "calc.exe", "", "", 1
            tmrAfterLoadCalc.Interval = 50
            tmrAfterLoadCalc.Enabled = True
        End If
    End Sub
      

  3.   

    tmrAfterLoadCalc  是什么,变量没定义
      

  4.   

    tmrAfterLoadCalc是个timer控件思路就是 Command1 按下时
    判断是否有标题为“计算器”的程序
    有的话用MoveWindowTo 移动“计算器”到指定位置
    没有就用shellexcute打开,同时让tmrAfterLoadCalc控件运行
    tmrAfterLoadCalc的功能就是把“计算器”移动到指定位置.....^_^最近都不想写代码了,好累啊
      

  5.   

    那若要移到 MDI 窗体内位置怎么写?
      

  6.   

    那若要移到 MDI 窗体内位置怎么写?
      

  7.   

    我是在MDI 窗体中打开的,当然很希望 “计算器” 是个 MDI 子窗体 。