;=========================================================================== ; StatusMsgs ; ; Creates a status window for alerts and information messages ; Kerry Kobashi ; Kobashi Computing ; September 16, 2012 ; ; Website: http://www.kobashicomputing.com ; ; Modified by MBee to use global variables and to optionally write to log file - 03-June-2016 ; & To Allow writing to log file without showing log window on screen - 11-Mar-2019 ; ;=========================================================================== #include-once ;=========================================================================== ;Include Files ;=========================================================================== #include #include #include #include ; ;=========================================================================== ;Global variable (value must be maintained once initialized) ;=========================================================================== Global $G_StatMsg_ShowStatus ; True if user wants to output status messages. Assume not. Global $G_StatMsg_ShowTime ; True if user wants to include the time with the msg Global $G_StatMsg_LogToFile ; True if user wants to log messages to file as well Global $G_StatMsg_LogFileHdl ; Handle to output log file (or 0 if unused) ; ;=========================================================================== ;Local variables (private) ;=========================================================================== Local $StatusMsgs_hWnd Local $StatusMsgs_listView Local $StatusMsgs_MAXMESSAGES = 100 Local $Style ;=========================================================================== ;Functions ;=========================================================================== ;Functions ;=========================================================================== ; mm/dd/yyyy hh:mm:ss Func StatusMsgs_GetCurrentDateTime() Local $dateTime = _Date_Time_GetSystemTime() Local $strDateTime = _Date_Time_SystemTimeToDateTimeStr($dateTime,0) return($strDateTime) EndFunc ;==> StatusMsgs_GetCurrentDateTime ; Func StatusMsgs_Create($arg_ShowStatus = False, $arg_ShowTime = True, $arg_LogToFile = False, $arg_LogFilePath = "") $G_StatMsg_LogToFile = $arg_LogToFile $G_StatMsg_LogFileHdl = 0 $G_StatMsg_ShowStatus = $arg_ShowStatus $G_StatMsg_ShowTime = $arg_ShowTime If $G_StatMsg_LogToFile Then If $arg_LogFilePath <> "" Then $G_StatMsg_LogFileHdl = FileOpen( $arg_LogFilePath, BitOr($FO_CREATEPATH, $FO_OVERWRITE, $FO_ANSI) ) If $G_StatMsg_LogFileHdl = -1 Then Return -1 Else $G_StatMsg_LogToFile = False EndIf EndIf If Not $G_StatMsg_ShowStatus Then Return 1 $Style = BitOr($WS_OVERLAPPEDWINDOW, $WS_VISIBLE) $StatusMsgs_hWnd = GuiCreate("Status Messages",600,600,240,10,$Style,0) $Style = BitOr($WS_BORDER,$WS_VSCROLL,$LVS_REPORT,$LVS_EX_GRIDLINES) $StatusMsgs_listView = _GUICtrlListView_Create($StatusMsgs_hWnd,"",10,10,580,580,$Style) If $G_StatMsg_LogToFile Then _GUICtrlListView_AddColumn($StatusMsgs_listView,"Time",140) EndIf _GUICtrlListView_AddColumn($StatusMsgs_listView,"Message",640) GUISetFont(9, 400, 0, "Courier New") ; Local $L_Stat = IsDeclared("$G_MaxStatMsgs") If $L_Stat = $DECLARED_GLOBAL Then $StatusMsgs_MAXMESSAGES = Eval("$G_MaxStatMsgs") Else $StatusMsgs_MAXMESSAGES = 100 EndIf ; Return 1 EndFunc ;==> StatusMsgs_Create ; Func StatusMsgs_Destroy() If $G_StatMsg_ShowStatus Then GUIDelete($StatusMsgs_listView) GUIDelete($StatusMsgs_hWnd) EndIf If $G_StatMsg_LogToFile Then FileFlush($G_StatMsg_LogFileHdl) FileClose($G_StatMsg_LogFileHdl) EndIf Return EndFunc ;==> StatusMsgs_Destroy ; Func StatusMsgs_WriteLine($message) If Not $G_StatMsg_ShowStatus Then Return ; We only hold a certain number of messages in the list and then flush it when it exceeds it If (_GUICtrlListView_GetItemCount($StatusMsgs_listView) >= $StatusMsgs_MAXMESSAGES) Then _GUICtrlListView_DeleteItem($StatusMsgs_listView, $StatusMsgs_MAXMESSAGES -1) EndIf ; This is how we enter in a message into the listview if $G_StatMsg_ShowTime Then Dim $aCols[1][2] Local $Lf_CurTime = StatusMsgs_GetCurrentDateTime() $aCols[0][0] = $Lf_CurTime $aCols[0][1] = $message Else Dim $aCols[1][1] $aCols[0][0] = $message EndIf _GUICtrlListView_AddArray($StatusMsgs_listView,$aCols) Return EndFunc ;==> StatusMsgs_WriteLine ; ; ;= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = ; ; Func _MyUpdStatusMsg($arg_Msg) Local $Lf_MsgCount, $Lf_CurTime If $G_StatMsg_ShowTime Then $Lf_CurTime = StatusMsgs_GetCurrentDateTime() Local $Lf_MsgLineAra = StringSplit($arg_Msg, @CR, $STR_ENTIRESPLIT) If @error = 1 Then ; If no crlf delimiters found... StatusMsgs_WriteLine($arg_Msg) If $G_StatMsg_LogToFile Then If $G_StatMsg_ShowTime Then FileWriteLine($G_StatMsg_LogFileHdl, $Lf_CurTime & ": " & $arg_Msg) Else FileWriteLine($G_StatMsg_LogFileHdl, $arg_Msg) EndIf EndIf Else $Lf_MsgCount = $Lf_MsgLineAra[0] For $i = 1 To $Lf_MsgCount StatusMsgs_WriteLine(StringStripCR($Lf_MsgLineAra[$i])) If $G_StatMsg_LogToFile Then If $G_StatMsg_ShowTime Then FileWriteLine($G_StatMsg_LogFileHdl, $Lf_CurTime & ": " & $Lf_MsgLineAra[$i]) Else FileWriteLine($G_StatMsg_LogFileHdl, $Lf_MsgLineAra[$i]) EndIf EndIf Next EndIf Return EndFunc ;==> _MyUpdStatusMsg ;