Sign in to follow this  
Followers 0
LarsJ

Simulating a modeless Choose Color dialog

3 posts in this topic

#1 ·  Posted (edited)

_ChooseColor in <Misc.au3> is based on ChooseColor function in comdlg32.dll. ChooseColor is depending on a  CHOOSECOLOR structure. The Flags and lpfnHook fields in this structure can be used to create a hook function for the ChooseColor window. This hook function can be used to simulate a modeless ChooseColor window. 

There are two interesting features of a hook funtion. It allows you to receive windows messages even if the ChooseColor dialog is a modal window. And it makes it possible to determine which messages are to be forwarded to the ChooseColor dialog, and which are not to be forwarded.

The hook function receives Windows messages before the ChooseColor dialog. If the hook function returns 0, the messages are forwarded to the ChooseColor dialog. If the hook function returns 1 (not 0), the messages are not forwarded to the ChooseColor dialog. Messages that are not forwarded to ChooseColor should be processed by the hook function.

When the OK button in ChooseColor dialog is clicked, this click is handled by the hook function and not forwarded to the ChooseColor dialog. This means, that the ChooseColor window does not close. In the hook function the selected color is calculated and send to the AutoIt window with _SendMessage.

In the zip below the main AutoIt GUI, ChooseColor.au3, contains a button. When you click this button another script, ModelessCC.au3, is started with ShellExecute. ModelessCC.au3 opens the ChooseColor dialog. There is no message loop in ModelessCC.au3. But because ChooseColor is modal, ModelessCC.au3 will not exit until ChooseColor is closed.

The hook function is also running in ModelessCC.au3. The hook function is running even if ChooseColor is modal. The function catches the OK button clicks in ChooseColor and sends the color to the main AutoIt GUI with _SendMessage. The hook function and ChooseColorEx is coded in MiscEx.au3.

The main AutoIt GUI contains 12 labels. Click a label, select a color in the ChooseColor dialog, click the OK button, and the background color of the label will be set to the selected color. You can select colors for all 12 labels without closing the ChooseColor dialog.

 

Modeless%20Choose%20Color%20Dialog%202_z

Tested with AutoIt 3.3.10 on Windows 7 64 bit and Windows XP 32 bit.

ModelessChooseColor.7z

Edited by LarsJ
4 people like this

Share this post


Link to post
Share on other sites



Thanks for sharing! Nice demonstration :thumbsup:


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

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