My program opens a window at position 0,0 in the quarter of the width of the screen. Now if a user would by chance move the window to a different position is it possible to move the window back to the position I wanted it at the start ?
I have a friend working with VB who showed me a small program where the small window appearing on the screen is 'fleeing' the mouse pointer so nobody was able to end it except using the taskmanager.
I know there are the @IDMOVE and @IDMOVING window messages IDs but how to use them in the right way ?
Thanks in advance for every help !
Richard
Hi!
GETSIZE / SETSIZE should work either.
Even SetWindowPos()
This example seems to work but i guess i forgot something as when window is moved it "flickers".
Maybe i need to redraw the window manually.
EDIT : or maybe i should use a timer and wait a few seconds before updating the window's restored position.
'DECLARE IMPORT,SetWindowPos(hwnd as UINT,hwndinsertafter as UINT,x as int,y as int,cx as int,cy as int,uFlags as UINT),INT
DEF w:WINDOW
DEF left,top,width,height:INT
'Open our window
OPENWINDOW w,0,0,640,400,@MINBOX,0,"Window test",&wndproc
MOVE w,200,150
PRINT w,"move the window from it's current position"
MOVE w,200,170
PRINT w,"and it will go back to the original one."
'Just wait for the window to be closed
run=1
WAITUNTIL run = 0
CLOSEWINDOW w
END
'Our window subroutine
SUB wndproc
SELECT @MESSAGE
CASE @IDCREATE
GETSIZE w,left,top,width,height
CASE @IDMOVE
' SetWindowPos(w.hWnd,0,left, top, -1, -1, 1 | 4 | 0x10)
' or
SETSIZE w,left,top,width,height
CASE @IDCLOSEWINDOW
run = 0
ENDSELECT
RETURN
ENDSUB
Thanks Peter,
works fine here even without flickering.
Richard
Code is updated and works now with a timer ;D
'DECLARE IMPORT,SetWindowPos(hwnd as UINT,hwndinsertafter as UINT,x as int,y as int,cx as int,cy as int,uFlags as UINT),INT
DEF w:WINDOW
DEF left,top,width,height:INT
'Open our window
OPENWINDOW w,0,0,640,400,@MINBOX,0,"Window test",&wndproc
MOVE w,200,150
PRINT w,"move the window from it's current position"
MOVE w,200,170
PRINT w,"and it will go back to the original one after 2 seconds ^^."
'Just wait for the window to be closed
run=1
WAITUNTIL run = 0
STOPTIMER w
CLOSEWINDOW w
END
'Our window subroutine
SUB wndproc
SELECT @MESSAGE
CASE @IDCREATE
GETSIZE w,left,top,width,height
CASE @IDTIMER
' SetWindowPos(w.hWnd,0,left, top, -1, -1, 1 | 4 | 0x10)
' or
SETSIZE w,left,top,width,height
CASE @IDMOVE
'If window is moved, it returns to it's original position after 2 seconds ^^
STARTTIMER w,2000
CASE @IDCLOSEWINDOW
run = 0
ENDSELECT
RETURN
ENDSUB
you need to have the timer turn itself off ;)
Larry
Hi Larry!
I'm afraid i don't understand what you mean.
Hi Larry,
in line 16 of Peter's demo you find STOPTIMER w
Richard
The way the program is written above the timer doesn't run until the window is moved
Once the window is moved the timer is turned on and after 2 secs it fires the timer message.
The timer messages resizes the window(relocates it)
2 secs later the timer message fires again and does the relocate again
2 secs later the timer message fires again.........
This goes on until the window is closed at which time the stoptimer command stops the timer.
Witj this setup the only time you are gauranteed of a 2 sec delay is the 1st time the window is moved. After that it will be randomly determined by where the timer is in it's repeating cycle when the window is moved.
I was suggesting this:
CASE @IDTIMER
SETSIZE w,left,top,width,height
stoptimer w
Larry
Thanks Larry!
That's quite well thought by the way.
I did not think about that side effect while coding it that way.
There was no "down to earth" clue that could let me think about it either.
I guess that's what makes the major gap between Seniors and ~ Juniors ;D
Thanks again Larry
Hi Larry,
I've done that before I wrote my answer to yours.
Added STOPTIMER exactly at the same place you suggested.
Thanks anyway
Richard