Just a What If:
I have two buttons to click through a database - one does previous record, one does next record. Well, if you have a lot of records, it can be a bit tedious click-clicking your way through. How can I make the buttons repeat? Click once, OK - hold down, and it moves through the records until you let go
Any ideas?
Brian
Brian,
You could use my mouse over control library to detect that you are over say the 'next' button.
With that, you can then detect if the mouse button has been clicked / mouse down...
If so, you can tell the program to jump to the next record and it should keep doing that until you let go of the mouse button / or move off the button.
Andy.
Having a go now, thanks Andy
Brian
Brian,
Here's a quick demo for you - go to button 1 and click and hold the left mouse button down.
'================================
' Mouse over controls example '
'================================
'=========================================================
' You need to include this for the mouse over functions. '
' '
' You MUST place this include AFTER Windowssdk.inc '
' IF Windowssdk.inc is used. '
'=========================================================
$include "windowssdk.inc"
$include "MouseOverControls.inc"
Window win,win2
const button_1 = 1
const button_2 = 2
const button_3 = 3
const button_4 = 4
const button_5 = 5
const button_6 = 6
const button_7 = 7
const button_9 = 9
const button_11 = 11
const static_1 = 12
const radio_1 = 13
const check_1 = 14
const button_new = 20
const button_exit = 21
UInT Hbmp[7]
'=========================================================================================
'
' HOW TO, AND ORDER OF USE:
'
' WINDOW CREATION:
'
' 1. After an OPENWINDOW command use SetWindowName(win,"win") to store your window's name.
' 2. Create your controls as normal.
' 3. After you have created your controls use MouseOverControl(Mywin,Mycontrol) for each
' control you want to keep track of.
' 4. Before a WAITUNTIL command, use StartTracking(win) to start a timer.
'
' WINDOW'S HANDLER SECTION:
'
' 5. Include a CASE @IDTIMER section in your window's handler.
' 6. Then place the TrackWindow(win) command in the timer section FIRST.
' 7. You can place the mouse over controls commands after it in the timer section.
' 8. (Optional) use StopTracking(win) to stop the tracking of controls etc.
'
'=========================================================================================
OPENWINDOW win,100,100,900,500,@CAPTION|@MINBOX|@MAXBOX,0," Mouse over controls - screen 1.",&Handler
'=====================================================================
' Always store your window's name first after the OPENWIDOW command. '
' Usage: '
' SetWindowName(win,"win") '
'=====================================================================
SetWindowName(win,"win")
'================================
' Create your controls as normal.
'================================
CONTROL win,@BUTTON,"Button 1",10,200,150,25,0, button_1
CONTROL win,@BUTTON,"Button 2",10,190,150,40,0, button_2
CONTROL win,@BUTTON,"Button 3",200,200,150,25,0,button_3
CONTROL win,@BUTTON,"Button 4",200,190,150,40,0,button_4
CONTROL win,@BUTTON,"Button 5",390,200,150,25,0,button_5
CONTROL win,@BUTTON,"Button 6",390,200,150,25,0,button_6
CONTROL win,@STATIC,"Move the mouse over here, buttons 1,3,5 and other controls.",10,250,400,35,@CTEDITLEFT, STATIC_1
CONTROL win,@radiobutton,"This is a radio button",10,300,300,25,0,radio_1
CONTROL win,@checkbox,"This is a checkbox",10,350,300,25,0,check_1
CONTROL win,@BUTTON,"2nd screen",10,400,150,25,0,button_new
CONTROL win,@BUTTON,"Exit",770,400,100,25,0,button_exit
SETFONT win,"Tahoma", 8, 400, 0, button_5
showwindow win,@SWHIDE,button_2
showwindow win,@SWHIDE,button_4
showwindow win,@SWHIDE,button_6
SETCONTROLCOLOR win, static_1,RGB(0,0,0), RGB(255,255,255)
SETCONTROLCOLOR win, check_1, RGB(0,0,0), RGB(255,255,255)
SETCONTROLCOLOR win, radio_1, RGB(0,0,0), RGB(255,255,255)
'==================================================================
' Store the co-ordinates and window details of the controls '
' we want to keep track of. '
' '
' In this example I want to track mouse over for button_1,3 & 5. '
' '
' Usage: '
' MouseOverControl(Window MyWin,Int MyControl) '
'==================================================================
MouseOverControl(win,button_1)
MouseOverControl(win,button_3)
MouseOverControl(win,button_5)
MouseOverControl(win,radio_1)
MouseOverControl(win,check_1)
MouseOverControl(win,static_1)
MouseOverControl(win,button_new)
MouseOverControl(win,button_exit)
'==================================================================
' Start tracking so we can keep checking the location of the mouse.
'==================================================================
StartTracking(win)
'StartTracking(win,100) '100 = speed in miliseconds (optional)
'StartTracking(win,100,1000) '1000 = timer id (optional)
'StartTracking(win,0,1000) ' 0 = default speed (50 miliseconds), 1000 = timer id (optional)
' OR you can use the IWB timer command
'starttimer win,50
' Just some images for this example program.
Hbmp[1] = LOADIMAGE(GETSTARTPATH + "1.bmp", @IMGBITMAP)
Hbmp[2] = LOADIMAGE(GETSTARTPATH + "2.bmp", @IMGBITMAP)
Hbmp[3] = LOADIMAGE(GETSTARTPATH + "3.bmp", @IMGBITMAP)
Hbmp[4] = LOADIMAGE(GETSTARTPATH + "b1.bmp", @IMGBITMAP)
Hbmp[5] = LOADIMAGE(GETSTARTPATH + "blank.bmp", @IMGBITMAP)
Hbmp[6] = LOADIMAGE(GETSTARTPATH + "exit.bmp", @IMGBITMAP)
waituntil win=0
end
SUB Handler(),INT
select @MESSAGE
case @IDCREATE
CENTERWINDOW win
case @IDTIMER
'SELECT @CODE
'case 1000
'======================================================================
' ALWAYS use TrackWindow command FIRST! - tells you if the mouse
' is over the window BUT it also checks to see if the window
' has moved, if so it updates the controls with their new co-ordinates.
'
' YOU CAN JUST USE - TrackWindow(win) on it's own if you do not
' want to do anything whilst the mouse is over the window.
'======================================================================
if TrackWindow(win)
setcaption win,"Mouse is Over window"
SHOWIMAGE(win,Hbmp[4], @IMGBITMAP,10,10,170,170)
else
setcaption win,"Mouse is Not Over window"
SHOWIMAGE(win,Hbmp[5], @IMGBITMAP,10,10,170,170)
endif
' or just use:
' TrackWindow(win)
'
' EITHER WAY, YOU MUST USE IT FIRST!
' --------------------------------------------------------------------------
' MouseOver tells you if the mouse is over a specific control
' Returns 0 (not over), 1 (mouse is over), 2 (mouse remains over)
' MouseMovedOff tells you if the mouse is no longer over a specific control
' Returns 0 (mouse over), 1 (mouse no longer over)
' --------------------------------------------------------------------------
if MouseOver(win,static_1) = 1 'Do this one time only.
setsize win,10,250,850,35,static_1
SETFONT win,"Tahoma", 22, 400, 0, static_1
else
if MouseMovedOff(win,static_1) 'Do this one time only.
setsize win,10,250,450,25,static_1
SETFONT win,"Arial", 10, 400, 0, static_1
endif
endif
if MouseOver(win,radio_1) = 1 'Do this one time only.
SETFONT win,"Tahoma", 22, 400, 0, radio_1
else
if MouseMovedOff(win,radio_1) 'Do this one time only.
SETFONT win,"Arial", 10, 400, 0, radio_1
endif
endif
if MouseOver(win,check_1) = 1 'Do this one time only.
SETFONT win,"Tahoma", 22, 400, 0, check_1
else
if MouseMovedOff(win,check_1) 'Do this one time only.
SETFONT win,"Arial", 10, 400, 0, check_1
endif
endif
'===========================================================
' Check if the mouse is over button_1 - if so, do something.
'===========================================================
if MouseOver(win,button_1) > 0 'Keep doing this.
IF MOUSEDOWN(1)
openconsole
closeconsole
ENDIF
'showwindow win,@SWHIDE,button_1
'showwindow win,@SWRESTORE,button_2
'SHOWIMAGE(win,Hbmp[1], @IMGBITMAP,720,20,170,170)
else
if MouseMovedOff(win,button_1) 'Do this one time only.
'showwindow win,@SWHIDE,button_2
'showwindow win,@SWRESTORE,button_1
'SHOWIMAGE(win,Hbmp[5], @IMGBITMAP,720,20,170,170)
endif
endif
'===========================================================
' Check if the mouse is over button_3 - if so, do something.
'===========================================================
if MouseOver(win,button_3) > 0 'Keep doing this.
showwindow win,@SWHIDE,button_3
showwindow win,@SWRESTORE,button_4
SHOWIMAGE(win,Hbmp[2], @IMGBITMAP,720,20,170,170)
else
if MouseMovedOff(win,button_3) 'Do this one time only.
showwindow win,@SWHIDE,button_4
showwindow win,@SWRESTORE,button_3
SHOWIMAGE(win,Hbmp[5], @IMGBITMAP,720,20,170,170)
endif
endif
'===========================================================
' Check if the mouse is over button_5 - if so, do something.
'===========================================================
if MouseOver(win,button_5) > 0 'Keep doing this.
showwindow win,@SWHIDE,button_5
showwindow win,@SWRESTORE,button_6
SHOWIMAGE(win,Hbmp[3], @IMGBITMAP,720,20,170,170)
else
if MouseMovedOff(win,button_5) 'Do this one time only.
showwindow win,@SWHIDE,button_6
showwindow win,@SWRESTORE,button_5
SHOWIMAGE(win,Hbmp[5], @IMGBITMAP,720,20,170,170)
endif
endif
if MouseOver(win,button_new) = 1 'Do this one time only.
setcontroltext win,button_new,"Click me"
else
if MouseMovedOff(win,button_new) 'Do this one time only.
setcontroltext win,button_new,"2nd screen"
endif
endif
if MouseOver(win,button_exit) > 0 'Do this one time only.
setcontroltext win,button_exit,"Exit?"
SHOWIMAGE(win,Hbmp[6], @IMGBITMAP,720,20,150,150)
else
if MouseMovedOff(win,button_exit) 'Do this one time only.
setcontroltext win,button_exit,"Exit"
SHOWIMAGE(win,Hbmp[5], @IMGBITMAP,720,20,170,170)
endif
endif
' Some extra commands you can play around with...
'if WindowHasFocus(win)
'setcaption win,"1"
'else
'DeleteImages()
'end
'endif
'if WindowMinimised(win)
'DeleteImages()
'end
'endif
'if WindowMaximised(win)
'DeleteImages()
'end
'endif
'if WindowNormal(win)
'DeleteImages()
'end
'endif
if WindowMoved(win)
openconsole
closeconsole
endif
'endselect
case @IDCONTROL
SELECT @CONTROLID
case button_new 'Screen 2
if @NOTIFYCODE = 0
'--------------------------------------------
'
' Stop tracking the window and it's controls.
StopTracking(win)
'--------------------------------------------
showwindow win,@swhide
screen2()
showwindow win,@swrestore
'---------------------------------------------------
'
' Start tracking the window and it's controls again.
StartTracking(win)
'---------------------------------------------------
endif
case button_exit 'Exit
if @NOTIFYCODE = 0
CLOSEWINDOW win
DeleteImages()
end
endif
endselect
CASE @IDCLOSEWINDOW
CLOSEWINDOW win
DeleteImages()
end
endselect
return 0
ENDSUB
sub DeleteImages(),int
IF hbmp[1] THEN DELETEIMAGE hbmp[1], @IMGBITMAP
IF hbmp[2] THEN DELETEIMAGE hbmp[2], @IMGBITMAP
IF hbmp[3] THEN DELETEIMAGE hbmp[3], @IMGBITMAP
IF hbmp[4] THEN DELETEIMAGE hbmp[4], @IMGBITMAP
IF hbmp[5] THEN DELETEIMAGE hbmp[5], @IMGBITMAP
IF hbmp[6] THEN DELETEIMAGE hbmp[6], @IMGBITMAP
return 0
endsub
sub Screen2(),int
OPENWINDOW win2,100,100,900,500,@CAPTION|@MINBOX|@MAXBOX,0," Mouse over controls - screen 2.",&Handler2
'=====================================================================
' Always store your window's name first after the OPENWIDOW command. '
' Usage: '
' SetWindowName(win2,"win2") '
'=====================================================================
SetWindowName(win2,"win2")
CONTROL win2,@BUTTON,"Button 1",10,200,150,25,0,button_1
CONTROL win2,@BUTTON,"Button 9",160,200,150,25,0,button_9
CONTROL win2,@BUTTON,"Button 11",310,200,150,25,0,button_11
CONTROL win2,@BUTTON,"Close",770,400,100,25,0,button_exit
enablecontrol win2,button_1,0
enablecontrol win2,button_9,0
enablecontrol win2,button_11,0
'==================================================================
' Store the co-ordinates and window details of the controls '
' we want to keep track of. '
' '
' In this example I want to track mouse over for button_1,9 & 11. '
' '
' Usage: '
' MouseOverControl(Window MyWin,Int MyControl) '
'==================================================================
MouseOverControl(win2,button_1)
MouseOverControl(win2,button_9)
MouseOverControl(win2,button_11)
move win2,10,170
print win2,"Move the mouse over buttons 1,9 and 11."
'==================================================================
' Start tracking so we can keep checking the location of the mouse.
'==================================================================
StartTracking(win2)
'StartTracking(win2,100) '100 = speed in miliseconds (optional)
'StartTracking(win2,100,1000) '1000 = timer id (optional)
'StartTracking(win2,0,1000) '1000 = timer id (optional)
' OR you can use the IWB timer command
'starttimer win2,50
waituntil win2=0
return 0
endsub
SUB Handler2(),INT
select @MESSAGE
case @IDCREATE
CENTERWINDOW win2
case @IDTIMER
'======================================================================
' ALWAYS use TrackWindow command FIRST! - tells you if the mouse
' is over the window BUT it also checks to see if the window
' has moved, if so it updates the controls with their new co-ordinates.
'
' YOU CAN JUST USE - TrackWindow(win2) on it's own if you do not
' want to do anything whilst the mouse is over the window.
'======================================================================
if TrackWindow(win2)
setcaption win2,"Mouse is Over window 2"
else
setcaption win2,"Mouse is Not Over window 2"
endif
' TrackWindow(win2)
'===========================================================
' Check if the mouse is over button_1 - if so, do something.
'===========================================================
if MouseOver(win2,button_1) = 1
enablecontrol win2,button_1,1
else
if MouseMovedOff(win2,button_1)
enablecontrol win2,button_1,0
endif
endif
'===========================================================
' Check if the mouse is over button_9 - if so, do something.
'===========================================================
if MouseOver(win2,button_9) = 1
enablecontrol win2,button_9,1
else
if MouseMovedOff(win2,button_9)
enablecontrol win2,button_9,0
endif
endif
'===========================================================
' Check if the mouse is over button_11 - if so, do something
'===========================================================
if MouseOver(win2,button_11) = 1
enablecontrol win2,button_11,1
else
if MouseMovedOff(win2,button_11)
enablecontrol win2,button_11,0
endif
endif
case @IDCONTROL
SELECT @CONTROLID
case button_exit 'Go back to screen 1
if @NOTIFYCODE = 0
CLOSEWINDOW win2
StopTracking(win2)
return 0
endif
endselect
CASE @IDCLOSEWINDOW
CLOSEWINDOW win2
StopTracking(win2)
return 0
endselect
return 0
ENDSUB
You could even go one further - eliminate the need for clicking at all, just move to the next record by placing the mouse over the next button...
IF MouseOver(win,button_1) > 0 'Keep doing this.
IF MOUSEDOWN(1) - Remove this line....
Brian,
I have amended the control demo example to show just one button.
Try this one...
'================================
' Mouse over controls example '
'================================
'=========================================================
' You need to include this for the mouse over functions. '
' '
' You MUST place this include AFTER Windowssdk.inc '
' IF Windowssdk.inc is used. '
'=========================================================
$include "windowssdk.inc"
$include "MouseOverControls.inc"
Window win
const button_1 = 1
'=========================================================================================
'
' HOW TO, AND ORDER OF USE:
'
' WINDOW CREATION:
'
' 1. After an OPENWINDOW command use SetWindowName(win,"win") to store your window's name.
' 2. Create your controls as normal.
' 3. After you have created your controls use MouseOverControl(Mywin,Mycontrol) for each
' control you want to keep track of.
' 4. Before a WAITUNTIL command, use StartTracking(win) to start a timer.
'
' WINDOW'S HANDLER SECTION:
'
' 5. Include a CASE @IDTIMER section in your window's handler.
' 6. Then place the TrackWindow(win) command in the timer section FIRST.
' 7. You can place the mouse over controls commands after it in the timer section.
' 8. (Optional) use StopTracking(win) to stop the tracking of controls etc.
'
'=========================================================================================
OPENWINDOW win,100,100,900,500,@CAPTION|@MINBOX|@MAXBOX,0," ",&Handler
'=====================================================================
' Always store your window's name first after the OPENWIDOW command. '
' Usage: '
' SetWindowName(win,"win") '
'=====================================================================
SetWindowName(win,"win")
'================================
' Create your controls as normal.
'================================
CONTROL win,@BUTTON,"Button 1",10,200,150,25,0, button_1
SETFONT win,"Tahoma", 8, 400, 0, button_1
'==================================================================
' Store the co-ordinates and window details of the controls '
' we want to keep track of. '
' '
' In this example I want to track mouse over for button_1,3 & 5. '
' '
' Usage: '
' MouseOverControl(Window MyWin,Int MyControl) '
'==================================================================
MouseOverControl(win,button_1)
'==================================================================
' Start tracking so we can keep checking the location of the mouse.
'==================================================================
StartTracking(win)
waituntil win=0
end
SUB Handler(),INT
select @MESSAGE
case @IDCREATE
CENTERWINDOW win
case @IDTIMER
'======================================================================
' ALWAYS use TrackWindow command FIRST! - tells you if the mouse
' is over the window BUT it also checks to see if the window
' has moved, if so it updates the controls with their new co-ordinates.
'
' YOU CAN JUST USE - TrackWindow(win) on it's own if you do not
' want to do anything whilst the mouse is over the window.
'======================================================================
if TrackWindow(win)
setcaption win,"Mouse is Over window" ' Your window caption
else
setcaption win,"Mouse is Over window"
endif
' EITHER WAY, YOU MUST USE IT FIRST!
' --------------------------------------------------------------------------
' MouseOver tells you if the mouse is over a specific control
' Returns 0 (not over), 1 (mouse is over), 2 (mouse remains over)
' MouseMovedOff tells you if the mouse is no longer over a specific control
' Returns 0 (mouse over), 1 (mouse no longer over)
' --------------------------------------------------------------------------
'===========================================================
' Check if the mouse is over button_1 - if so, do something.
'===========================================================
if MouseOver(win,button_1) > 0 'Keep doing this.
IF MOUSEDOWN(1)
openconsole
closeconsole
ENDIF
endif
CASE @IDCLOSEWINDOW
StopTracking(win)
CLOSEWINDOW win
end
endselect
return 0
ENDSUB
Andy,
Well, it does work, but it is slow, and I have also another task in the @IDTIMER section that it has to do at the same time. I will keep testing...
Also, because I am not using all of your code, when it compiles it is saying that these SUBs are missing:
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (334) Warning: Unreferenced SUB CreateButton
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (552) Warning: Unreferenced SUB WindowMinimized
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (615) Warning: Unreferenced SUB StopTracking
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (570) Warning: Unreferenced SUB WindowMaximized
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (466) Warning: Unreferenced SUB MouseOverWhichType
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (195) Warning: Unreferenced SUB MouseMovedOff
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (416) Warning: Unreferenced SUB MouseOverAnyControl
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (373) Warning: Unreferenced SUB MouseOverControlType
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (316) Warning: Unreferenced SUB DeleteControl
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (360) Warning: Unreferenced SUB CreateRadio
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (543) Warning: Unreferenced SUB WindowMinimised
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (532) Warning: Unreferenced SUB WindowHasFocus
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (579) Warning: Unreferenced SUB WindowNormal
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (561) Warning: Unreferenced SUB WindowMaximised
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (347) Warning: Unreferenced SUB CreateCheckBox
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (590) Warning: Unreferenced SUB WindowMoved
File: C:\Program Files (x86)\iwbdev\include\MouseOverControls.inc (499) Warning: Unreferenced SUB MouseOverCaption
I obviously don't need all of them
Brian
Quote from: Brian Pugh on June 20, 2017, 04:30:23 AM
Just a What If:
I have two buttons to click through a database - one does previous record, one does next record. Well, if you have a lot of records, it can be a bit tedious click-clicking your way through. How can I make the buttons repeat? Click once, OK - hold down, and it moves through the records until you let go
Any ideas?
Brian
When I started to do all the antenna dimension calculators, I had the same dilemma. I started out by using the mouse and a timer, but very soon found this rather ackward to use. Instead I endeed up using the arrow keys and PageUp/PageDown keys to adjust the frequencies. Much simpler, and gave me better control. The code below is for CB, but no change is needed to use with IWB.
Egil
CASE @IDKEYDOWN
if GETKEYSTATE(0x21) <> 0 then fq=fq+10 :' PG UP pressed
if GETKEYSTATE(0x22) <> 0 then fq=fq-10 :' PG DOWN pressed
if GETKEYSTATE(0x25) <> 0 then fq=fq-0.1 :' LEFT ARROW pressed
if GETKEYSTATE(0x26) <> 0 then fq=fq+1 :' UP ARROW pressed
if GETKEYSTATE(0x27) <> 0 then fq=fq+0.1 :' RIGHT ARROW pressed
if GETKEYSTATE(0x28) <> 0 then fq=fq-1 :' DOWN ARROW pressed
Brian,
Just ignore the unreferenced subs.
As far as timing is concerned, it's probably down to the db code getting the next record, as something simple as opening / closeing say a console is quick.
Maybe you could try timing how long it takes the db code to get the next record?
@Brian
You mentioned you were already using @IDTIMER for something else. You can use @IDTIMER for as many different timer functions as you want.
All you have to do is assign your timers unique numbers when you start them with the id - Optional timer id, defaults to 1.
STARTTIMER win, 1000, 456
STARTTIMER win,100,778
Then in your @IDTIMER section set it up like this
case @IDTIMER
SELECT @CODE
CASE 456 ' your 1st timer
CASE 778 ' your next timer
END SELECT
Larry,
You beat me to it!
Larry, I like it!
Brian