Code: Select all
t$="hello"
Title$ = "Unbenannt - Editor" ; german ;)
Title$ = "Untitled - Notepad" ; Yours
hWnd=FindWindow_(0, Title$)
If hWnd
*SetString = UTF8(t$)
Debug SetProp_(hWnd,"zzz", *SetString) ; 1
EndIf
t$=""
*GetString = GetProp_(hWnd,"zzz")
If *GetString
t$ = PeekS(*GetString, -1, #PB_UTF8|#PB_ByteLength)
FreeMemory(*GetString)
EndIf
Debug t$
Bisonte, your example doesn't work from separate sources, like mine - it crashes with an invalid memory access error for PeekS() when trying to read the prop.
So if my app quits and restarts, it won't get the prop again.
@Fred: But if I allocate memory, how will my app know about it when it restarts?
Basically, the situation is this: I want to (for example) set a property to a window that it's been "seen" by my app. In other words, my app has interacted with it at least once. Now, if my app quits and restarts and that window still exists, the new launch of my app has to be able to know that it's "seen" it before. Or, if my app quits and that window has closed, and a new window the same opens (think Calculator), then when my app restarts it has to know that it hasn't "seen" it before, because Calculator is a new window instance.
I could probably save the handles of all seen windows in a file, but this has the problem of potential clashes if a handle of a closed window matches the handle of newly-opened window; plus my app might be running from a non-writable location or slow media; or even if the user re-installs my app then the window data file will be lost.
So, props for windows seem to be the best way, since the props are attached to a specific runtime window instance and are self-deleted when the window closes. But I just can't make this work.