May 16, 2024, 08:40:59 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Disable/enable mouse ?

Started by paja, January 15, 2011, 09:57:07 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

paja

January 15, 2011, 09:57:07 AM Last Edit: January 15, 2011, 10:02:48 AM by paja
Hi,

How can I disable/enable mouse control - left and right buttons  ?

LarryMc

If you disabled the mouse clicks I'm not sure how you would enable them again other than with a timer.

I don't know exactly how but if I need to do it this is what I would try. I didn't find a simple command I could use but there still may be one in the api.

create a dummy window off screen so it can't be seen like openwindow dwin,-1000,-1000,0,0,blah.....
remember it will need a handler

then when ever I wanted to kill the mouse in my regular window I would use setcaputure api to let the dummy win capture all the mouse clicks and I would also start a timer

when the timer timed out I would use the releasecapture api to go back to normal.

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

LarryMc

If you don't have too many controls this will work.
create a global flag say int mydisable=0

when ever you want to disable button click set mydisable=1

in your handler, say for a button, use this:
CASE @IDCONTROL
   SELECT @CONTROLID
      CASE 3
         if @notifycode=0
            if mydisable then return 0
            showwindow #<WINDOW>@HITWINDOW,@swhide,3
         endif

that way you can select which controls you want to quit responding.

I guess it is hard to offer any other suggestions without knowing why you want to disable mouse clicks.

LarryMc

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

paja

I need use mouse disable and the enable in program - here is a part for demonstration.

In the loop I test serial line. It works OK.
But when I use left mouse button then the program will crash.
I means to use disable mouse before this part of program and then enable mouse.

autodefine "off"
$INCLUDE "windowssdk.inc"
$INCLUDE "winsock2.inc"

DEF w90:window
def command:INT

OPENWINDOW W90,0,0,500,500,@MAXIMIZED|@NOCAPTION|@BORDER|@TOPMOST,0,"",&w90_handler
Setwindowcolor w90,RGB(0,0,0)
ShowCursor(0)

DRAWMODE w90,@TRANSPARENT
frontpen w90,RGB(255,0,0)

move w90,200,250
SETFONT w90,"Venus Rising",50,1
PRINT w90,"Emergency Status"

command = 128

WHILE command = 128

rem ReadFile(hCom_1,data_avr,3,BytesRead_2,0)
rem command =  ASC(left$(data_avr,1))

WEND

CLOSEWINDOW w90
END

' *******************************************************
' NOT AUS 
' *******************************************************
SUB w90_handler

SELECT @MESSAGE

CASE @IDCLOSEWINDOW

CASE @IDKEYDOWN

CASE @IDLBUTTONDN

CASE @IDCONTROL

CASE @IDLBUTTONDBLCLK

ENDSELECT

RETURN
ENDSUB


LarryMc

January 15, 2011, 03:19:54 PM #4 Last Edit: January 15, 2011, 03:22:57 PM by Larry McCaughn
See if this works for you; I can't test it.

autodefine "off"
$INCLUDE "windowssdk.inc"
$INCLUDE "winsock2.inc"

window w90,dummy
int command

OPENWINDOW W90,0,0,500,500,@MAXIMIZED|@NOCAPTION|@BORDER|@TOPMOST,0,"",&w90_handler
OPENWINDOW dummy,-1000,-1000,50,50,0,w90,"",&dummy_handler
Setwindowcolor w90,RGB(0,0,0)
ShowCursor(0)

DRAWMODE w90,@TRANSPARENT
frontpen w90,RGB(255,0,0)

move w90,200,250
SETFONT w90,"Venus Rising",50,1
PRINT w90,"Emergency Status"

command = 128

SetCapture(dummy.hwnd)
WHILE command = 128

rem ReadFile(hCom_1,data_avr,3,BytesRead_2,0)
rem command =  ASC(left$(data_avr,1))
WEND
ReleaseCapture()

CLOSEWINDOW dummy
CLOSEWINDOW w90
END

' *******************************************************
' NOT AUS  
' *******************************************************
SUB w90_handler

SELECT @MESSAGE

CASE @IDCLOSEWINDOW

CASE @IDKEYDOWN

CASE @IDLBUTTONDN

CASE @IDCONTROL

CASE @IDLBUTTONDBLCLK

ENDSELECT

RETURN
ENDSUB

SUB dummy_handler

SELECT @MESSAGE

ENDSELECT

RETURN
ENDSUB


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

paja


LarryMc

Just grabbing at straws. Try this.
You know, Sapero will probably post 2 lines of code that does it and make me look like an idiot again!!  ;) ;)
autodefine "off"
$INCLUDE "windowssdk.inc"
$INCLUDE "winsock2.inc"

window w90,dummy
int command

OPENWINDOW W90,0,0,500,500,@MAXIMIZED|@NOCAPTION|@BORDER|@TOPMOST,0,"",&w90_handler
OPENWINDOW dummy,-1000,-1000,50,50,0,w90,"",&dummy_handler
Setwindowcolor w90,RGB(0,0,0)
ShowCursor(0)

DRAWMODE w90,@TRANSPARENT
frontpen w90,RGB(255,0,0)

move w90,200,250
SETFONT w90,"Venus Rising",50,1
PRINT w90,"Emergency Status"

command = 128
int killmouse=1
SetCapture(dummy.hwnd)
WHILE command = 128

rem ReadFile(hCom_1,data_avr,3,BytesRead_2,0)
rem command =  ASC(left$(data_avr,1))
ReleaseCapture()
killmouse=0
WEND
CLOSEWINDOW dummy
CLOSEWINDOW w90
END

' *******************************************************
' NOT AUS 
' *******************************************************
SUB w90_handler

SELECT @MESSAGE

CASE @IDCLOSEWINDOW

CASE @IDKEYDOWN
if killmouse then return 1

CASE @IDLBUTTONDN
if killmouse then return 1
CASE @IDCONTROL
if killmouse then return 1
CASE @IDLBUTTONDBLCLK
if killmouse then return 1
ENDSELECT

RETURN
ENDSUB

SUB dummy_handler

SELECT @MESSAGE

ENDSELECT

RETURN
ENDSUB

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

Paja, I think your program is not crashing, but does not respond to user input, so the system opens the "hung app" box to wait or terminate.
You can:
1. Add WAIT TRUE to the WHILE loop
WHILE (command = 128) and w90.hWnd

WAIT TRUE
if (ReadFile(hCom_1,data_avr,3,BytesRead_2,0) and BytesRead_2)
data_avr[BytesRead_2] = 0 ' cut off invalid data; data_avr must be at least 3+1 bytes!
command =  ASC(left$(data_avr,1))
endif

WEND


2. Do not open windows before waiting for slow devices, or at least disable the window.
3. Move the loop to separate thread (CreateThread)
4. (advanced) Open the port in overlapped mode, and use ReadFileEx (thread must be in alertable state), or call RegisterWaitForSingleObject to install a callback function for the event passed to OVERLAPPED structure, and use ReadFile with a pointer to OVERLAPPED.

paja

Sapero,

Only WAIT helps enough !

Thanks

sapero

Don't forget to call SetCommTimeouts with read-timeout up to the HungAppTimeout value from HKEY_CURRENT_USER\Control Panel\Desktop (if missing, read it from HKEY_USERS\.DEFAULT\Control Panel\Desktop). A small timeout - 1,2,3 seconds can be assumed.