April 20, 2024, 06:25:16 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Click anywhere on screen to close window

Started by LarryMc, May 26, 2012, 11:52:40 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

While working on the form testing portion I came up with the following.
It allows you to open a window (can also be adapted to work with a dialog) and close the window by clicking anywhere on your screen.
The left-click can be anywhere on the window itself(including any of it's controls) or anywhere outside the window.

Somebody might find a use/need for it.


DECLARE "user32.dll",SetCapture(hwnd:INT),INT
DECLARE "user32.dll",ReleaseCapture(),INT
Const WM_NCHITTEST=0x84
CONST HTCLIENT = 1
CONST WM_KILLFOCUS = 8
ENUM win_const
win_BUTTON1 = 100
ENDENUM
WINDOW win

OpenWindow win,0,0,400,300,@SIZE|@MINBOX|@MAXBOX|@NOCAPTION|@SYSMENU,0,"Form1",&win_handler
CONTROL win,@SysButton,"Button 1",98,153,60,25,0,win_BUTTON1
SetCapture(win.hwnd)
WAITUNTIL ISWINDOWCLOSED(win)
END

SUB win_handler(), INT
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW win
CASE @IDCONTROL
SELECT @CONTROLID
CASE win_BUTTON1
IF @NOTIFYCODE = 0
ENDIF
ENDSELECT
case WM_NCHITTEST
return HTCLIENT
CASE @IDCLOSEWINDOW
CASE& @IDLBUTTONUP
case& WM_KILLFOCUS
ReleaseCapture()
CLOSEWINDOW win
ENDSELECT
RETURN 0
END SUB
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library