[SOLVED] Problems with WinSet/WinGet within Property

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

[SOLVED] Problems with WinSet/WinGet within Property

29 Sep 2014, 07:36

I'm currently playing around with Properties (AHK 1.1.16.05) and WinSet/WinGet, running following script:

Code: Select all

; Create a Testwindow ...
Run, notepad.exe
WinWait, ahk_class Notepad, , 2
WinMove, ahk_class Notepad,, 10, 10, 300, 300
OutputDebug % "*********************** WINDOW CREATED *******************"
hWnd := WinExist("ahk_class Notepad")
tw := new TestIt(hwnd)
sleep 1000
OutputDebug % "*********************** CAPTION OFF **********************"
tw.style := "-0x00C00000"  ; Remove the active window's title bar (WS_CAPTION).
sleep 1000
OutputDebug % "*********************** CAPTION ON ***********************"
tw.style := "+0x00C00000"  ; Re-Add the active window's title bar (WS_CAPTION).
sleep 1000
OutputDebug % "*********************** DONE *****************************"
ExitApp

class TestIt {
	style[] {
		get {
			hWnd := this._hwnd
			WinGet, st, Style, ahk_id %hwnd%
			OutputDebug % "|[" A_ThisFunc "([" this._hwnd "])] -> (" st ")"
			return st
		}
		set {
			hwnd := this._hwnd
			WinGet, st, Style, ahk_id %hwnd%
			OutputDebug % "...[" A_ThisFunc "([" this._hwnd "], style=" value ")] -> style BEFORE: " st
			WinSet, Style, value, ahk_id %hwnd%
			sleep 500
			WinGet, st2, Style, ahk_id %hwnd%
			OutputDebug % "...[" A_ThisFunc "([" this._hwnd "], style=" value ")] -> style AFTER: "  st2
			return value
		}
	}
	__New(_hWnd) {
		this._hWnd := _hWnd
		return this
	}	
}
The sourcecode above produces following output:
001 [9924] *********************** WINDOW CREATED *******************
002 [9924] *********************** CAPTION OFF **********************
003 [9924] ...[TestIt.style.set([0x1290d82], style=-0x00C00000)] -> style BEFORE: 0x14CF0000
004 [9924] ...[TestIt.style.set([0x1290d82], style=-0x00C00000)] -> style AFTER:
005 [9924] *********************** CAPTION ON ***********************
006 [9924] ...[TestIt.style.set([0x1290d82], style=+0x00C00000)] -> style BEFORE:
007 [9924] ...[TestIt.style.set([0x1290d82], style=+0x00C00000)] -> style AFTER:
008 [9924] *********************** DONE *****************************
I try to remove and re-add the caption bar via property implementation unsing WinSet/WinGet.

Removing the caption bar works - but it isn't re-added again. Looking at the debug output (line 004) shows, that getting the window-style via WinGet after WinSet fails within my implementation ... and the style cannot retrieved via WinGet anymore (lines 006-007)

What's going wrong?
Last edited by hoppfrosch on 29 Sep 2014, 08:12, edited 2 times in total.
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: Problems with WinSet/WinGet

29 Sep 2014, 07:39

BtW:

Code: Select all

hwnd := this._hwnd
WinGet, st, Style, ahk_id %hwnd%
Is it possible to avoid the temporary variable hwnd and use this._hwnd directly within WinGet?
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
Contact:

Re: Problems with WinSet/WinGet within Property

29 Sep 2014, 07:59

value should be %value% in this line: WinSet, Style, value, ahk_id %hwnd%
Is it possible to avoid the temporary variable hwnd and use this._hwnd directly within WinGet?
Yes you can avoid the temporary variable by forcing an expression, e.g.: WinShow % "ahk_id " this._hwnd.
AHK Docs wrote:Force an expression: An expression can be used in a parameter that does not directly support it (except an OutputVar or InputVar parameter such as those of StringLen) by preceding the expression with a percent sign and a space or tab. This technique is often used to access arrays.
Last edited by Coco on 29 Sep 2014, 08:13, edited 1 time in total.
User avatar
hoppfrosch
Posts: 443
Joined: 07 Oct 2013, 04:05
Location: Rhine-Maine-Area, Hesse, Germany
Contact:

Re: Problems with WinSet/WinGet within Property

29 Sep 2014, 08:08

I always assumed to be a noob - there's the official confirmation .... :headwall:

Oh man - how do I hate the expression confusion! :crazy:

Thanks a lot Coco!
Last edited by hoppfrosch on 29 Sep 2014, 08:28, edited 1 time in total.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: wilkster and 332 guests