flew0214 发表于 2009-2-17 15:48:16

api vb转成autoit

看到autoit也有调用api的方法,所以就想去改改看。结果效果有点问题。
下面是VB中的调用Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private 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
Private Declare Function ShowWindow Lib "user32" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

'========================上面是隐藏开始
'函数声明
'=======================下面是隐藏任务栏
Private Declare Function FindWindow8 Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private 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
Private Const SWP_SHOWWINDOW As Long = &H40
Private Const SWP_HIDEWINDOW As Long = &H80
Private Const SWP_NOACTIVATE As Long = &H10


Private Sub Command0_Click()
OurParent& = FindWindow("Shell_TrayWnd", "")
OurHandle& = FindWindowEx(OurParent&, 0, "Button", vbNullString)
ShowWindow OurHandle&, 0
End Sub

Private Sub Command1_Click()
OurParent& = FindWindow("Shell_TrayWnd", "")
OurHandle& = FindWindowEx(OurParent&, 0, "Button", vbNullString)
ShowWindow OurHandle&, 5 '显示开始按钮
End Sub

Private Sub Command2_Click()
Dim hide As Long
hide = FindWindow8("Shell_traywnd", vbNullString)
Call SetWindowPos(hide, 0, 0, 0, 0, 0, SWP_HIDEWINDOW)
End Sub

Private Sub Command3_Click()
Dim show As Long
show = FindWindow8("Shell_traywnd", vbNullString)
Call SetWindowPos(show, 0, 0, 0, 0, 0, SWP_SHOWWINDOW)
End Sub下面是用autoit改的
#NoTrayIcon
#include <GUIConstantsEx.au3>
#AutoIt3Wrapper_run_debug_mode=Y    ;开启调试模式
Global Const $SWP_SHOWWINDOW = 0x0040
Global Const $SWP_HIDEWINDOW= 0x0080
Global Const $SWP_NOACTIVATE = 0x0010
Local $Dll=DllOpen(@SystemDir&"\user32.dll")
dim $OurParent
dim $OurHandle
dim $hide
dim $show
dim $vbNullString=Chr(0)
$hGUI = GUICreate("调试", 250, 150)
$openstart=GUICtrlCreateButton("启动开始",10,30,100,30)
$endstart = GUICtrlCreateButton("关闭开始",10,80,100,30)
$openren = GUICtrlCreateButton("启动任务栏",130,30,100,30)
$endren = GUICtrlCreateButton("关闭任务栏",130,80,100,30)
GUISetState()
While 1
        $Msg = GUIGetMsg()
    Switch $Msg
                Case $GUI_EVENT_CLOSE
            ExitLoop
                Case $openstart
$OurParent = DllCall("$Dll","Int","FindWindowA","str", "Shell_TrayWnd","str", ""   )
$OurHandle = DllCall("$Dll","Int","FindWindowExA","Int",$OurParent,"Int",0,"str","Button","str",$vbNullString)
DllCall("$Dll","Int","hwnd","Int",$OurHandle,"Int",0)
      Case $endstart
$OurParent = DllCall("$Dll","Int","FindWindowA","str", "Shell_TrayWnd","str", ""   )
$OurHandle = DllCall("$Dll","Int","FindWindowExA","Int",$OurParent,"Int",0,"str","Button","str",$vbNullString)
DllCall("$Dll","Int","hwnd","Int",$OurHandle,"Int",5)
      case $openren   
$hide = DllCall("$Dll","Int","FindWindowA","str", "Shell_traywnd","str",$vbNullString)
DllCall("$Dll","Int","SetWindowPos","Int",$hide,"Int",0,"Int",0,"Int",0,"Int",0,"Int",0,"Int",$SWP_HIDEWINDOW)
      case $endren
$show = DllCall("$Dll","Int","FindWindowA","str", "Shell_traywnd","str",$vbNullString)
DllCall("$Dll","Int","SetWindowPos","Int",$show,"Int",0,"Int",0,"Int",0,"Int",0,"Int",0,"Int",$SWP_SHOWWINDOW)
            EndSwitch
                  WEnd
DllClose($Dll)
但是起不了隐藏开始,任务栏的作用。问题出在哪里?又人知道吗?谢谢大家的帮忙

[ 本帖最后由 flew0214 于 2009-2-18 14:51 编辑 ]

pusofalse 发表于 2009-2-17 16:29:22

$hWin = DllCall("user32.dll", "hwnd", "FindWindow", "str", "Shell_TrayWnd", "ptr", 0)
DllCall("user32.dll", "int", "ShowWindow", "hwnd", $hWin, "int", @sw_hide)

flew0214 发表于 2009-2-17 16:43:56

多谢指点,看到希望了。调用的是那几个函数啊。怎么用法不一样的,autoit调用api有没有相关的例子啊

[ 本帖最后由 flew0214 于 2009-2-17 16:54 编辑 ]

flew0214 发表于 2009-2-18 14:29:23

解决了。想明白了

[ 本帖最后由 flew0214 于 2009-2-18 14:51 编辑 ]
页: [1]
查看完整版本: api vb转成autoit