How to get position of TGMainFrame

I would like to save the position and size of my TGMainFrame derived application each time its run so the next time its launched, its size and position can be restored. TGFrame::GetWidth() and TGFrame::GetHeight() seem to work, but the GetX() and GetY() methods always return 0. How do I get positions that I can TGFrame::Move() to?

I’m using win32gdk 3.10/1 on win2k. Thanks


Hi Ed,

Did you try to use the methods

Cheers, Ilka

Hello Ilka,
Yes, I tried GetWMPosition(x,y) - allways returns x=y=-1.

Hi Ed,

This is likely work around but it works (at least on linux)… After using SetWMPosition(x,y) do Move(x,y) to the same position after MapWindow() of the main frame. I got correct values of x,y
and next time the application was on the same position.

Cheers, Ilka

Hi Ed, Ilka,
you can use TVirtualX::TranslateCoordinates method as follows:

Int_t x = 0;
Int_t y = 0;
Int_t fx;
Int_t fy;
Window_t ch;


(-fx,-fy) is main window position

We will add mods to TGMainFrame::GetWMPosition method.

Thanks. Regards. Valeriy

Hi Valeriy,

It is just another example that you should describe TVirtualX ASAP.

The mods of TGMainFrame might need a fix or improvement. Please follow this and the TGPopupMenu hot key problem reported by Ed too. Thank you.
I will be absent next week.

Regards, Ilka


I’d like to continue this ancient discussion. :slight_smile:
I use TVirtualX::TranslateCoordinates. But it returns wrong position. For example if TGMainFrame is created at the position (100,100), the code

will found it shifted to (fx=106,fy=126). 6 looks like the border width, and 20 looks like the height of window title.
How can I get correct window position?

And another one question. When the TGMainFrame is really painted? It is easy to calculate the shift described above:

UInt w=50,h=50;
Int_t x=100,y=100; // initial position
Int_t fx,fy;       // "translated" position of (0,0) point
Int_t dx,dy;       // shift to be found

TGMainFrame* main=new TGMainFrame(gClient->GetRoot(),w,h);

Window_t ch;
dx = -fx - x;
dy = -fy - y;

But there is a problem. TranslateCoordinates always returns (fx=0,fy=0). Why is it so? Does the window actually painted at the moment I call TranslateCoordinates?

I am using root 5.13/04.