Jump to content

How to close gui with GUIRegisterMsg


Go to solution Solved by mikell,

Recommended Posts

Posted

Can somebody show me what I'am doing wrong ?

I want to close gui with GUIRegisterMsg

I do not want to use GUIGetMsg .

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

Global $__hGUI

GUI_TESTING("TESTING", 50, 0, 1000, 700)

While Not _IsPressed('13') ; 13 PAUSE key
    Sleep(10)
WEnd

Func GUI_TESTING($sTitle, $iLeft, $iTop, $iWidth, $iHeight)
    ; Create GUI
    $__hGUI = GUICreate($sTitle, $iWidth, $iHeight, $iLeft, $iTop, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_MAXIMIZEBOX))

    ; When window is resized, run this function
    GUIRegisterMsg($WM_EXITSIZEMOVE, "_MY_WM_SIZE")
;~  GUIRegisterMsg($WM_SIZING, "_MY_WM_SIZE")
;~  GUIRegisterMsg($WM_SIZE, "_MY_WM_SIZE")
    GUIRegisterMsg($WM_QUIT, "_DESTROY_GUI")
    GUIRegisterMsg($WM_CLOSE, "_DESTROY_GUI")

    GUISetState()
EndFunc   ;==>GUI_TESTING

Func _MY_WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    MsgBox(1, '_MY_WM_SIZE', 'test')
    If $hWnd = $__hGUI Then
    EndIf
EndFunc   ;==>_MY_WM_SIZE

Func _DESTROY_GUI($hWnd, $Msg, $wParam, $lParam)
    MsgBox(1, 'test 1 ', '_DESTROY_GUI')
    If $hWnd = $__hGUI Then
        MsgBox(1, 'test 2', '_DESTROY_GUI')
        ; Clean up
        GUIDelete($__hGUI)
    EndIf
EndFunc   ;==>_DESTROY_GUI

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Solution
Posted (edited)

;http://msdn.microsoft.com/en-us/library/windows/desktop/ms646360%28v=vs.85%29.aspx

#Include <GUIConstantsEx.au3>

Global Const $SC_CLOSE = 0xF060

$gui = GUICreate("")
GUISetState()
GUIRegisterMsg(0x0112, "OnSysCommand") ; 0x0112 = WM_SYSCOMMAND

While 1
  Sleep(10)
WEnd


Func OnSysCommand($hWnd, $Msg, $wParam, $lParam)
    $test = BitAND($wParam, 0xFFF0)
    If $test = 0xF060 Then Exit
EndFunc

Very raw  but I'm sure you'll be able to carry on  :)

Edited by mikell
  • Moderators
Posted

mikell,

Please put a Sleep in that loop or you will be needing a new CPU. ;)

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:

  Reveal hidden contents

 

Posted
  On 6/11/2014 at 12:17 PM, mikell said:

Very raw  but I'm sure you'll be able to carry on  :)

Thanks man, I'll throw a look at it tonight.

 

ps.

And just in case, put a water cooling for your CPU ;)

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

I did a quick review of the URL specified by you

click by click and....

a quick overview:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms646352(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/ms647984(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/ms647983(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/ms647553(v=vs.85).aspx#accessing_menu_items_programmatically

 

Whether due to these function, somebody could finally do some more precise automation to PopupMenu ?

EDIT:

I'm sorry if I'm going in completely wrong directions ...

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

mikell

Thank you so much.
You'll be able to soon see the use of it in my next UDF.

 

But for now, 

Based on your very good tip,
following piece of code may be useful to someone,

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global Const $SC_CLOSE = 0xF060
Global Const $SC_CONTEXTHELP = 0xF180
Global Const $SC_DEFAULT = 0xF160
Global Const $SC_HOTKEY = 0xF150
Global Const $SC_HSCROLL = 0xF080
Global Const $SC_KEYMENU = 0xF100
Global Const $SC_MAXIMIZE = 0xF030
Global Const $SC_MINIMIZE = 0xF020
Global Const $SC_MONITORPOWER = 0xF170
Global Const $SC_MOUSEMENU = 0xF090
Global Const $SC_MOVE = 0xF010
Global Const $SC_NEXTWINDOW = 0xF040
Global Const $SC_PREVWINDOW = 0xF050
Global Const $SC_RESTORE = 0xF120
Global Const $SC_SCREENSAVE = 0xF140
Global Const $SC_SIZE = 0xF000
Global Const $SC_TASKLIST = 0xF130
Global Const $SC_VSCROLL = 0xF070

Global $gui = GUICreate("OnSysCommand Test", -1, -1, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_MAXIMIZEBOX))
GUISetState()
GUIRegisterMsg(0x0112, "OnSysCommand") ; 0x0112 = WM_SYSCOMMAND

While 1
    Sleep(10)
WEnd

Func OnSysCommand($hWnd, $Msg, $wParam, $lParam)
    If $hWnd = $gui Then
        Local $test = BitAND($wParam, 0xFFF0)
        Switch $test
            Case $SC_CLOSE
                TrayTip('OnSysCommand', '$SC_CLOSE', 5)
                Exit

            Case $SC_CONTEXTHELP
                TrayTip('OnSysCommand', '$SC_CONTEXTHELP', 5)

            Case $SC_DEFAULT
                TrayTip('OnSysCommand', '$SC_DEFAULT', 5)

            Case $SC_HOTKEY
                TrayTip('OnSysCommand', '$SC_HOTKEY', 5)

            Case $SC_HSCROLL
                TrayTip('OnSysCommand', '$SC_HSCROLL', 5)

            Case $SC_KEYMENU
                TrayTip('OnSysCommand', '$SC_KEYMENU', 5)

            Case $SC_MAXIMIZE
                TrayTip('OnSysCommand', '$SC_MAXIMIZE', 5)

            Case $SC_MINIMIZE
                TrayTip('OnSysCommand', '$SC_MINIMIZE', 5)

            Case $SC_MONITORPOWER
                TrayTip('OnSysCommand', '$SC_MONITORPOWER', 5)

            Case $SC_MOUSEMENU
                TrayTip('OnSysCommand', '$SC_MOUSEMENU', 5)

            Case $SC_MOVE
                TrayTip('OnSysCommand', '$SC_MOVE', 5)

            Case $SC_NEXTWINDOW
                TrayTip('OnSysCommand', '$SC_NEXTWINDOW', 5)

            Case $SC_PREVWINDOW
                TrayTip('OnSysCommand', '$SC_PREVWINDOW', 5)

            Case $SC_RESTORE
                TrayTip('OnSysCommand', '$SC_RESTORE', 5)

            Case $SC_SCREENSAVE
                TrayTip('OnSysCommand', '$SC_SCREENSAVE', 5)

            Case $SC_SIZE
                TrayTip('OnSysCommand', '$SC_SIZE', 5)

            Case $SC_TASKLIST
                TrayTip('OnSysCommand', '$SC_TASKLIST', 5)

            Case $SC_VSCROLL
                TrayTip('OnSysCommand', '$SC_VSCROLL', 5)

        EndSwitch
    EndIf
EndFunc   ;==>OnSysCommand

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Nice but instead of enumerating constants, to please guinness and for readability you should better use MenuConstants.au3  :)

After many cogitations about water cooling I finally chose to use Sleep() which is a bit cheaper

Posted

good advice .... this is indeed cheaper ;)

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

For more GUIRegisterMsg magic, check the link in my signature for a working demo for various windows message handlers.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

Thanks, man.
I did not expect that the answers to my questions I had in my face every day ;)

mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Something about me

http://blog.ac-rouen.fr/clg-montesquieu-comenius-project/2011/04/24/polish-poems-translated-into-english/

 

EDIT:

"Glasses"

Mister Hilary runs and screams:

“Where on Earth could my glasses be?”

He checks in his pants and in his frock,
In his shoes, and in his socks.

Closet? Upturned, in a sorry shape,
He pats his robe, already patted his cape.

“A scandal!” he yells, “it’s beyond belief!
To have my glasses—stolen by a thief!”

Under the couch, on top of the seat,
Everywhere he pries: wheezing, beat.

He looks in the oven, and up the chimney,
In mouse holes and between piano keys.

He’ll rip up the floor, piece by piece,
Already he wants to call the police.

Then suddenly he peeks into the mirror…
He can’t believe it… He draws nearer.

Eureka! Though who would ever suppose,
His glasses are on his very own nose."

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 6/11/2014 at 7:40 PM, mikell said:

to please guinness

I honestly stopped caring after v3.3.10.2 was released about improving coding standards around here. Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

cramps, but you did not write anything as you liked the rhyme.

btw.

presently

I'm a beer, so I can sometimes foolishly write ;)

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

mLipok,

Personnally I like the poem but my english is not good enough to allow me to give an appreciation  :)

guinness,

A heartbreaking for sure but a wise decision though  :D

Posted

  On 6/11/2014 at 9:29 PM, mikell said:

guinness,

A heartbreaking for sure but a wise decision though  :D

Ungrateful people like you broke my spirit, so I am glad I found the likes of C# in which standards are respected throughout the community.

PS I am not laughing!

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

guinness,
I'm a teaser and not particularly representative of the AutoIt community
Everybody here is very grateful to you for all your work, and so am I, can you believe this ?

Posted

No excuse to be whining anymore since I have resumed development of PreExpand.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Rather than whinings, surprises with some heavinesses e.g. $STR_REGEXPARRAYGLOBALFULLMATCH (which name should logically be $STR_REGEXPARRAYOFARRAYSGLOBALFULLMATCH btw) 

:)

Posted

  On 6/14/2014 at 8:38 AM, mikell said:

Rather than whinings, surprises with some heavinesses e.g. $STR_REGEXPARRAYGLOBALFULLMATCH (which name should logically be $STR_REGEXPARRAYOFARRAYSGLOBALFULLMATCH btw) 

:)

That's 4.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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...