[HELP]Why PtWindowToFront doesn't work?

I try to switch between two overlapped windows(window1,window2) in my
program.
So a callback of a button in window1 will switch window2 to front and a
callback of a button in window2 will switch window1 to front.
By the way ,I have set window state of two windows as Ph_WM_STATE_ISFRONT.
The switching part of my program is like this:
//window2 button’s callback function
PtWindowToFront(ABW_window1);
PtFlush();
//window1 button’s callback function
PtWindowToFront(ABW_window2);
PtFlush();
But each window can’t switch to the other.What’s the problem?
Eagerly waiting for your help! Thanks a lot!

On Sat, 09 Apr 2005 13:11:42 +0000, johnsonyoung
<johnsonyoung2002@yahoo.com.cn> wrote:

I try to switch between two overlapped windows(window1,window2) in my
program.
So a callback of a button in window1 will switch window2 to front and a
callback of a button in window2 will switch window1 to front.
By the way ,I have set window state of two windows as
Ph_WM_STATE_ISFRONT.
The switching part of my program is like this:
//window2 button’s callback function
PtWindowToFront(ABW_window1);
PtFlush();
//window1 button’s callback function
PtWindowToFront(ABW_window2);
PtFlush();
But each window can’t switch to the other.What’s the problem?
Eagerly waiting for your help! Thanks a lot!

Maybe you are trying to put a window in front of the base window?
If so:
Try 3 windows, 1 base, and 2 child windows.
Do the switching with the two child windows.

The other problem could be that clicking on a window will
keep focus on that window so the WindowToFront is ignored.
Try PtUnrealizeWidget() / PtRealizeWidget instead.

//window2 button’s callback function
PtUnrealizeWidget(ABW_window2);
PtRealizeWidget(ABW_window1);

//window1 button’s callback function
PtUnrealizeWidget(ABW_window1);
PtRealizeWidget(ABW_window2);

\

Using Opera’s revolutionary e-mail client: http://www.opera.com/m2/

“Alex/Systems 104” <acellarius@yah0o.lsd.com> wrote in message
news:opsoyt2ysbbinb6v@alex-pentium-m…

On Sat, 09 Apr 2005 13:11:42 +0000, johnsonyoung
johnsonyoung2002@yahoo.com.cn> > wrote:
I try to switch between two overlapped windows(window1,window2) in my
program.
So a callback of a button in window1 will switch window2 to front and a
callback of a button in window2 will switch window1 to front.
By the way ,I have set window state of two windows as
Ph_WM_STATE_ISFRONT.
The switching part of my program is like this:
//window2 button’s callback function
PtWindowToFront(ABW_window1);
PtFlush();

You don’t need the PtFlush() calls here.

But each window can’t switch to the other.What’s the problem?
Eagerly waiting for your help! Thanks a lot!
Maybe you are trying to put a window in front of the base window?
If so:
Try 3 windows, 1 base, and 2 child windows.
Do the switching with the two child windows.

It can work with two windows, but you need to make sure that they’re
siblings. You can’t put a child window behind its parent.

By default, all the PhAB windows you create become children of the base
window, but you can use ApModuleParent() to create a second window that
doesn’t have a parent.

The other problem could be that clicking on a window will
keep focus on that window so the WindowToFront is ignored.

It’s true that there’s a bit of a race condition there, but it shouldn’t be
a problem. When your app receives the click, another copy of the event has
already been put in the window manager’s event queue. Since your ToFront
request has to go through the same queue, there’s no way pwm can see it
before the click.

Try PtUnrealizeWidget() / PtRealizeWidget instead.
//window2 button’s callback function
PtUnrealizeWidget(ABW_window2);
PtRealizeWidget(ABW_window1);

That’s another good way of doing it. But I’d realize the new window before
unrealizing the old – otherwise, the backdrop behind the windows gets a
chance to draw through and cause unnecessary flicker.

Yet another way would be to mimimize the window instead of unrealizing it.
If any widgets in the window need to have regions, unrealizing the window
destroys all those regions, and creating them again when you realize the
window requires a message to Photon per region. Minimizing just moves the
whole family of regions behind the backdrop, and unminimizing just moves it
back.

Wojtek Lerch wrote:

“Alex/Systems 104” <> acellarius@yah0o.lsd.com> > wrote in message
news:opsoyt2ysbbinb6v@alex-pentium-m…

On Sat, 09 Apr 2005 13:11:42 +0000, johnsonyoung
johnsonyoung2002@yahoo.com.cn> > wrote:

I try to switch between two overlapped windows(window1,window2) in my
program.
So a callback of a button in window1 will switch window2 to front and a
callback of a button in window2 will switch window1 to front.
By the way ,I have set window state of two windows as
Ph_WM_STATE_ISFRONT.
The switching part of my program is like this:
//window2 button’s callback function
PtWindowToFront(ABW_window1);
PtFlush();


You don’t need the PtFlush() calls here.


But each window can’t switch to the other.What’s the problem?
Eagerly waiting for your help! Thanks a lot!

Maybe you are trying to put a window in front of the base window?
If so:
Try 3 windows, 1 base, and 2 child windows.
Do the switching with the two child windows.


It can work with two windows, but you need to make sure that they’re
siblings. You can’t put a child window behind its parent.

By default, all the PhAB windows you create become children of the base
window, but you can use ApModuleParent() to create a second window that
doesn’t have a parent.


The other problem could be that clicking on a window will
keep focus on that window so the WindowToFront is ignored.


It’s true that there’s a bit of a race condition there, but it shouldn’t be
a problem. When your app receives the click, another copy of the event has
already been put in the window manager’s event queue. Since your ToFront
request has to go through the same queue, there’s no way pwm can see it
before the click.


Try PtUnrealizeWidget() / PtRealizeWidget instead.
//window2 button’s callback function
PtUnrealizeWidget(ABW_window2);
PtRealizeWidget(ABW_window1);


That’s another good way of doing it. But I’d realize the new window before
unrealizing the old – otherwise, the backdrop behind the windows gets a
chance to draw through and cause unnecessary flicker.

Yet another way would be to mimimize the window instead of unrealizing it.
If any widgets in the window need to have regions, unrealizing the window
destroys all those regions, and creating them again when you realize the
window requires a message to Photon per region. Minimizing just moves the
whole family of regions behind the backdrop, and unminimizing just moves it
back.
\

Thank a lot for both of you. In fact, these two windows are siblings and
they have same size,same location and have no minimize or maxmize flags.
When I click switch button on each of them, I should switch to the other
window. But PtWindowToFront doesn’t work in both of the two button’s
callback functions. I also try to use PtForwardWindowEvent which neither
work.
Now PtUnrealizeWidget and PtRealizeWidget works well.
Thanks again!

“johnsonyoung” <johnsonyoung2002@yahoo.com.cn> wrote in message
news:4258F617.6090608@yahoo.com.cn

Thank a lot for both of you. In fact, these two windows are siblings and
they have same size,same location and have no minimize or maxmize flags.

What do you mean by “no minimize or maximize flags”? Maybe that’s why it
doesn’t work? With all the flags set to their default, both
PtWindowToFront() and minimizing works for me.

When I click switch button on each of them, I should switch to the other
window. But PtWindowToFront doesn’t work in both of the two button’s
callback functions. I also try to use PtForwardWindowEvent which neither
work.

This works for me:

PhWindowEvent_t wev = { 0 };
wev.event_f = Ph_WM_HIDE;
wev.rid = PtWidgetRid( window );
wev.event_state = mini ? Ph_WM_EVSTATE_HIDE : Ph_WM_EVSTATE_UNHIDE;
PtForwardWindowEvent( &wev );

And so does this:

PtSetResource( window, Pt_ARG_WINDOW_STATE, mini ? ~0u : 0u,
Ph_WM_STATE_ISHIDDEN );

Now PtUnrealizeWidget and PtRealizeWidget works well.

But it’s the least efficient of the three methods.

BTW Another thing worth trying is two overlapping containers in the same
window.

Thanks for your kindly help. Maybe you’re puzzled by my poor english.
Could I send you my simple PHOTON project to illustrate that problem
more clearly?
kinWojtek Lerch wrote:

What do you mean by “no minimize or maximize flags”? Maybe that’s why it
doesn’t work? With all the flags set to their default, both
PtWindowToFront() and minimizing works for me.

No matter whether these flags are set or cleared or default,

PtWindowToFront doesn’t work in my project.


This works for me:

PhWindowEvent_t wev = { 0 };
wev.event_f = Ph_WM_HIDE;
wev.rid = PtWidgetRid( window );
wev.event_state = mini ? Ph_WM_EVSTATE_HIDE : Ph_WM_EVSTATE_UNHIDE;
PtForwardWindowEvent( &wev );

And so does this:

PtSetResource( window, Pt_ARG_WINDOW_STATE, mini ? ~0u : 0u,
Ph_WM_STATE_ISHIDDEN );


In fact, I don’t want to show the minimized window. The function of my

program is something like switching window in WINDOWS by pressing
“Alt+Tab”. So my code is as followed but doesn’t works:


Now PtUnrealizeWidget and PtRealizeWidget works well.


But it’s the least efficient of the three methods.

BTW Another thing worth trying is two overlapping containers in the same
window.
That’s the point why I try PtWindowToFront. All I want is just switching

between two overlapped windows. But maybe I’m too clumsy to master
the usage of this function and feel so confused.
Thank you so much once again!

johnsonyoung wrote:

Thanks for your kindly help. Maybe you’re puzzled by my poor english.
Could I send you my simple PHOTON project to illustrate that problem
more clearly?

That sounds like a good idea.