【已解决】关于状态栏的请教
本帖最后由 anythinging 于 2021-2-24 21:58 编辑关于状态栏,遇到2个小问题,在此请教各位!
1、右对齐 被吃进去了一此,目前只会用在后面加空格解决。
2、窗口最大化或调整大小,状态栏无法随着变化
代码是帮助文件的例子,加了个样式
感谢!
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
Global $g_idMemo, $g_hMainGUI, $g_hStatus
Example()
Func Example()
Local $hGUI
Local $aText = ["左对齐", @TAB & "居中", @TAB & @TAB & "右对齐"]
Local $aParts =
; 创建 GUI
$hGUI = GUICreate("(示例 3) 创建状态栏", 400, 300,-1,-1,BitOR($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX ,$WS_MAXIMIZEBOX ) )
;设置组件与文本
$g_hStatus = _GUICtrlStatusBar_Create($hGUI, $aParts, $aText)
; 创建备忘录控件
$g_idMemo = GUICtrlCreateEdit("", 2, 2, 396, 274, $WS_VSCROLL)
GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
GUICtrlSendMsg($g_idMemo, $EM_SETREADONLY, True, 0)
GUICtrlSetBkColor($g_idMemo, 0xFFFFFF)
GUISetState(@SW_SHOW)
MemoWrite("状态栏创建:" & @CRLF & _
@TAB & "句柄," & @CRLF & _
@TAB & "组件宽度数组, 3 个元素" & @CRLF & _
@TAB & "组件文本数组, 3 个元素" & @CRLF)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
; 获取边框尺寸
MemoWrite("水平边框宽度 .: " & _GUICtrlStatusBar_GetBordersHorz($g_hStatus))
MemoWrite("垂直边框宽度 .: " & _GUICtrlStatusBar_GetBordersVert($g_hStatus))
MemoWrite("矩形宽度 .....: " & _GUICtrlStatusBar_GetBordersRect($g_hStatus))
; 循环到用户退出.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUISetState(@SW_ENABLE, $g_hMainGUI)
GUIDelete($hGUI)
EndFunc ;==>Example
; 写脚本运行消息到备忘录控件
Func MemoWrite($sMessage = "")
GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Local $tInfo
Switch $hWndFrom
Case $g_hStatus
Switch $iCode
Case $NM_CLICK ; 用户在控件范围内点击鼠标左键
$tInfo = DllStructCreate($tagNMMOUSE, $lParam)
$hWndFrom = HWnd(DllStructGetData($tInfo, "hWndFrom"))
$iIDFrom = DllStructGetData($tInfo, "IDFrom")
$iCode = DllStructGetData($tInfo, "Code")
_DebugPrint("$NM_CLICK" & @CRLF & "--> 控件句柄:" & @TAB & $hWndFrom & @CRLF & _
"-->控件 ID:" & @TAB & $iIDFrom & @CRLF & _
"-->操作代码:" & @TAB & $iCode & @CRLF & _
"-->项目规格:" & @TAB & DllStructGetData($tInfo, "ItemSpec") & @CRLF & _
"-->项目数据:" & @TAB & DllStructGetData($tInfo, "ItemData") & @CRLF & _
"-->X 坐标:" & @TAB & DllStructGetData($tInfo, "X") & @CRLF & _
"-->Y 坐标:" & @TAB & DllStructGetData($tInfo, "Y") & @CRLF & _
"-->点击消息:" & @TAB & DllStructGetData($tInfo, "HitInfo"))
Return True ; 处理鼠标点击, 制止系统默认处理
; Return FALSE ;允许默认处理点击操作.
Case $NM_DBLCLK ; 用户在控件内双击鼠标左键
$tInfo = DllStructCreate($tagNMMOUSE, $lParam)
$hWndFrom = HWnd(DllStructGetData($tInfo, "hWndFrom"))
$iIDFrom = DllStructGetData($tInfo, "IDFrom")
$iCode = DllStructGetData($tInfo, "Code")
_DebugPrint("$NM_DBLCLK" & @CRLF & "--> 控件句柄:" & @TAB & $hWndFrom & @CRLF & _
"-->控件 ID:" & @TAB & $iIDFrom & @CRLF & _
"-->操作代码:" & @TAB & $iCode & @CRLF & _
"-->项目规格:" & @TAB & DllStructGetData($tInfo, "ItemSpec") & @CRLF & _
"-->项目数据:" & @TAB & DllStructGetData($tInfo, "ItemData") & @CRLF & _
"-->X 坐标:" & @TAB & DllStructGetData($tInfo, "X") & @CRLF & _
"-->Y 坐标:" & @TAB & DllStructGetData($tInfo, "Y") & @CRLF & _
"-->点击消息:" & @TAB & DllStructGetData($tInfo, "HitInfo"))
Return True ; 处理鼠标点击, 制止系统默认处理
; Return FALSE ;允许默认处理点击操作.
Case $NM_RCLICK ; 用户在控件范围内单击鼠标右键
$tInfo = DllStructCreate($tagNMMOUSE, $lParam)
$hWndFrom = HWnd(DllStructGetData($tInfo, "hWndFrom"))
$iIDFrom = DllStructGetData($tInfo, "IDFrom")
$iCode = DllStructGetData($tInfo, "Code")
_DebugPrint("$NM_RCLICK" & @CRLF & "--> 控件句柄:" & @TAB & $hWndFrom & @CRLF & _
"-->控件 ID:" & @TAB & $iIDFrom & @CRLF & _
"-->操作代码:" & @TAB & $iCode & @CRLF & _
"-->项目规格:" & @TAB & DllStructGetData($tInfo, "ItemSpec") & @CRLF & _
"-->项目数据:" & @TAB & DllStructGetData($tInfo, "ItemData") & @CRLF & _
"-->X 坐标:" & @TAB & DllStructGetData($tInfo, "X") & @CRLF & _
"-->Y 坐标:" & @TAB & DllStructGetData($tInfo, "Y") & @CRLF & _
"-->点击消息:" & @TAB & DllStructGetData($tInfo, "HitInfo"))
Return True ; 处理鼠标点击, 制止系统默认处理
; Return FALSE ;允许默认处理点击操作.
Case $NM_RDBLCLK ; 用户在控件范围内双击鼠标右键
$tInfo = DllStructCreate($tagNMMOUSE, $lParam)
$hWndFrom = HWnd(DllStructGetData($tInfo, "hWndFrom"))
$iIDFrom = DllStructGetData($tInfo, "IDFrom")
$iCode = DllStructGetData($tInfo, "Code")
_DebugPrint("$NM_RDBLCLK" & @CRLF & "--> 控件句柄:" & @TAB & $hWndFrom & @CRLF & _
"-->控件 ID:" & @TAB & $iIDFrom & @CRLF & _
"-->操作代码:" & @TAB & $iCode & @CRLF & _
"-->项目规格:" & @TAB & DllStructGetData($tInfo, "ItemSpec") & @CRLF & _
"-->项目数据:" & @TAB & DllStructGetData($tInfo, "ItemData") & @CRLF & _
"-->X 坐标:" & @TAB & DllStructGetData($tInfo, "X") & @CRLF & _
"-->Y 坐标:" & @TAB & DllStructGetData($tInfo, "Y") & @CRLF & _
"-->点击消息:" & @TAB & DllStructGetData($tInfo, "HitInfo"))
Return True ; 处理鼠标点击, 制止系统默认处理
; Return FALSE ;允许默认处理点击操作.
Case $SBN_SIMPLEMODECHANGE ; 简单模式改变
_DebugPrint("$SBN_SIMPLEMODECHANGE" & @CRLF & "--> 控件句柄:" & @TAB & $hWndFrom & @CRLF & _
"-->控件 ID:" & @TAB & $iIDFrom & @CRLF & _
"-->操作代码:" & @TAB & $iCode)
; 没有返回值
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @CRLF & _
"+======================================================" & @CRLF & _
"-->行号(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
"+======================================================" & @CRLF)
EndFunc ;==>_DebugPrint
感谢指点,解决了!
代码如下:
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
Global $g_idMemo, $g_hMainGUI, $g_hStatus
Example()
Func Example()
Local $hGUI
Local $aText = ["左对齐", @TAB & "居中", @TAB & @TAB & "右对齐"]
Local $aParts =
; 创建 GUI
$hGUI = GUICreate("(示例 3) 创建状态栏", 400, 300,-1,-1,BitOR($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX ,$WS_MAXIMIZEBOX ) )
;设置组件与文本
$g_hStatus = _GUICtrlStatusBar_Create($hGUI, $aParts, $aText)
; 创建备忘录控件
$g_idMemo = GUICtrlCreateEdit("", 2, 2, 396, 274, $WS_VSCROLL)
GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
GUICtrlSendMsg($g_idMemo, $EM_SETREADONLY, True, 0)
GUICtrlSetBkColor($g_idMemo, 0xFFFFFF)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
MemoWrite("状态栏创建:" & @CRLF & _
@TAB & "句柄," & @CRLF & _
@TAB & "组件宽度数组, 3 个元素" & @CRLF & _
@TAB & "组件文本数组, 3 个元素" & @CRLF)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
; 获取边框尺寸
MemoWrite("水平边框宽度 .: " & _GUICtrlStatusBar_GetBordersHorz($g_hStatus))
MemoWrite("垂直边框宽度 .: " & _GUICtrlStatusBar_GetBordersVert($g_hStatus))
MemoWrite("矩形宽度 .....: " & _GUICtrlStatusBar_GetBordersRect($g_hStatus))
; 循环到用户退出.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUISetState(@SW_ENABLE, $g_hMainGUI)
GUIDelete($hGUI)
EndFunc ;==>Example
; 写脚本运行消息到备忘录控件
Func MemoWrite($sMessage = "")
GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Local $tInfo
Switch $hWndFrom
Case $g_hStatus
Switch $iCode
Case $NM_CLICK ; 用户在控件范围内点击鼠标左键
$tInfo = DllStructCreate($tagNMMOUSE, $lParam)
$hWndFrom = HWnd(DllStructGetData($tInfo, "hWndFrom"))
$iIDFrom = DllStructGetData($tInfo, "IDFrom")
$iCode = DllStructGetData($tInfo, "Code")
_DebugPrint("$NM_CLICK" & @CRLF & "--> 控件句柄:" & @TAB & $hWndFrom & @CRLF & _
"-->控件 ID:" & @TAB & $iIDFrom & @CRLF & _
"-->操作代码:" & @TAB & $iCode & @CRLF & _
"-->项目规格:" & @TAB & DllStructGetData($tInfo, "ItemSpec") & @CRLF & _
"-->项目数据:" & @TAB & DllStructGetData($tInfo, "ItemData") & @CRLF & _
"-->X 坐标:" & @TAB & DllStructGetData($tInfo, "X") & @CRLF & _
"-->Y 坐标:" & @TAB & DllStructGetData($tInfo, "Y") & @CRLF & _
"-->点击消息:" & @TAB & DllStructGetData($tInfo, "HitInfo"))
Return True ; 处理鼠标点击, 制止系统默认处理
; Return FALSE ;允许默认处理点击操作.
Case $NM_DBLCLK ; 用户在控件内双击鼠标左键
$tInfo = DllStructCreate($tagNMMOUSE, $lParam)
$hWndFrom = HWnd(DllStructGetData($tInfo, "hWndFrom"))
$iIDFrom = DllStructGetData($tInfo, "IDFrom")
$iCode = DllStructGetData($tInfo, "Code")
_DebugPrint("$NM_DBLCLK" & @CRLF & "--> 控件句柄:" & @TAB & $hWndFrom & @CRLF & _
"-->控件 ID:" & @TAB & $iIDFrom & @CRLF & _
"-->操作代码:" & @TAB & $iCode & @CRLF & _
"-->项目规格:" & @TAB & DllStructGetData($tInfo, "ItemSpec") & @CRLF & _
"-->项目数据:" & @TAB & DllStructGetData($tInfo, "ItemData") & @CRLF & _
"-->X 坐标:" & @TAB & DllStructGetData($tInfo, "X") & @CRLF & _
"-->Y 坐标:" & @TAB & DllStructGetData($tInfo, "Y") & @CRLF & _
"-->点击消息:" & @TAB & DllStructGetData($tInfo, "HitInfo"))
Return True ; 处理鼠标点击, 制止系统默认处理
; Return FALSE ;允许默认处理点击操作.
Case $NM_RCLICK ; 用户在控件范围内单击鼠标右键
$tInfo = DllStructCreate($tagNMMOUSE, $lParam)
$hWndFrom = HWnd(DllStructGetData($tInfo, "hWndFrom"))
$iIDFrom = DllStructGetData($tInfo, "IDFrom")
$iCode = DllStructGetData($tInfo, "Code")
_DebugPrint("$NM_RCLICK" & @CRLF & "--> 控件句柄:" & @TAB & $hWndFrom & @CRLF & _
"-->控件 ID:" & @TAB & $iIDFrom & @CRLF & _
"-->操作代码:" & @TAB & $iCode & @CRLF & _
"-->项目规格:" & @TAB & DllStructGetData($tInfo, "ItemSpec") & @CRLF & _
"-->项目数据:" & @TAB & DllStructGetData($tInfo, "ItemData") & @CRLF & _
"-->X 坐标:" & @TAB & DllStructGetData($tInfo, "X") & @CRLF & _
"-->Y 坐标:" & @TAB & DllStructGetData($tInfo, "Y") & @CRLF & _
"-->点击消息:" & @TAB & DllStructGetData($tInfo, "HitInfo"))
Return True ; 处理鼠标点击, 制止系统默认处理
; Return FALSE ;允许默认处理点击操作.
Case $NM_RDBLCLK ; 用户在控件范围内双击鼠标右键
$tInfo = DllStructCreate($tagNMMOUSE, $lParam)
$hWndFrom = HWnd(DllStructGetData($tInfo, "hWndFrom"))
$iIDFrom = DllStructGetData($tInfo, "IDFrom")
$iCode = DllStructGetData($tInfo, "Code")
_DebugPrint("$NM_RDBLCLK" & @CRLF & "--> 控件句柄:" & @TAB & $hWndFrom & @CRLF & _
"-->控件 ID:" & @TAB & $iIDFrom & @CRLF & _
"-->操作代码:" & @TAB & $iCode & @CRLF & _
"-->项目规格:" & @TAB & DllStructGetData($tInfo, "ItemSpec") & @CRLF & _
"-->项目数据:" & @TAB & DllStructGetData($tInfo, "ItemData") & @CRLF & _
"-->X 坐标:" & @TAB & DllStructGetData($tInfo, "X") & @CRLF & _
"-->Y 坐标:" & @TAB & DllStructGetData($tInfo, "Y") & @CRLF & _
"-->点击消息:" & @TAB & DllStructGetData($tInfo, "HitInfo"))
Return True ; 处理鼠标点击, 制止系统默认处理
; Return FALSE ;允许默认处理点击操作.
Case $SBN_SIMPLEMODECHANGE ; 简单模式改变
_DebugPrint("$SBN_SIMPLEMODECHANGE" & @CRLF & "--> 控件句柄:" & @TAB & $hWndFrom & @CRLF & _
"-->控件 ID:" & @TAB & $iIDFrom & @CRLF & _
"-->操作代码:" & @TAB & $iCode)
; 没有返回值
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @CRLF & _
"+======================================================" & @CRLF & _
"-->行号(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
"+======================================================" & @CRLF)
EndFunc ;==>_DebugPrint
; GUI 大小变化时, 调整状态栏
Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam, $lParam
_GUICtrlStatusBar_Resize($g_hStatus)
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_SIZE
状态栏没有对齐方式样式,可以试试内嵌带对齐样式的 Label 控件
看 _GUICtrlStatusBar_Resize() 本帖最后由 gyp2000 于 2021-2-24 22:24 编辑
anythinging 发表于 2021-2-24 21:57
感谢指点,解决了!
代码如下:
你这编辑框不对,未能跟随改变大小
$g_idMemo = GUICtrlCreateEdit("", 2, 2, 396, 274, $WS_VSCROLL); 22行
GUICtrlSetResizing(-1, 102);这里要添加: 设置窗口缩放时控件位置/大小的调整方式 gyp2000 发表于 2021-2-24 22:20
你这编辑框不对,未能跟随改变大小
$g_idMemo = GUICtrlCreateEdit("", 2, 2, 396, 274, $WS_VSCROL ...
感谢回复,这试了下加不加这句好象没区别 anythinging 发表于 2021-2-25 20:49
感谢回复,这试了下加不加这句好象没区别
不添加的话,编辑框缩放异常。
页:
[1]