Post by tsh73 on Nov 24, 2018 21:43:06 GMT
In continuation of thread
Moving a window... possible with Just Basic?
Moving a window... possible with Just Basic?
'get window position demo
'
'uses ritchielawrence.github.io/cmdow/
'tested under Win XP with cmdow.exe in PATH
'(actually copied in c:\windows)
'
'Do you have cmdow.exe?
'Click om window. It should move.
'Now move it by mouse (drag by window title)
'and click inside.
'It should move RELATIVE TO CURRENT POSITION
global XMAX, YMAX, ULX, DIR
'nomainwin
XMAX = 500
YMAX = 500
DIR = -1
WindowWidth = XMAX + 8
WindowHeight = YMAX + 32
UpperLeftX = (DisplayWidth - XMAX) / 2
ULX = UpperLeftX
UpperLeftY = (DisplayHeight - YMAX) / 2
open "Move Window Test - click mouse to relocate window" for graphics_nsb_nf as #gr
#gr "setfocus"
#gr "trapclose quit"
#gr "when leftButtonUp lButtonUp"
#gr "place ";190;" ";240;";|";"UpperLeftX = "+str$(ULX)
wait
'----------------------------------------
sub try2kill fileName$
on error goto [skip]
kill fileName$
[skip]
end sub
function fileExists(path$, filename$)
dim info$(0, 0)
files path$, filename$, info$()
fileExists = val(info$(0, 0)) 'non zero is true
end function
function fileNotEmpty(path$, filename$)
open path$+"\"+filename$ for input as #aFile
fileNotEmpty=(lof(#aFile)>0)
close #aFile
end function
sub pause mil
t0=time$("ms")
while time$("ms")<t0+mil
scan
wend
exit sub
[quit]
close #gr
end
end sub
sub getWinCoords title$, byRef left, byRef top
'uses ritchielawrence.github.io/cmdow/
'tested under Win XP with cmdow.exe in PATH
'(actually copied in c:\windows)
qq$=chr$(34)
fname$="res.txt"
call try2kill fname$
cmd$ = "cmd.exe /c cmdow.exe "+qq$+"Move Window Test"+qq$+"* /p /b >"+fname$
'cmd$ = "cmd.exe /k cmdow.exe "+qq$+"Move Window Test"+qq$+"* /p /b >"+fname$
'print cmd$
run cmd$, hide
call pause 300
if fileExists(DefaultDir$, fname$) then
if fileNotEmpty(DefaultDir$, fname$) then
open fname$ for input as #winInfo
line input #winInfo, aLine$
close #winInfo
left=val(word$(aLine$, 8))
top=val(word$(aLine$, 9))
print aLine$
print ,left, top
else
notice "Empty file ";fname$+chr$(13)+"is cmdow.exe exists in path?"
end if
else
notice "No file ";fname$+chr$(13)+"is cmdow.exe exists in path?"
end if
end sub
sub lButtonUp H$, mx, my 'must have handle and mouse x,y
call getWinCoords "Move Window Test", left, top
close #H$
WindowWidth = XMAX + 8
WindowHeight = YMAX + 32
'ULX = ULX + 100 * DIR
ULX = left + 100 * DIR
if ULX < 0 then DIR = DIR * -1 : ULX = 10
if ULX + XMAX > DisplayWidth then DIR = DIR * -1 : ULX = DisplayWidth - XMAX
UpperLeftX = ULX
'UpperLeftY = (DisplayHeight - YMAX) / 2
UpperLeftY = top
open "Move Window Test - click mouse to relocate window top, left corner" for graphics_nsb_nf as #gr
#gr "setfocus"
#gr "trapclose quit"
#gr "when leftButtonUp lButtonUp"
#gr "place ";190;" ";240;";|";"UpperLeftX = "+str$(ULX)
end sub
sub quit H$
close #H$
end
end sub