Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Store a value associated with a window?
#1
I currently do this by appending the window name with the string i want to keep associated to this window, but if the window name changes, I lose my value.
The value I am storing is a variable, so using GetProp or FindTaggedWindow I was unable to find the value because it varies. (previous window dimensions)
I played around a bit with global variables but didn't like it.
Is there an alternative method to store a value associated with a window(string) inside the window itself so that it is obtainable on the next run?



****
Edit: I am pretty sure i can use RegWinPos and get this to work.
****
Edit2: Code removed, contained error
#2
Function SetPropString
Code:
Copy      Help
;/
function hwnd $name $value

;Assigns a string property to the window. Or changes.
;Similar to SetProp, but SetProp assigns an integer property.


str s1.from(name "[1]*") s2
if(FindProp(hwnd s1 s2)) RemoveProp hwnd s2
s1.from(name "[1]" value)
SetProp hwnd s1 1

Function GetPropString
Code:
Copy      Help
;/
function! hwnd $name str&value

;Gets a string property assigned to the window using SetPropString.
;Similar to GetProp, but GetProp gets an integer property.
;Returns 1 if found, 0 if not.

;EXAMPLE
;int h=win("Notepad")
;SetPropString h "y" "asdfg"
;str s
;if(GetPropString(h "y" s))
,;out s


str s1.from(name "[1]*")
if(FindProp(hwnd s1 value))
,value.get(value findc(value 1)+1)
,ret 1

Function FindProp
Code:
Copy      Help
;/
function! hwnd $propw str&propFull

;Find a window property.
;In propw you specify window property name with wildcard characters, eg "ab=*".
;In propFull you receive full property name, eg "ab=cd"
;Returns 1 if found, 0 if not.
;Note: This function is not to be used with properties set by SetPropString. Use GetPropString instead.

;EXAMPLE
;int h=win("Notepad")
;SetProp h "x=qwerty" 71
;str s
;if(FindProp(h "x=*" s))
,;out s
,;out GetProp(h s)


type FINDPROPDATA $propw str*propFull
propFull.len=0
EnumPropsEx hwnd &FP_EnumProc &propw
ret propFull.len!0

Function FP_EnumProc
Code:
Copy      Help
;/
function# hwnd $lpszString hData FINDPROPDATA&x

if(lpszString<=0xffff) ret 1 ;;atom
;out lpszString
if(!matchw(lpszString x.propw 1)) ret 1
*x.propFull=lpszString

--------------------------------------------------------------

this is not needed for the above functions but may be useful somewhere else

Macro enum window props
Code:
Copy      Help
;shows what properties the window has

out
int h=win("Notepad")
EnumPropsEx h &Prop_EnumProc 0

Function Prop_EnumProc
Code:
Copy      Help
;/
function# hwnd $lpszString hData x

;used only by "enum window props" macro

if(lpszString<=0xffff) ret 1 ;;atom
out lpszString
ret 1
#3
Thanks for the functions, 1 problem.
for FINDPROPDATA, I am getting unknown identifier. It is not appearing in purple/pink. Am I missing a file?


I figured out a solution I am pretty happy with using TagWindow + RegWinPos but your solution appears to be exactly what I was previously looking for.

***
Edit: Code removed, contained error
***
#4
in Prop_EnumProc? Remove FINDPROPDATA& , i forgot it.
#5
That works, thanks!


Forum Jump:


Users browsing this thread: 1 Guest(s)