# DocumentWindow getWindowStateAsString()

**URL:** <https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216>\
**Category:** General JUCE discussion\
**Created:** [January 17, 2011, 2:50pm UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216 "2011-01-17T14:50:18Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [January 17, 2011, 2:50pm UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/1 "2011-01-17T14:50:18Z")

</div>

I save my window state with this, and i restore it. As long as the window is not maximized (using the maximize button and using the native titlebar) i can use the restoreWindowStateFromString, but once i have the window maximised, then exit and then re-launch and do restoreWindowStateFromString the window moves to high, the native titlebar is off the screen on the top. This is the string that gets saved and is used for restoring

> [@](#):
>
> fs 0 30 1680 1010

i don’t know if “fs” means fullscreen, but if that’s the case maximized does not mean fullscreen, theese are two different things.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 17, 2011, 9:47pm UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/2 "2011-01-17T21:47:17Z")

</div>

Is this windows, mac? Does your window use a native title bar?

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [January 17, 2011, 10:30pm UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/3 "2011-01-17T22:30:56Z")

</div>

no it’s windows7 x64 and yes using native titlebar.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 18, 2011, 7:35pm UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/4 "2011-01-18T19:35:42Z")

</div>

Well, I just tried this in the juce demo:

[code] void initialise (const String& /_commandLine_/)  
{  
#if JUCE\_IPHONE  
theMainWindow.setVisible (true);  
theMainWindow.setFullScreen (true);  
#else  
// theMainWindow.centreWithSize (700, 600);

```
    theMainWindow.setUsingNativeTitleBar (true);
    theMainWindow.restoreWindowStateFromString ("fs 0 30 1680 1010");
    theMainWindow.setVisible (true);
  #endif[/code]

```

and it seemed to do the right thing to me. Can you give me some code that reproduces the problem?

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [January 19, 2011, 8:45am UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/5 "2011-01-19T08:45:26Z")

</div>

i use that in a standalone wrapper for plugins

in the ctor of the main document window

```auto
JUCE_TRY
    {
        filter = createPluginFilter();

        if (filter != 0)
        {
            filter->setPlayConfigDetails (2, 2, 44100, 512);
			MemoryBlock data = GETM(Config::Global, T("filterState"));
            filter->setStateInformation (data.getData(), data.getSize());
                
			setContentComponent (filter->createEditorIfNeeded(), true, true);

			if (GETS(Config::Windows, getName()) != String::empty)
			{
				L(GETS(Config::Windows, getName()));
				restoreWindowStateFromString (GETS(Config::Windows, getName()));
			}
			else
			{
				centreWithSize (600,600);
			}
        }
    }
```

this prints to the log if the last state was a maximized window

```auto
fs 418 208 844 645
```

in the destructor

```auto
if (filter != 0)
    {
        MemoryBlock data;
        filter->getStateInformation (data);
		SET (Config::Global, "filterState", data);
		SET (Config::Windows, getName(), getWindowStateAsString());
		L(getWindowStateAsString());
	}
    deleteFilter();
```

the result is a window that looks like this (this is the full screenshot from the screen nothing is cut, you will see what’s wrong) [http://bayimg.com/FaDaMaadG](http://bayimg.com/FaDaMaadG)

the weird thing is when i click on the taskbar button 3time (bring it to front bring it to back then bring it to front again), it comes back as a normal window the titlebar is visible, however it’s not maximized like so [http://bayimg.com/FADaOAADG](http://bayimg.com/FADaOAADG)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 19, 2011, 11:15am UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/6 "2011-01-19T11:15:40Z")

</div>

It looks to me like the window hasn’t got a native titlebar at the time when you restore its size… Perhaps you’re calling setUsesNativeTitlebar (true) after you’ve already restored its size?

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [January 19, 2011, 12:36pm UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/7 "2011-01-19T12:36:36Z")

</div>

i tried both, before and after, same result

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 19, 2011, 12:48pm UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/8 "2011-01-19T12:48:41Z")

</div>

Maybe give me some code I can apply to the demo app that reproduces this… I can’t see what you’re doing that would make it go wrong.

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [January 19, 2011, 1:17pm UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/9 "2011-01-19T13:17:54Z")

</div>

well it’s a bit my fault but not all, i was working around the issue where when you start a juce application with a native titlebar it does not go to front on start you need to click it  
so i was creating the window, restoring it from the string but after that setting it visible and adding it to desktop.

```auto
MyWindow::MyWindow : DocumentWindow (title, backgroundColour, DocumentWindow::allButtons, false)
```

if i do it the normal way it works.

```auto
MyWindow::MyWindow : DocumentWindow (title, backgroundColour, DocumentWindow::allButtons, true)
```

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 19, 2011, 5:44pm UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/10 "2011-01-19T17:44:37Z")

</div>

Ah, right. Because until it’s actually on the screen and visible, it can’t have a native title bar, so the resizing won’t be able to take that into account when positioning it.

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [February 15, 2011, 10:06pm UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/11 "2011-02-15T22:06:52Z")

</div>

i noticed that when i maximize the window on the second monitor, when i restore it, it’s moved to the primary monitor (the size is saved).

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [February 16, 2011, 9:13am UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/12 "2011-02-16T09:13:37Z")

</div>

ok… never noticed that before, I’ll have a go.

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [February 17, 2011, 10:11pm UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/13 "2011-02-17T22:11:51Z")

</div>

it’s weird (i’m at the tip) if a window is stretched over two monitors (starts at one ends at the other) once it closed and the re-opened, it’s move to the monitor that it occupies the most (if it’s mostly on the left one after the restore it’s only on the left one and the other way around).

i think it’s important to say i’m on windows7 with NVidia drivers, i know that ATI does it’s multi monitor thing in some different way on XP don’t know how it’s done on Vista/7

aaand 🙂 it’s even more important to say i have 3 graphics cards, one disabled (Matrox internal onboard), and two NVidia geforce’s each monitor is connected to a different card.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [February 18, 2011, 9:20am UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/14 "2011-02-18T09:20:06Z")

</div>

That doesn’t sound particularly strange, because when it makes it full-screen, it just makes it fill the monitor that contains the centre point of the component.

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [February 18, 2011, 10:20am UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/15 "2011-02-18T10:20:37Z")

</div>

yes but it’s not fullscreem, here are two screens before and after.  
 ![](http://www.fujitsu-ts.tk/incoming/before.gif)  
 ![](http://www.fujitsu-ts.tk/incoming/after.gif)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [February 18, 2011, 10:45am UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/16 "2011-02-18T10:45:43Z")

</div>

Ok… I’ll have a look, though I run Win7 in a VM so not sure if I’ll be able to reproduce that myself.

---

<div class="post-metadata">

**Author:** ![atom](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/atom/32/113_2.png) [@atom](https://forum.juce.com/u/atom)\
**Post date:** [February 18, 2011, 10:51am UTC](https://forum.juce.com/t/documentwindow-getwindowstateasstring/6216/17 "2011-02-18T10:51:23Z")

</div>

i think vmware has multiple display support, don’t know about parallels or virtualbox.
