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

[AU3基础] Toolbar如何居中,显示大字?

[复制链接]
发表于 2013-2-16 03:25:47 | 显示全部楼层 |阅读模式
本帖最后由 heavenm 于 2013-2-16 03:39 编辑
#NoTrayIcon
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <GuiToolBar.au3>
#include <GuiToolTip.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>

Opt("GuiOnEventMode", 1)
#region variables and settings
Global $MSG_NOTIFY
Global Enum $ToolBar_Open = 1000, $ToolBar_Close, $ToolBar_Extract, $ToolBar_View, $ToolBar_Test, $ToolBar_Decrypt
#endregion variables and settings
#region GUI

;===============# Main GUI #===============================================
$hGUIMain = GUICreate("管理工具", @DesktopWidth-10, 79,0,0)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$hToolBar = _GUICtrlToolbar_Create($hGUIMain, $TBSTYLE_FLAT  ,$TBSTYLE_EX_MIXEDBUTTONS         )


$STEP1 = _GUICtrlToolbar_AddString($hToolBar, "测试一下")
$CloseString = _GUICtrlToolbar_AddString($hToolBar, "  进程管理     ")
$ExtractString = _GUICtrlToolbar_AddString($hToolBar, "  垃圾清理    ")
$ViewString = _GUICtrlToolbar_AddString($hToolBar, "  系统安全     ")
$TestString = _GUICtrlToolbar_AddString($hToolBar, "   Test   ")

_GUICtrlToolbar_AddButton($hToolBar, $ToolBar_Open,-1, $STEP1  ) ;窗口管理
_GUICtrlToolbar_AddButtonSep($hToolBar)
_GUICtrlToolbar_AddButton($hToolBar, $ToolBar_Close, -1, $CloseString)
_GUICtrlToolbar_AddButtonSep($hToolBar)

;_GUICtrlToolbar_SetButtonSize($hToolBar, 60, 200)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW, $hGUIMain)
#endregion GUI

If $CmdLine[0] > 0 Then ; 每个事件都需建这个东东
        _SelectArchive() ; 关联第95行
EndIf ;


While 1
        _GetMsgNotify()
        Sleep(100)
WEnd


Func _Exit()
        Exit
EndFunc   ;==>_Exit



Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
        Local $tNMHDR, $hWndFrom, $iCode, $tNMTOOLBAR, $iItem
        
        $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
        $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
        $iCode = DllStructGetData($tNMHDR, "Code")
        
        $tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $lParam)
        $iItem = DllStructGetData($tNMTOOLBAR, "iItem")
        
        Switch $hWndFrom
                Case $hToolBar
                        Switch $iCode
                                Case $NM_LDOWN
                                        Switch $iItem
                                                Case $ToolBar_Open ;这是读取第37行的。
                                                        $MSG_NOTIFY = "MenuOpen" ;第102行
                                        EndSwitch
                        EndSwitch
        EndSwitch
        
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY





Func _GetMsgNotify();获取事件
        Switch $MSG_NOTIFY
                Case "MenuOpen"
                        _SelectArchive() ;第95行
                Case "MenuExit"
                        _Exit()

        EndSwitch
        $MSG_NOTIFY = ""
EndFunc   ;==>_GetMsgNotify

Func _SelectArchive()
        Run("Notepad.exe")
EndFunc   ;==>_SelectArchive
发表于 2013-2-16 08:57:04 | 显示全部楼层
论坛内搜索

工具栏中的AddString 能否设置字符串的字体样
 楼主| 发表于 2013-2-16 14:29:58 | 显示全部楼层
本帖最后由 heavenm 于 2013-2-16 14:47 编辑
论坛内搜索

工具栏中的AddString 能否设置字符串的字体样
veket_linux 发表于 2013-2-16 08:57



    恩  是可以额,但是文字还是没办法居中显示的说!
也不能设置按钮高度,看来这个东东还是比较麻烦的!
 楼主| 发表于 2013-2-16 14:48:22 | 显示全部楼层
#NoTrayIcon
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <GuiToolBar.au3>
#include <GuiToolTip.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <FontConstants.au3>

Opt("GuiOnEventMode", 1)
#region variables and settings
Global $MSG_NOTIFY
Global Enum $ToolBar_Open = 1000, $ToolBar_Close, $ToolBar_Extract, $ToolBar_View, $ToolBar_Test, $ToolBar_Decrypt
#endregion variables and settings
#region GUI

;===============# Main GUI #===============================================
$hGUIMain = GUICreate("管理工具", @DesktopWidth - 10, 79, 0, 0)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$hToolBar = _GUICtrlToolbar_Create($hGUIMain, $TBSTYLE_FLAT)

$hToolBar_Image = _GUIImageList_Create(1, 1, 1, 1)
_GUIImageList_AddIcon($hToolBar_Image, @ScriptDir & "\sicon.DLL", 1, True)
_GUIImageList_AddIcon($hToolBar_Image, @ScriptDir & "\sicon.DLL", 2, True)
_GUIImageList_AddIcon($hToolBar_Image, @ScriptDir & "\sicon.DLL", 3, True)
_GUIImageList_AddIcon($hToolBar_Image, @ScriptDir & "\sicon.DLL", 4, True)
_GUIImageList_AddIcon($hToolBar_Image, @ScriptDir & "\sicon.DLL", 5, True)
_GUIImageList_AddIcon($hToolBar_Image, @ScriptDir & "\sicon.DLL", 6, True)
_GUICtrlToolbar_SetImageList($hToolBar, $hToolBar_Image)


$STEP1 = _GUICtrlToolbar_AddString($hToolBar, "测试一下")

$CloseString = _GUICtrlToolbar_AddString($hToolBar, "  进程管理     ")
$ExtractString = _GUICtrlToolbar_AddString($hToolBar, "  垃圾清理    ")
$ViewString = _GUICtrlToolbar_AddString($hToolBar, "  系统安全     ")
$TestString = _GUICtrlToolbar_AddString($hToolBar, "   Test   ")

_GUICtrlToolbar_AddButton($hToolBar, $ToolBar_Open, 0, $STEP1) ;窗口管理
_GUICtrlToolbar_AddButtonSep($hToolBar)
_GUICtrlToolbar_AddButton($hToolBar, $ToolBar_Close, -1, $CloseString)
_GUICtrlToolbar_AddButtonSep($hToolBar)


;设置字体
$hFont = _WinAPI_CreateFont(16, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, '黑体')
_WinAPI_SetFont($hToolBar, $hFont, True)
_GUICtrlToolbar_SetButtonSize($hToolBar,40, 320)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW, $hGUIMain)
#endregion GUI

If $CmdLine[0] > 0 Then ; 每个事件都需建这个东东
        _SelectArchive() ; 关联第95行
EndIf ;


While 1
        _GetMsgNotify()
        Sleep(100)
WEnd


Func _Exit()
        Exit
EndFunc   ;==>_Exit



Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
        Local $tNMHDR, $hWndFrom, $iCode, $tNMTOOLBAR, $iItem
        
        $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
        $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
        $iCode = DllStructGetData($tNMHDR, "Code")
        
        $tNMTOOLBAR = DllStructCreate($tagNMTOOLBAR, $lParam)
        $iItem = DllStructGetData($tNMTOOLBAR, "iItem")
        
        Switch $hWndFrom
                Case $hToolBar
                        Switch $iCode
                                Case $NM_LDOWN
                                        Switch $iItem
                                                Case $ToolBar_Open ;这是读取第37行的。
                                                        $MSG_NOTIFY = "MenuOpen" ;第102行
                                        EndSwitch
                        EndSwitch
        EndSwitch
        
        Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY





Func _GetMsgNotify();获取事件
        Switch $MSG_NOTIFY
                Case "MenuOpen"
                        _SelectArchive() ;第95行
                Case "MenuExit"
                        _Exit()

        EndSwitch
        $MSG_NOTIFY = ""
EndFunc   ;==>_GetMsgNotify

Func _SelectArchive()
        Run("Notepad.exe")
EndFunc   ;==>_SelectArchive
不完全解决办法 !~~
按钮只能显示一半
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-20 03:36 , Processed in 0.076329 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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