找回密码
 加入
搜索
查看: 1549|回复: 3

api vb转成autoit

[复制链接]
发表于 2009-2-17 15:48:16 | 显示全部楼层 |阅读模式
看到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 编辑 ]
发表于 2009-2-17 16:29:22 | 显示全部楼层
$hWin = DllCall("user32.dll", "hwnd", "FindWindow", "str", "Shell_TrayWnd", "ptr", 0)
DllCall("user32.dll", "int", "ShowWindow", "hwnd", $hWin[0], "int", @sw_hide)
 楼主| 发表于 2009-2-17 16:43:56 | 显示全部楼层
多谢指点,看到希望了。调用的是那几个函数啊。怎么用法不一样的,autoit调用api有没有相关的例子啊

[ 本帖最后由 flew0214 于 2009-2-17 16:54 编辑 ]
 楼主| 发表于 2009-2-18 14:29:23 | 显示全部楼层
解决了。想明白了

[ 本帖最后由 flew0214 于 2009-2-18 14:51 编辑 ]
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-5 16:32 , Processed in 0.073218 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表