Extended toolbars

The following toolbar option sets hook procedure:

 

 /hook functionname

 

The specified user-defined function (hook procedure) receives all messages that are sent to the toolbar's main window (not owner), starting from WM_CREATE. This allows extending QM toolbars. You, for example, can create more controls.

 

A template is available in menu -> File -> New -> Templates.

 

Toolbar hook procedure must begin with function# hWnd message wParam lParam.

 

If the hook procedure returns a nonzero value, the message is not further processed in the default window procedure. Some messages (see below) also are not processed in the default toolbar window procedure. To return 0 without further processing, declare the function as long (function% ...), and return 0x100000000.

 

To change toolbar behavior, return a nonzero value on these messages:

WM_SIZE - disable resizing the child toolbar control.

WM_EXITSIZEMOVE - disable deactivating after resize/move.

WM_MOUSEACTIVATE - disable deactivating on click.

WM_COMMAND - don't run the macro/file/command associated with the button.

Other messages that will not be processed: WM_GETMINMAXINFO, WM_NCHITTEST, WM_WINDOWPOSCHANGING, WM_SYSCOMMAND, WM_ERASEBKGND.

 

If the hook procedure executes end , it is no longer called.

 

QM 2.2.0. WM_INITDIALOG is sent when the toolbar is fully initialized, before showing. wParam is child toolbar control handle, lParam is 0, should return 0. In previous versions, WM_INITDIALOG was not sent.

 

QM 2.2.0.11. Toolbar controls are created without WS_EX_NOPARENTNOTIFY style, and therefore toolbar hook procedure receives WM_PARENTNOTIFY messages. For example, it can set font when the toolbar control is created (buttons are still not added at that time).

 

Toolbar hook procedure runs in QM main thread. Be careful when creating it, because code that runs in QM thread can easily make QM unstable. Don't use wait commands. Don't use atend. Avoid thread variables. To have variables with current toolbar scope, use SetProp, GetProp and RemoveProp functions. Example:

 

 /MyToolbar
function# hWnd message wParam lParam

type MYTOOLBARVARS a str'b ARRAY(POINT)c ;;declare type to hold multiple variables (example)
MYTOOLBARVARS* v=+GetProp(hWnd "v") ;;retrieve (required)

sel message
	case WM_INITDIALOG
	v._new; SetProp(hWnd "v" v) ;;create (required)
	v.a=1; out v.a ;;use (example)
	
	case WM_DESTROY
	v.a=3; out v.a ;;use (example)
	v._delete; RemoveProp(hWnd "v") ;;destroy (required)
	
	case WM_SETCURSOR
	v.a=2; out v.a ;;use (example)

 

There are several sample toolbars in the forum.