Jump to content
Sign in to follow this  
fopetesl

Exit not work without button defined (NEWB)

Recommended Posts

fopetesl,

That is an easy one. You are setting the label style to $SS_CENTER - but by so doing you are overwriting the default $SS_NOTIFY style which is required to allow the label to send an event message when clicked. So you need to combine the styles as follows:

$0Box_1 = GUICtrlCreateLabel("Scan", -1, 260, 140, 20, BitOr($SS_NOTIFY, $SS_CENTER))

I suggest reading the Setting Styles tutorial in the Wiki to better understand how styles work.

M23

 


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Did it work for you, M23?

For me it hasn't succeeded

$0Box_1 = GUICtrlCreateLabel("Scan", -1, 100, 140, 20, BitOr($SS_NOTIFY, $SS_CENTER))

I moved the label into the box first since leaving it at y=260 outside the box it worked as before.

Do you need me to repost the whole code?


The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites

fopetesl,

Of course it worked - or I would not have posted the solution. Please do post your current code and I will take another look.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

OK, apologies.

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <StaticConstants.au3>

; Create arrays to hold details of element text and ControlID
Global $aBox_1[3][2] = [[" System Setup", 0], [" My Info Tool", 0], [" User Details Tool", 0]]
Global $aBox_2[3][2] = [[" Manager Reports", 0], [" Currency Details", 0], [" User Details", 0]]

; Create GUI
 $hGUI = GUICreate("New GUI", @DesktopWidth * .99, @DesktopHeight * .96, 0, 0,-1)

; Create tab structure
$cTab = GUICtrlCreateTab(5, 5, @DesktopWidth * .97, @DesktopHeight * .95,-1,1)

;;;; Acquisition tab and action boxes......
; Create tab item
$cTab_0 = GUICtrlCreateTabItem("Acquisition")
; Create coloured box
  GUICtrlCreateLabel("", 20, 40, 250, 220,-1,1)
  GUICtrlSetBkColor(-1, 0xAFEEEE)
  GUICtrlSetState(-1, $GUI_DISABLE) ; And disable so that element labels are actionable
; Add title
  GUICtrlCreateLabel("New Sample", 20, 50, 240, 200,  BitOr($SS_NOTIFY, $SS_CENTER))
  GUICtrlSetFont(-1, 10, 800) ; Set to bold font
  $0Box_1 = GUICtrlCreateLabel("Scan", -1, 60, 140, 20, BitOr($SS_NOTIFY, $SS_CENTER))
  GUICtrlSetFont(-1, 10, 800) ; Set to bold font
  $0Box_2 = GUICtrlCreateLabel("Start Scan", -1, 100, 140, 20, BitOr($SS_NOTIFY, $SS_CENTER))
  GUICtrlSetFont(-1, 10, 800) ; Set to bold font
;;;; ...end..Acquisition tab and action boxes......

;;;;  Manager tab and action boxes......
; And another
$cTab_1 = GUICtrlCreateTabItem("Manager")
GUICtrlSetState($cTab_1, $GUI_SHOW) ; Force to be shown when GUI created
; Create coloured box
GUICtrlCreateLabel("", 20, 40, 150, 100,-1,1)
GUICtrlSetBkColor(-1, 0xFFCCCC)
GUICtrlSetState(-1, $GUI_DISABLE) ; And disable so that element labels are actionable
; Add title
GUICtrlCreateLabel($aBox_1[0][0], 20, 50, 140, 20)
GUICtrlSetFont(-1, Default, 800) ; Set to bold font
; Add actionable elements from the array
For $i = 1 To UBound($aBox_1) - 1
    $aBox_1[$i][1] = GUICtrlCreateLabel($aBox_1[$i][0], 20, 60 + (20 * $i), 140, 20)
Next
; Create another coloured box
GUICtrlCreateLabel("", 20, 180, 150, 100,-1,1)
GUICtrlSetBkColor(-1, 0xCCCCFF)
GUICtrlSetState(-1, $GUI_DISABLE)
; Add title
GUICtrlCreateLabel($aBox_2[0][0], 20, 190, 140, 20)
GUICtrlSetFont(-1, Default, 800)
; Add actionable elements from the array
For $i = 1 To UBound($aBox_2) - 1
    $aBox_2[$i][1] = GUICtrlCreateLabel($aBox_2[$i][0], 20, 200 + (20 * $i), 140, 20)
Next
;;;;;;;;; ..end.. Manager tab & action boxes ;;;;;;;;

;;;;;;;;  Database tab & action boxes.....
; Create another tab item
$cTab_0 = GUICtrlCreateTabItem("Database")
;;;;;;;; ..end.. Database tab & action boxes.....

; Close tab structure creation
GUICtrlCreateTabItem("")

; Add other controls
;$cButton_1 = GUICtrlCreateButton("Button 1", 10, 410, 80, 30)  ; actionable :))
;$cButton_2 = GUICtrlCreateButton("Button 2", 410, 410, 80, 30)

GUISetState()

While 1

    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
 ;       Case $cButton_1
 ;           MsgBox($MB_SYSTEMMODAL, "Clicked", "Button 1")
 ;       Case $cButton_2
 ;           MsgBox($MB_SYSTEMMODAL, "Clicked", "Button 2")
        Case $0Box_1
             MsgBox($MB_SYSTEMMODAL, "Clicked", "Scan")
        Case $0Box_2
             MsgBox($MB_SYSTEMMODAL, "Clicked", "Start Scan")
        Case Else
            ; Now look for the ControlID in the arrays
            For $i = 1 To UBound($aBox_1) - 1
                If $iMsg = $aBox_1[$i][1] Then
                    ; It was this element
                    MsgBox($MB_SYSTEMMODAL, "Clicked", $aBox_1[$i][0])
                    ; No point in looking further
                    ExitLoop
                EndIf
            Next
            For $i = 1 To UBound($aBox_2) - 1
                If $iMsg = $aBox_2[$i][1] Then
                    MsgBox($MB_SYSTEMMODAL, "Clicked", $aBox_2[$i][0])
                    ExitLoop
                EndIf
            Next
    EndSwitch

WEnd

 


The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites

fopetesl,

See if you can spot the difference between this line and your original:

GUICtrlCreateLabel("New Sample", 20, 50, 240, 20, BitOr($SS_NOTIFY, $SS_CENTER))

If you get stuck:

Spoiler

The original label was 200 deep and so the other labels overlapped. AutoIt will not honour overlapped actionable controls as it cannot read your mind to determine which you meant to action. Always a good place to start debugging when you find controls that refuse to action.

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Didn't actually need to see the hidden contents.

One extra Zero blew it. Would a debugger have revealed my typo?

Must remember it's the height of the label, not the box!

Appreciate your patience.


The most powerful number in the Universe.  Zero.

Share this post


Link to post
Share on other sites

fopetesl,

Alas, I fear any debugger would have passed the line as correct - after all, how would it know that you did not really mean to use a perfectly valid value for that parameter? But take heart - you are not alone as I imagine everyone gets caught out by this particular problem from time to time.  As I said above, checking for overlaps is always a good place to start debugging when you come across controls that refuse to action - I usually colour the labels to see exactly where they are located. 

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By muchki
      i am more or less happy with my code
      only the X button does not exit
      what can i do?
      I made an 'exit' button and it works
      pressing Esc works
      just the X button not working
       
      here's my code:
       
      URLTrimmer 1.5.2 12 21 2019.txt
    • By IamKJ
      So I have a lot of different functions in the little program I'm making.  Most of them use the Do statement, such as finding images, clicking buttons, etc.
       
      The question I have is how would I be able to both
      1) Create a hotkey to pause whatever I am doing at the moment.  If I have to put something into every function in the program, I don't mind.
      2) Create a hotkey to exit whatever I am doing and stop all loops or commands and bring back the main GUI?
    • By ur
      I have created an exit function and registered using OnAutoItExitRegister.But it is not running when I close the app from taskbar or even with normal exit during end.
       
      Below is the part of code and the included files.
      #include <MsgBoxConstants.au3> #include <FileConstants.au3> #include <WinAPIFiles.au3> #include <Date.au3> #include <file.au3> #include <Array.au3> #include <String.au3> OnAutoItExitRegister("Exit_Program") Func Exit_Program() LoggingMainScr("Entered Exit_Program") Local $exitmethod = ["Natural closing", "close by Exit function", "close by clicking on exit of the systray","close by user logoff","close by Windows shutdown"] ExitProgram("Exit with exit code: "& @exitCode & " And because of: " & $exitmethod[@exitmethod],@exitmethod) EndFunc Func ExitProgram($sReason="Exit by user",$sCode=0) LoggingMainScr($sReason) if $sCode <> 0 then LoggingMainScr("stopped before completion") FileDelete(@ScriptDir&"\Machines*.txt") FileDelete(@ScriptDir&"\PsExec.exe") FileDelete(@ScriptDir&"\HyperVMachines.ps1") FileDelete(@ScriptDir&"\VMwareMachines.ps1") EndFunc Func LoggingMainScr($sMessage) LoggingDefault($sMessage,@ScriptDir&"\MainScr_Logging.log") EndFunc Func LoggingDefault($sMessage,$sLogFile=@ScriptDir&"\Logging.log") If $sMessage = "" Then FileWriteLine($sLogFile, "") Else FileWrite($sLogFile,_NowCalc() & " :: " & $sMessage&@CRLF) EndIf EndFunc Any suggestion.
       
    • By fosil
      Hi all,

      I'm working on a relatively complex automation program and I need it to call a specific function when it is closed by a user. Ive resorted to "OnAutoItExitRegister" as i believe that's the only option available.

      This command works perfectly fine in a small scale test application I wrote, but once implemented in the final program that's much larger and divided over many files in many directories it no longer works. I don't get any error messages.

      My question is has anyone encountered an issue where implementation of this command in a large scale program gave them trouble? Does it matter where "OnAutoItExitRegister" is called and where the function is located? Currently they are both places in the main file that runs the whole program but it still doesn't work.

      Any help is appreciated
    • By Masum
      Hi all,
      Ctrl+Break stops script only if AutoIt window is active. It doesn't work while automation is going on elsewhere.
      Is there a way to stop the script regardless of where the automation is happening?
      Thanks
×
×
  • Create New...