Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"if w" strange behavior...
#1
Hi!
Strange behavior detected...

This one works:
 
Code:
Copy      Help
if win("Notepad" "Notepad")
,act win("Notepad" "Notepad")
else
,run "$system$\notepad.exe" "" "" "" 0x200
,rep()
,,0.01
,,if win("Notepad" "Notepad")
,,,mov+ 0.5 0 0.5 1.0 win("Notepad" "Notepad") 4
,,,break


But this one doesn't:
 
Code:
Copy      Help
int w = win("Notepad" "Notepad")
if w
,act w
else
,run "$system$\notepad.exe" "" "" "" 0x200
,rep()
,,0.01
,,if w
,,,mov+ 0.5 0 0.5 1.0 w 4
,,,break

But both macros are actually the same... How is that possible?
Actually, if Notepad is already running, the second macro detects it, and activates the window (act w). But the "else" condition is never met...

And another question, is there more elegant way to wait for the window to appear than this rep()... - construction?

Thank you for your help!
#2
Hi.
This is my QM code used to it could some help.
 
Code:
Copy      Help
;;** Declare
str WindowName = ""
str Notepad = "Notepad"    ;;** CN name?
str RunEXE = "$system$\notepad.exe"

;;** Window Check_and_run Medthod
if win(WindowName Notepad) = 0
    out "Window Is0"
    run RunEXE "" "" "" 0x200    ;;** run file patch
    wait(15 WC win(WindowName Notepad))    ;;** wait Launcher to start (15 sec)

;;** Do something
out "Window IsAlive"
int w = win(WindowName Notepad)    ;;** Get value
act w    ;;** Window Action
mov+ 0.5 0 0.5 1.0 w 4    ;;** Mouse action
#3
can simplify this a lot .
This will check if notepad window exist and activate it or run it and activate it 
Function Function45
Code:
Copy      Help
int w
run "$system$\notepad.exe" "" "" "" 0x800 win("" "Notepad") w
out w
rep()
,0.01
,if w
,,mov+ 0.5 0 0.5 1.0 w 4
,,break
#4
Thank you, Kevin!
Your code works!

But my intention was different.
What i need is - if Notepad is already running, and its window is resized/moved, leave it as it is. But if it's not running - launch it, and move its window to a certain position.
So, your code simplification removes part of functionality I need.

Anyway, somehow your code works with w variable, and my code only works with full window specification, doesn't work with w.
All I need is to figure out why Smile
#5
try this

Function Function45
Code:
Copy      Help
int w
run "$system$\notepad.exe" "" "" "" 0x1800 win("" "Notepad") w
int x y cx cy
GetWinXY w x y cx cy;; gets window size and position
out F"{x},{y}, {cx},{cy}";; show size and position in qm output
if(!(x=960 and y=0 and cx=960 and cy=1040));;change these values to your wanted window size and position
,out "need to move"
,mov+ 0.5 0 0.5 1.0 w 4
,act w
else;;not needed just for example
,out "no need to move"


Forum Jump:


Users browsing this thread: 1 Guest(s)