Sign in to follow this  
Followers 0
strate

Button Not Working

1 post in this topic

Below is code that I use at work to print out excel documents. If I try to use the button $Btn_Remove it will not allow it. If I draw it on to the first GUI though it will. What do I need to change to get this to work properly. I want the button on the slide out GUI. Is GUIGetMsg only looking at the first GUI?

#include<ExcelCom.au3>
#include<Array.au3>
#include <GuiConstants.au3>
#Include <GuiList.au3>


Global $Strings[1], $error
Print_Dialog()
$Strings [0] = UBound($Strings)
BlockInput(1)
$ExcelMain = ObjCreate("Excel.Application")
$ExcelMain.Visible = 1
If $Strings[0] > 1 Then
    For $i = 1 To $Strings[0] - 1
        $FilePath = $Strings[$i] 
        $ExcelMain.Workbooks.open ($FilePath, 0)
        $oExcel = ObjGet($FilePath)
        _XLshow ($FilePath, 1)
        $oExcel.Application.activesheet.PrintOut()
;~      _GUICtrlListDeleteItem($mylist,$line)
        $oExcel.close (0)
    Next
EndIf
$ExcelMain.quit
$ExcelMain = ""
BlockInput(0)
Exit


Func Print_Dialog()
$Main = GuiCreate("Excel - Print", 171, 189,(@DesktopWidth-171)/2, (@DesktopHeight-139)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)
$Label_1 = GuiCtrlCreateLabel("Kit Number:", 20, 10, 60, 20)
$Input_2 = GuiCtrlCreateInput("", 20, 30, 130, 20)
$Button_3 = GuiCtrlCreateButton("Next", 20, 60, 60, 20,$BS_DEFPUSHBUTTON)
$Button_4 = GuiCtrlCreateButton("Print", 20, 90, 130, 30)
$Button_4 = GuiCtrlCreateButton("Forms", 20, 130, 130, 20)
$Button_5 = GuiCtrlCreateButton("Exit", 90, 60, 60, 20)
$radio1 = GUICtrlCreateCheckbox ("Show Print List", 20, 160, 130, 20)
;~ Global $Btn_Remove = GuiCtrlCreateButton("Remove From List", 35, 167, 100, 20)
GUICtrlSetState ($radio1,$GUI_CHECKED)

GUICtrlSetState($Input_2,$GUI_FOCUS)
GUISetState (@SW_SHOW)
$Main_Pos = WinGetPos('Excel - Print')
$Print_List = GuiCreate("Print Job List",171, 195, $Main_Pos[0] + $Main_Pos[2],$Main_Pos[1]+25, $WS_POPUP,'',$Main)
Global $mylist=GUICtrlCreateList ("", 10,13,151,150)
_GuiRoundCorners($Print_List, 0, 6, 3, 3)
Global $Btn_Remove = GuiCtrlCreateButton("Remove From List", 35, 167, 100, 20)
GUISetState (@SW_HIDE)

If GUICtrlRead($radio1) = $GUI_CHECKED Then 
    DllCall ( "user32.dll", "int", "AnimateWindow", "hwnd", $Print_List , "int", 500, "long", 0x00040001 );slide in from left
EndIf

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $radio1
        If GUICtrlRead($radio1) = $GUI_UNCHECKED Then 
            DllCall ( "user32.dll", "int", "AnimateWindow", "hwnd", $Print_List, "int", 500, "long", 0x00050002 );slide out to left
        EndIf
        If GUICtrlRead($radio1) = $GUI_CHECKED Then 
            DllCall ( "user32.dll", "int", "AnimateWindow", "hwnd", $Print_List , "int", 500, "long", 0x00040001 );slide in from left
        EndIf
    Case $msg = $GUI_EVENT_CLOSE; Exit
        Exit
    Case $msg = $Button_5; Exit
        Exit
    Case $msg = $Button_3; Next
        $File_Sel = GUICtrlRead($Input_2)
        If FileExists('G:\Packaging\Process Sheets\' & $File_Sel & '.xls') Then
            ReDim $Strings[UBound($Strings) + 1]
            $Strings [UBound($Strings) - 1] = 'G:\Packaging\Process Sheets\' & $File_Sel & '.xls'
            GUICtrlSetData($Input_2,'')
            _GUICtrlListInsertItem($mylist, $File_Sel,1 = -1)
            GUICtrlSetState($Input_2,$GUI_FOCUS)    
        Else
            If $File_Sel = '' Then
                MsgBox(0,'Excel - Print',"ERROR: You did not enter anything into the input box.")
                GUICtrlSetState($Input_2,$GUI_FOCUS)    
            Else
                MsgBox(0,'Excel - Print','ERROR: The number you entered: '&$File_Sel&' does not exist.')
                GUICtrlSetState($Input_2,$GUI_FOCUS)    
            EndIf
        EndIf
    Case $msg = $Button_4; Print
        If GUICtrlRead($Input_2) <> '' Then
            $File_Sel = GUICtrlRead($Input_2)
            ReDim $Strings[UBound($Strings) + 1]
            $Strings [UBound($Strings) - 1] = 'G:\Packaging\Process Sheets\' & $File_Sel & '.xls'
            _GUICtrlListInsertItem($mylist, $File_Sel,1 = -1)
            GUICtrlSetData($Input_2,'')
            GUICtrlSetState($Input_2,$GUI_FOCUS)
        EndIf
        ExitLoop
    Case $msg = $Btn_Remove; Remove Button
        $ret = _GUICtrlListGetSelItems ($mylist)
        If (Not IsArray($ret)) Then
            MsgBox(16, "Error", "Unknown error from _GUICtrlListGetSelItems")
        Else
            For $i = 1 To $ret[0]
                MsgBox(0, "Selected", $ret[$i])
            Next
        EndIf
    EndSelect
WEnd
EndFunc



Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
   Dim $pos, $ret, $ret2
   $pos = WinGetPos($h_win)
   $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $pos[2], "long", $pos[3], "long", $i_x3, "long", $i_y3)
   If $ret[0] Then
      $ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $ret[0], "int", 1)
      If $ret2[0] Then
         Return 1
      Else
         Return 0
      EndIf
   Else
      Return 0
   EndIf
EndFunc ;==>_GuiRoundCorners

INI TreeViewA bus station is where a bus stops, a train station is where a train stops. Onmy desk I have a work station...

Share this post


Link to post
Share on other sites



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
Sign in to follow this  
Followers 0