Jump to content

Recommended Posts

Posted

Hi guys,

need some helps here. i was trying to check if there's any excel file opened, then disable the ok button. Enable it Until the excel file is closed. I managed to do that, but the thing is when there's excel file open and i click on cancel or $GUI_EVENT_CLOSE button, it didnt work. It will work after i closed my excel file.

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Timers.au3>
#include <GuiStatusBar.au3>
#include <ProgressConstants.au3>
#include <GuiListView.au3>
#include <Date.au3>
Global $hStatusBar, $LWSelectedICurrent = -1,$Sec, $Min, $Hour, $Time
Local $StartTicks = _TimeToTicks(@HOUR, @MIN, @SEC)
;MsgBox(0,"",$StartTicks)
; calculate 1 minutes later
Local $EndTicks = ($StartTicks + 1 * 60 * 1000)
;MsgBox(0,"",$EndTicks)
_TicksToTime($EndTicks, $Hour, $Min, $Sec)
;MsgBox(262144, '', 'If No selection has been made,the Program Will terminate at :' & $Hour & ":" & $Min & ":" & $Sec)
Local $hGUI, $iTimerProgress
Local $aParts[3] = [100,250,-1]
dim $Selection
Example()
Func Example()
Local $listview, $button,$Cancel, $item1, $item2, $item3,$item4, $msg
$hGUI = GUICreate("Test Summary Generation", 300, 250, 600, 500, -1, $WS_EX_ACCEPTFILES)
;ToolTip("If No selection has been made,the Program Will terminate at : " & StringFormat("%02d:%02d:%02d", $Hour, $Min, $Sec), 600, 720)
ToolTip("If No selection has been made,the Program Will terminate at : " & $Hour & ":" & $Min & ":" & $Sec, 600, 720)
GUISetBkColor(0x00E0FFFF) ; will change background color
$listview = GUICtrlCreateListView("Test Summary Update  ", 50,10, 200, 150);,$LVS_SORTDESCENDING)
$button = GUICtrlCreateButton("OK", 75, 170, 70, 20)
$Cancel = GUICtrlCreateButton("Cancel", 150, 170, 70, 20)
$item1 = GUICtrlCreateListViewItem("item1", $listview)
$item2 = GUICtrlCreateListViewItem("item2", $listview)
$hStatusBar = _GUICtrlStatusBar_Create($hGUI, $aParts)
_GUICtrlStatusBar_SetText($hStatusBar,"Current Date : " & StringFormat("%02d-%02d-%02d", @MDAY, @MON, @YEAR), 1)
_GUICtrlStatusBar_SetText($hStatusBar,@TAB & @TAB & StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC), 2)
_GUICtrlStatusBar_SetText($hStatusBar,"No Selection")
_Timer_SetTimer($hGUI, 1000, "_UpdateStatusBarClock")
GUICtrlSetData($item1, "Exchange Online")
GUICtrlSetData($item2, "OCS Wave 14")
GUISetState()

[b]While ProcessExists('Excel.EXE'); Checks if process is running maybe?
MsgBox(16,'Excel Status','Close And Save any Excel file')
GUICtrlSetState ($button,$GUI_DISABLE)
if ProcessWaitClose('Excel.EXE')Then
GUICtrlSetState ($button,$GUI_ENABLE)[/b]
[b]EndIf
WEnd[/b]

Do
  
   $LWSelectedI = _GUICtrlListView_GetSelectedIndices($listview, true)
   If $LWSelectedI[0] <> 0 Then
   If $LWSelectedI[1] <> $LWSelectedICurrent Then
   _GUICtrlStatusBar_SetText($hStatusBar,_GUICtrlListView_GetItemTextString($listview ,$LWSelectedI[1]))
   $LWSelectedICurrent = $LWSelectedI[1]
   EndIf
   EndIf
$msg = GUIGetMsg()
Select
Case $msg = $button
;MsgBox(0, "Selection Made", GUICtrlRead(GUICtrlRead($listview)))
$Selection= guictrlread($listview)
if $selection = 6 or $selection=7 Then
local $answer=MsgBox(1, "Selection Made", _GUICtrlListView_GetItemTextString($listview ,$LWSelectedICurrent) & @LF & "Note* You can Press {ECS} key to terminate program when generating the summary*")
if $answer = 1 Then
ExitLoop
EndIf
if $answer = 2 Then
$rreturn = 00123
endif
EndIf
if $selection = 0 Then
msgbox (16,"Please Select","No Selection")
Elseif $rreturn = 00123 then
else
ExitLoop
endif
Case $msg = $listview
MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
Case $msg = $GUI_EVENT_CLOSE Or $msg = $Cancel
;ExitLoop
_Exit()
EndSelect
Until $msg = $GUI_EVENT_CLOSE
EndFunc ;==>Example
Func _UpdateStatusBarClock($hWnd, $Msg, $iIDTimer, $dwTime)
#forceref $hWnd, $Msg, $iIDTimer, $dwTime
_GUICtrlStatusBar_SetText($hStatusBar, @TAB & @TAB & StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC), 2)
$livetime = _TimeToTicks(@HOUR, @MIN, @SEC)
;$EndTicks = $Hour & ":" & $Min & ":" & $Sec
;MsgBox(0,"",$livetime)
;MsgBox(0,"",$EndTicks)
if $livetime  = $EndTicks Then
MsgBox(0,"Program Self-Termination","No Selection has been Made",10)
_Exit()
EndIf
EndFunc ;==>_UpdateStatusBarClock

Func _Exit()
    Exit
EndFunc   ;==>_Exit
exit
Posted

woah... try pasting them in autoit tags, rather than code tags to make it easier to read please?

Anyway, the problem is because you don't run GuiGetMsg in your script, until excel has been closed.

Posted

hmmmm....still unsuccessful

While ProcessExists('Excel.EXE')
  $msg = GUIGetMsg()
MsgBox(16,'Excel Status','Close And Save any Excel file')
GUICtrlSetState ($button,$GUI_DISABLE)
if ProcessWaitClose('Excel.EXE')Then
GUICtrlSetState ($button,$GUI_ENABLE)
  ExitLoop
elseif $msg = $GUI_EVENT_CLOSE Or $msg = $Cancel Then
_exit()
EndIf
WEnd
Posted

Does this meet your needs.

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Timers.au3>
#include <GuiStatusBar.au3>
#include <ProgressConstants.au3>
#include <GuiListView.au3>
#include <Date.au3>
Global $hStatusBar, $LWSelectedICurrent = -1,$Sec, $Min, $Hour, $Time
Local $StartTicks = _TimeToTicks(@HOUR, @MIN, @SEC)
;MsgBox(0,"",$StartTicks)
; calculate 1 minutes later
Local $EndTicks = ($StartTicks + 1 * 60 * 1000)
;MsgBox(0,"",$EndTicks)
_TicksToTime($EndTicks, $Hour, $Min, $Sec)
;MsgBox(262144, '', 'If No selection has been made,the Program Will terminate at :' & $Hour & ":" & $Min & ":" & $Sec)
Local $hGUI, $iTimerProgress
Local $aParts[3] = [100,250,-1]
dim $Selection
Example()
Func Example()
Local $listview, $button,$Cancel, $item1, $item2, $item3,$item4, $msg
$hGUI = GUICreate("Test Summary Generation", 300, 250, 600, 500, -1, $WS_EX_ACCEPTFILES)
;ToolTip("If No selection has been made,the Program Will terminate at : " & StringFormat("%02d:%02d:%02d", $Hour, $Min, $Sec), 600, 720)
ToolTip("If No selection has been made,the Program Will terminate at : " & $Hour & ":" & $Min & ":" & $Sec, 600, 720)
GUISetBkColor(0x00E0FFFF) ; will change background color
$listview = GUICtrlCreateListView("Test Summary Update  ", 50,10, 200, 150);,$LVS_SORTDESCENDING)
$button = GUICtrlCreateButton("OK", 75, 170, 70, 20)
$Cancel = GUICtrlCreateButton("Cancel", 150, 170, 70, 20)
$item1 = GUICtrlCreateListViewItem("item1", $listview)
$item2 = GUICtrlCreateListViewItem("item2", $listview)
$hStatusBar = _GUICtrlStatusBar_Create($hGUI, $aParts)
_GUICtrlStatusBar_SetText($hStatusBar,"Current Date : " & StringFormat("%02d-%02d-%02d", @MDAY, @MON, @YEAR), 1)
_GUICtrlStatusBar_SetText($hStatusBar,@TAB & @TAB & StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC), 2)
_GUICtrlStatusBar_SetText($hStatusBar,"No Selection")
_Timer_SetTimer($hGUI, 1000, "_UpdateStatusBarClock")
GUICtrlSetData($item1, "Exchange Online")
GUICtrlSetData($item2, "OCS Wave 14")
GUISetState()
If ProcessExists('Excel.EXE') <> 0 Then
   GUICtrlSetState ($button,$GUI_DISABLE)
   MsgBox(16,'Excel Status','Close And Save any Excel file')
EndIf
While ProcessExists('Excel.EXE')
   $Msg = GUIGetMsg()
  
   If $Msg = $GUI_EVENT_CLOSE Or $Msg = $Cancel Then
   _exit()
   EndIf
WEnd
If ProcessExists('Excel.EXE') = 0 Then
   GUICtrlSetState ($button,$GUI_ENABLE)
EndIf
Do
 
   $LWSelectedI = _GUICtrlListView_GetSelectedIndices($listview, true)
   If $LWSelectedI[0] <> 0 Then
   If $LWSelectedI[1] <> $LWSelectedICurrent Then
   _GUICtrlStatusBar_SetText($hStatusBar,_GUICtrlListView_GetItemTextString($listview ,$LWSelectedI[1]))
   $LWSelectedICurrent = $LWSelectedI[1]
   EndIf
   EndIf
$msg = GUIGetMsg()
Select
Case $msg = $button
;MsgBox(0, "Selection Made", GUICtrlRead(GUICtrlRead($listview)))
$Selection= guictrlread($listview)
if $selection = 6 or $selection=7 Then
local $answer=MsgBox(1, "Selection Made", _GUICtrlListView_GetItemTextString($listview ,$LWSelectedICurrent) & @LF & "Note* You can Press {ECS} key to terminate program when generating the summary*")
if $answer = 1 Then
ExitLoop
EndIf
if $answer = 2 Then
$rreturn = 00123
endif
EndIf
if $selection = 0 Then
msgbox (16,"Please Select","No Selection")
Elseif $rreturn = 00123 then
else
ExitLoop
endif
Case $msg = $listview
MsgBox(0, "listview", "clicked=" & GUICtrlGetState($listview), 2)
Case $msg = $GUI_EVENT_CLOSE Or $msg = $Cancel
;ExitLoop
_Exit()
EndSelect
Until $msg = $GUI_EVENT_CLOSE
EndFunc ;==>Example
Func _UpdateStatusBarClock($hWnd, $Msg, $iIDTimer, $dwTime)
#forceref $hWnd, $Msg, $iIDTimer, $dwTime
_GUICtrlStatusBar_SetText($hStatusBar, @TAB & @TAB & StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC), 2)
$livetime = _TimeToTicks(@HOUR, @MIN, @SEC)
;$EndTicks = $Hour & ":" & $Min & ":" & $Sec
;MsgBox(0,"",$livetime)
;MsgBox(0,"",$EndTicks)
if $livetime  = $EndTicks Then
MsgBox(0,"Program Self-Termination","No Selection has been Made",10)
_Exit()
EndIf
EndFunc ;==>_UpdateStatusBarClock
Func _Exit()
    Exit
EndFunc   ;==>_Exit
exit

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...