找回密码
 加入
搜索
查看: 1899|回复: 7

[AU3基础] 如何显示上下文菜单的打勾 对号效果 √ 已解决

[复制链接]
发表于 2019-8-26 15:51:04 | 显示全部楼层 |阅读模式
本帖最后由 Mixrelax 于 2019-8-26 16:26 编辑

如何显示上下文菜单的打勾 对号效果 √
#RequireAdmin
#Region ;**** 由 AccAu3Wrapper_GUI 创建指令 ****
#AccAu3Wrapper_Outfile_x64=PrintCtrl.exe
#AccAu3Wrapper_UseUpx=y
#AccAu3Wrapper_Res_Language=2052
#AccAu3Wrapper_Res_requestedExecutionLevel=None
#AccAu3Wrapper_Run_Tidy=y
#EndRegion ;**** 由 AccAu3Wrapper_GUI 创建指令 ****
#include-once
#include <Misc.au3>
#include <WinAPI.au3>
#include <GuiMenu.au3>
#include <Constants.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

HotKeySet("{`}", "GUI_SetState") ;显示隐藏主窗口 注释掉
<blockquote>
If _Singleton("PrintCtrl", 1) = 0 Then Exit

Opt("TrayMenuMode", 3)
Opt("GUIOnEventMode", 1)

variables()
Func variables()
        Global $dir, $sDrive, $sDir, $sFilename, $SearchDir, $Filename, $File, $output_Filename, $output_File, $Extension, $SkipRootAfterDir
EndFunc   ;==>variables

#Region ### START Koda GUI section ### Form=C:\Users\Administrator\Documents\FormPrintCtrl.kxf
$hGUI = GUICreate("打印控制台", 1000, @DesktopHeight / 1.2, 10, 10, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_SetState")
GUISetIcon(@ScriptDir & "\Resource\PrintCtrl.ico", -1)
Global $idListView = GUICtrlCreateListView("文档名|纸张|翻页|布局|划边框线|装订|份数|打印机|打印状态|提交时间|文档路径|去PPT背景色|PDF Reader|旋转180度", 0, 0, 999, @DesktopHeight / 1.2, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
GUICtrlSetBkColor(-1, 0xC0DCC0)
$hidListView = GUICtrlGetHandle($idListView)
_GUICtrlListView_SetColumn($idListView, 0, '文档名', 250) ;文档名
_GUICtrlListView_SetColumn($idListView, 1, '纸张', 50) ;纸张
_GUICtrlListView_SetColumn($idListView, 2, '翻页', 50) ;翻页
_GUICtrlListView_SetColumn($idListView, 3, '布局', 75) ;布局
_GUICtrlListView_SetColumn($idListView, 4, '划边框线', 75) ;划边框线
_GUICtrlListView_SetColumn($idListView, 5, '装订', 70) ;装订
_GUICtrlListView_SetColumn($idListView, 6, '份数', 75) ;份数
_GUICtrlListView_SetColumn($idListView, 7, '打印机', 120) ;打印机
_GUICtrlListView_SetColumn($idListView, 8, '打印状态', 105) ;打印状态
_GUICtrlListView_SetColumn($idListView, 9, '提交时间', 75) ;提交时间
_GUICtrlListView_SetColumn($idListView, 10, '文档路径', 500) ;文档路径
_GUICtrlListView_SetColumn($idListView, 11, '去PPT背景色', 105) ;去PPT背景色
_GUICtrlListView_SetColumn($idListView, 12, 'PDF Reader', 130) ;PDFReader
_GUICtrlListView_SetColumn($idListView, 13, '旋转180度', 85) ;旋转180度

_GUICtrlListView_SetExtendedListViewStyle($idListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

Global $wProcHandle = DllCallbackRegister("_WindowProc", "ptr", "hwnd;uint;wparam;lparam")
Global $wProcOld = _WinAPI_SetWindowLong($hidListView, $GWL_WNDPROC, DllCallbackGetPtr($wProcHandle))

Global Enum $idOpen, $idOpenPath, $idPause, $idClearDone, $idCancelAllDoc
Global $hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_AddMenuItem($hMenu, "打开(&O)", $idOpen)
_GUICtrlMenu_AddMenuItem($hMenu, "打开路径(&O)", $idOpenPath)
Global $idMenu1 = _GUICtrlMenu_AddMenuItem($hMenu, "暂停打印(&A)", $idPause)
_GUICtrlMenu_AddMenuItem($hMenu, "清空已完成(&Q)", $idClearDone)
_GUICtrlMenu_AddMenuItem($hMenu, "取消所有文档(&L)", $idCancelAllDoc)

GUISetState(@SW_SHOW)
;~ GUISetState(@SW_MINIMIZE)
#EndRegion ### END Koda GUI section ###

Func _WindowProc($hWnd, $Msg, $wParam, $lParam)
        Switch $hWnd
                Case $hidListView
                        Switch $Msg
                                Case $WM_CONTEXTMENU
                                        If RegRead("HKEY_CURRENT_USER\Software\dygl", "PrintAction") = 1 Then ;读取状态
                                                _GUICtrlMenu_EnableMenuItem($hMenu, $idMenu1, 0)
                                        Else
                                                _GUICtrlMenu_EnableMenuItem($hMenu, $idMenu1, 1)
                                        EndIf
                                        _GUICtrlMenu_TrackPopupMenu($hMenu, $wParam)
                                        Return 0
                                Case $WM_COMMAND
                                        $Selected_Array = _GUICtrlListView_GetSelectedIndices($idListView, True)
                                        $ItemSelected = $Selected_Array[0]
                                        Switch $wParam
                                                Case $idOpen
                                                        For $i = 1 To $ItemSelected
                                                                $Index_Job = $Selected_Array[$i]
                                                                $ItemTextString = _GUICtrlListView_GetItemTextArray($idListView, $Index_Job)
                                                                $File = $ItemTextString[11]
                                                                ShellExecute($File)
                                                        Next
                                                Case $idOpenPath
                                                        For $i = 1 To $ItemSelected
                                                                $Index_Job = $Selected_Array[$i]
                                                                $ItemTextString = _GUICtrlListView_GetItemTextArray($idListView, $Index_Job)
                                                                $File = $ItemTextString[11]
                                                                PathSplit($File)
                                                                ShellExecute($dir)
                                                        Next
                                                Case $idPause
                                                        If RegRead("HKEY_CURRENT_USER\Software\dygl", "PrintAction") = 1 Then ;读取状态
                                                                RegWrite("HKEY_CURRENT_USER\Software\dygl", "PrintAction", "REG_SZ", 0) ;暂停打印
                                                        Else
                                                                RegWrite("HKEY_CURRENT_USER\Software\dygl", "PrintAction", "REG_SZ", 1) ;恢复打印
                                                        EndIf
                                                Case $idClearDone
                                                        menu_CancelAllPrintItemClick()
                                                Case $idCancelAllDoc
                                                        _GUICtrlListView_DeleteAllItems($idListView) ;清空列表
                                        EndSwitch
                        EndSwitch
        EndSwitch

        Local $aRet = DllCall("user32.dll", "int", "CallWindowProc", "ptr", $wProcOld, _
                        "hwnd", $hWnd, "uint", $Msg, "wparam", $wParam, "lparam", $lParam)
        Return $aRet[0]
        
EndFunc   ;==>_WindowProc

TraySetClick(8)
Local $Exit = TrayCreateItem("退出(&T)")
TraySetIcon(@ScriptDir & "\Resource\PrintCtrl.ico")

While 1
        Switch TrayGetMsg()
                Case $TRAY_EVENT_PRIMARYDOWN ;Click 1
                        GUI_SetState()
                Case $TRAY_EVENT_PRIMARYDOUBLE ;Click 2
                        GUI_SetState()
                Case $Exit
                        _Exit()
        EndSwitch
WEnd

Func _Exit()
        $Button_PrintCtrl_ID = MsgBox(4 + 32 + 8192 + 262144, "退出", '您的打印任务可能会中断,确定要退出打印后台吗?')
        If $Button_PrintCtrl_ID = 6 Then Exit
EndFunc   ;==>_Exit

Func GUI_SetState()
        Exit ;注释掉
        $GUI_IsVisible = _WinAPI_IsWindowVisible($hGUI)
        If $GUI_IsVisible = False Then
                GUISetState(@SW_RESTORE, $hGUI)
                GUISetState(@SW_SHOW, $hGUI)
        Else
                GUISetState(@SW_HIDE, $hGUI)
        EndIf
EndFunc   ;==>GUI_SetState

Func menu_CancelAllPrintItemClick()
        $Row = _GUICtrlListView_GetItemCount($idListView)
        If $Row > 0 Then
                $Button_CancelAllPrintItem_ID = MsgBox(4 + 32 + 8192 + 262144, "取消队列", '您真的要取消所有打印作业吗?')
                If $Button_CancelAllPrintItem_ID = 6 Then
                        
                        For $Index = 0 To $Row - 1
                                $PrintStatus = _GUICtrlListView_GetItemTextArray($idListView, $Index)[9]
                                If $PrintStatus = '已完成' Then _GUICtrlListView_SetItemSelected($idListView, $Index, True)

                        Next
                        
                        _GUICtrlListView_DeleteItemsSelected($idListView) ;取消打印

                EndIf
        EndIf
EndFunc   ;==>menu_CancelAllPrintItemClick

Func PathSplit($File)
        $Filename = _WinAPI_PathFindFileName(_WinAPI_PathRemoveExtension($File))
        $Extension = _WinAPI_PathFindExtension($File)
        Local $PathIsRoot = '\'
        $dir = _WinAPI_PathRemoveFileSpec($File)
        If _WinAPI_PathIsRoot($dir) Then $PathIsRoot = ''
        $dir = $dir & $PathIsRoot
        $SkipRootAfterDir = _WinAPI_PathSkipRoot(StringReplace($dir, @DesktopDir, ""))
EndFunc   ;==>PathSplit



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2019-8-26 16:07:42 | 显示全部楼层
代码要精简,问题才有针对性…

...
_GUICtrlMenu_CheckMenuItem($hMenu, 0)        ;勾选打开
GUISetState(@SW_SHOW)
 楼主| 发表于 2019-8-26 16:26:47 | 显示全部楼层
afan 发表于 2019-8-26 16:07
代码要精简,问题才有针对性…

...

额,是的 ,多谢Afan 兄
发表于 2019-8-27 13:07:48 | 显示全部楼层
学习了,学习了
发表于 2019-8-28 12:34:12 | 显示全部楼层
大開眼界 謝謝分享
发表于 2019-9-2 01:00:17 | 显示全部楼层
不错支持一下
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-3-29 02:47 , Processed in 0.075136 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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