I solved it by making the window not hidden but size 0,0 and then paint it, and then resizing it. Seems to work.