点击对应控件并执行指定程序,求解
本帖最后由 wsfda 于 2011-6-11 17:14 编辑#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
Opt("GUIOnEventMode", 1) ; 开启 Event 模式
Global $H_info = 5,$Tab,$T ;$H_Iinfo = 说明的高度 ,...,...$Tab = 分页标签的数量
Global $b_DB = TimerInit();双击事件
$Tab = IniReadSectionNames("menu.ini")
$F = GUICreate("",550,90,200,210)
GUISetOnEvent($GUI_EVENT_CLOSE, "main")
$TB = GUICtrlCreateTab(0, 0, 565, 90)
GUICtrlSetState(-1, 8)
For $I = 1 To $Tab
$T[$I] = GUICtrlCreateTabItem($Tab[$I]);根据配置文件内的字段数量创建相应数量的分页标签
$Command = IniReadSection("menu.ini", $Tab[$I])
For $L = 1 To $Command
$Command[$L] = GUICtrlCreateButton($Command[$L], $H_info + ($L - 1) * 70, 25, 65, 60)
_GUICtrlButton_SetImageList(-1, _GetImageListHandle($Command[$L], 0, True), 2, -1, 5)
GUICtrlSetCursor(-1, 0) ;鼠标样式
GUICtrlSetOnEvent($Command[$L], "Command")
Next
Next
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
While 1
If GUIGetMsg() <> -3 Then _WinHide($F);自动隐藏
$hw = _WinAPI_GetForegroundWindow();置顶 Start
If $hw <> $F Then
_WinAPI_SetWindowPos($hw, -2, 0, 0, 0, 0, 3)
EndIf
_WinAPI_SetWindowPos($F, -1, 0, 0, 0, 0, 3);置顶 End
GetPos()
Sleep(15)
WEnd
Func Command()
For $L = 1 To UBound($Command, 1) - 1
If @GUI_CtrlId = $Command[$L] Then ShellExecute($Command[$L])
Next
EndFunc
Func _WinHide($Hwnd)
$Wp = WinGetPos($F)
$Mp = MouseGetPos()
Select
Case $Wp <= 3
If ($Mp < $Wp Or $Mp > $Wp + $Wp Or $Mp > $Wp + $Wp) Then
WinMove($Hwnd, "", $Wp, 3 - $Wp, $Wp, $Wp, 1)
Else
WinMove($Hwnd, "", $Wp, 3, $Wp, $Wp, 1)
EndIf
Case $Wp >= (@DesktopWidth - $Wp + 3)
If ($Mp < $Wp Or $Mp < $Wp Or $Mp > $Wp + $Wp) Then
WinMove($Hwnd, "", @DesktopWidth - 3, $Wp, $Wp, $Wp, 1)
Else
WinMove($Hwnd, "", @DesktopWidth - $Wp + 3, $Wp, $Wp, $Wp, 1)
EndIf
EndSelect
EndFunc
Func main()
Switch @GUI_CtrlId ; 根据宏 @GUI_CtrlId 来判断消息
Case $GUI_EVENT_CLOSE
;For $I = 1 To $Tab
;If GUICtrlRead ($Tb) = 0Then
;MsgBox(0,"",$Tab)
;ExitLoop
;ElseIf GUICtrlRead ($Tb) = $I Then
;MsgBox(0,"",$Tab[$I+1])
;EndIf
;Next
Exit
EndSwitch
EndFunc ;==>main
Func _GetImageListHandle($sFile, $nIconID = 0, $fLarge = False);添加图标
Local $iSize = 16
If $fLarge Then $iSize = 32
Local $hImage = _GUIImageList_Create($iSize, $iSize, 5, 3)
If StringUpper(StringMid($sFile, StringLen($sFile) - 2)) = "BMP" Then
_GUIImageList_AddBitmap($hImage, $sFile)
Else
_GUIImageList_AddIcon($hImage, $sFile, $nIconID, $fLarge)
EndIf
Return $hImage
EndFunc ;==>_GetImageListHandle
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
Opt("GUIOnEventMode", 1) ; 开启 Event 模式
Global $H_info = 5,$Tab,$T ;$H_Iinfo = 说明的高度 ,...,...$Tab = 分页标签的数量
Global $b_DB = TimerInit();双击事件
$Tab = IniReadSectionNames("menu.ini")
$F = GUICreate("",550,90,200,210)
GUISetOnEvent($GUI_EVENT_CLOSE, "main")
$TB = GUICtrlCreateTab(0, 0, 565, 90)
GUICtrlSetState(-1, 8)
For $I = 1 To $Tab
$T[$I] = GUICtrlCreateTabItem($Tab[$I]);根据配置文件内的字段数量创建相应数量的分页标签
$Command = IniReadSection("menu.ini", $Tab[$I])
For $L = 1 To $Command
$Command[$L] = GUICtrlCreateButton($Command[$L], $H_info + ($L - 1) * 70, 25, 65, 60)
_GUICtrlButton_SetImageList(-1, _GetImageListHandle($Command[$L], 0, True), 2, -1, 5)
GUICtrlSetCursor(-1, 0) ;鼠标样式
GUICtrlSetOnEvent($Command[$L], "Command")
Next
Next
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
While 1
If GUIGetMsg() <> -3 Then _WinHide($F);自动隐藏
$hw = _WinAPI_GetForegroundWindow();置顶 Start
If $hw <> $F Then
_WinAPI_SetWindowPos($hw, -2, 0, 0, 0, 0, 3)
EndIf
_WinAPI_SetWindowPos($F, -1, 0, 0, 0, 0, 3);置顶 End
GetPos()
Sleep(15)
WEnd
Func Command()
For $L = 1 To UBound($Command, 1) - 1
If @GUI_CtrlId = $Command[$L] Then ShellExecute($Command[$L])
Next
EndFunc
Func _WinHide($Hwnd)
$Wp = WinGetPos($F)
$Mp = MouseGetPos()
Select
Case $Wp <= 3
If ($Mp < $Wp Or $Mp > $Wp + $Wp Or $Mp > $Wp + $Wp) Then
WinMove($Hwnd, "", $Wp, 3 - $Wp, $Wp, $Wp, 1)
Else
WinMove($Hwnd, "", $Wp, 3, $Wp, $Wp, 1)
EndIf
Case $Wp >= (@DesktopWidth - $Wp + 3)
If ($Mp < $Wp Or $Mp < $Wp Or $Mp > $Wp + $Wp) Then
WinMove($Hwnd, "", @DesktopWidth - 3, $Wp, $Wp, $Wp, 1)
Else
WinMove($Hwnd, "", @DesktopWidth - $Wp + 3, $Wp, $Wp, $Wp, 1)
EndIf
EndSelect
EndFunc
Func main()
Switch @GUI_CtrlId ; 根据宏 @GUI_CtrlId 来判断消息
Case $GUI_EVENT_CLOSE
;For $I = 1 To $Tab
;If GUICtrlRead ($Tb) = 0Then
;MsgBox(0,"",$Tab)
;ExitLoop
;ElseIf GUICtrlRead ($Tb) = $I Then
;MsgBox(0,"",$Tab[$I+1])
;EndIf
;Next
Exit
EndSwitch
EndFunc ;==>main
Func _GetImageListHandle($sFile, $nIconID = 0, $fLarge = False);添加图标
Local $iSize = 16
If $fLarge Then $iSize = 32
Local $hImage = _GUIImageList_Create($iSize, $iSize, 5, 3)
If StringUpper(StringMid($sFile, StringLen($sFile) - 2)) = "BMP" Then
_GUIImageList_AddBitmap($hImage, $sFile)
Else
_GUIImageList_AddIcon($hImage, $sFile, $nIconID, $fLarge)
EndIf
Return $hImage
EndFunc ;==>_GetImageListHandle
代码如上:
如何做到点击按钮,执行指定程序
谢谢各位大哥帮忙
配置文件如下:
[默认分类]
随机音乐=D:\深蓝随机音乐台.exe
[编程应用]
key=C:\Users\make\Desktop\key.exe
[办公应用]
QQ=C:\Program Files\Tencent\QQ\Bin\QQ.exe
Mozilla Firefox=C:\Program Files\mozilla firefox\firefox.exe ;~ http://www.autoitx.com/forum.php?mod=viewthread&tid=25298&page=1&extra=#pid313974
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
Opt("GUIOnEventMode", 1) ; 开启 Event 模式
Global $H_info = 5, $Tab, $T ;$H_Iinfo = 说明的高度 ,...,...$Tab = 分页标签的数量
Global $b_DB = TimerInit();双击事件
Global $COMMAND_CTRL;#####################################
$Tab = IniReadSectionNames("menu.ini")
$F = GUICreate("", 550, 90, 200, 210)
GUISetOnEvent($GUI_EVENT_CLOSE, "main")
$TB = GUICtrlCreateTab(0, 0, 565, 90)
GUICtrlSetState(-1, 8)
For $I = 1 To $Tab
$T[$I] = GUICtrlCreateTabItem($Tab[$I]);根据配置文件内的字段数量创建相应数量的分页标签
$Command = IniReadSection("menu.ini", $Tab[$I])
ReDim $COMMAND_CTRL[$Tab+ 1][$Command + 1];#####################################
For $L = 1 To $Command
$COMMAND_CTRL[$I] = $Command;#####################################
$COMMAND_CTRL[$I][$L] = GUICtrlCreateButton($Command[$L], $H_info + ($L - 1) * 70, 25, 65, 60);#####################################
$COMMAND_CTRL[$I][$L] = $Command[$L];#####################################
_GUICtrlButton_SetImageList(-1, _GetImageListHandle($Command[$L], 0, True), 2, -1, 5)
GUICtrlSetCursor(-1, 0) ;鼠标样式
GUICtrlSetOnEvent($COMMAND_CTRL[$I][$L], "Command");#####################################
Next
Next
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
While 1
If GUIGetMsg() <> -3 Then _WinHide($F);自动隐藏
$hw = _WinAPI_GetForegroundWindow();置顶 Start
If $hw <> $F Then
_WinAPI_SetWindowPos($hw, -2, 0, 0, 0, 0, 3)
EndIf
_WinAPI_SetWindowPos($F, -1, 0, 0, 0, 0, 3);置顶 End
;~ GetPos()
Sleep(15)
WEnd
Func Command()
For $I = 1 To $Tab
For $L = 1 To $COMMAND_CTRL[$I];#####################################
If @GUI_CtrlId = $COMMAND_CTRL[$I][$L] Then Return MsgBox(0, 0, $COMMAND_CTRL[$I][$L]);ShellExecute($COMMAND_CTRL[$L]);#####################################
Next
Next
EndFunc ;==>Command
Func _WinHide($Hwnd)
$Wp = WinGetPos($F)
$Mp = MouseGetPos()
Select
Case $Wp <= 3
If ($Mp < $Wp Or $Mp > $Wp + $Wp Or $Mp > $Wp + $Wp) Then
WinMove($Hwnd, "", $Wp, 3 - $Wp, $Wp, $Wp, 1)
Else
WinMove($Hwnd, "", $Wp, 3, $Wp, $Wp, 1)
EndIf
Case $Wp >= (@DesktopWidth - $Wp + 3)
If ($Mp < $Wp Or $Mp < $Wp Or $Mp > $Wp + $Wp) Then
WinMove($Hwnd, "", @DesktopWidth - 3, $Wp, $Wp, $Wp, 1)
Else
WinMove($Hwnd, "", @DesktopWidth - $Wp + 3, $Wp, $Wp, $Wp, 1)
EndIf
EndSelect
EndFunc ;==>_WinHide
Func main()
Switch @GUI_CtrlId ; 根据宏 @GUI_CtrlId 来判断消息
Case $GUI_EVENT_CLOSE
;For $I = 1 To $Tab
;If GUICtrlRead ($Tb) = 0Then
;MsgBox(0,"",$Tab)
;ExitLoop
;ElseIf GUICtrlRead ($Tb) = $I Then
;MsgBox(0,"",$Tab[$I+1])
;EndIf
;Next
Exit
EndSwitch
EndFunc ;==>main
Func _GetImageListHandle($sFile, $nIconID = 0, $fLarge = False);添加图标
Local $iSize = 16
If $fLarge Then $iSize = 32
Local $hImage = _GUIImageList_Create($iSize, $iSize, 5, 3)
If StringUpper(StringMid($sFile, StringLen($sFile) - 2)) = "BMP" Then
_GUIImageList_AddBitmap($hImage, $sFile)
Else
_GUIImageList_AddIcon($hImage, $sFile, $nIconID, $fLarge)
EndIf
Return $hImage
EndFunc ;==>_GetImageListHandle 在线等,..... 本帖最后由 漠北雪~狼 于 2011-6-11 16:01 编辑
楼主代码发重复了且GetPos函数不存在。
请参照http://www.autoitx.com/thread-5729-1-1.html中例1,问题自然迎刃而解。
哦,刚刚还没有看明白你的代码,帮你改好了,我标记了;#####################################的地方,是对你源代码有修改的地方
代码在5楼,其中需要用到一个三维数组,有不明白的地方请跟贴。
另外,第63行的return最好是不要省掉。 回复 1# wsfda
楼主你这代码是借用别人的吧??明显重复包含了,而且里面的一些函数也没有,比如是getpos()
估计是wingetpos() 回复 5# 漠北雪~狼
谢谢大哥帮忙,谢谢 路过。。。 进来学习,又懂了一些
页:
[1]