Click to See Complete Forum and Search --> : Can a normal window pop up from a dialogbox?


jeffreygoines
January 18th, 2008, 07:59 AM
hi i'm tyring to create a dialogbox-based application that pops up another window.

I know a modeless dialogbox can pop up from a overlapped/popup window and succeeded before.

What i'm trying to do now is the reverse.

The design is like this:

When some button on the dialogbox is pressed, following will be executed:

onButton() {
CreateWindowEx(...)
ShowWindow(hWnd);
}

but this doesn't work. The "normal" window i want to pop up
just disappears in a moment...like 0.1s?

The strange thing is, when

CreateWindowEx();

is executed in WinMain(), before clicking on the button,
and only the following is executed on clicking the button,

ShowWindow(hWnd);

the window does appear.

But i cannot use the second method because in the actual code
the number of windows to pop up is not given in compile time.
So the CreateWindowEx() must be called after button-clicking.

What i want to know is if this behavior of dialogbox is normal.
I guess some messages to the normal window are interrupted by the dialogbox

eero_p
January 18th, 2008, 08:28 AM
Likely HWND returned by CreateWindowEx goes out of scope -> dialog disappears.

Having that HWND as member variable should fix the situation if the reason is what I suspected.

jeffreygoines
January 18th, 2008, 09:03 AM
finally fixed the code...and the problem was the wrapper class for window/dialogbox
onButton() {
Window wnd;
wnd.create();
wnd.show();
// wnd is destroyed at this point.
}
Because ~Window() contained the following code, the window object was destroyed:
~Window() { DestroyWindow(hWNd);}

To avoid this, i had to use some pointer operations:
onButton() {
Window *wnd;
wnd->create();
wnd->show();
// wnd is lost and memory leak will occur
}
now memory leak is a problem but i can fix this.

thanks for the comment eero

srelu
January 19th, 2008, 12:55 AM
finally fixed the code...and the problem was the wrapper class for window/dialogbox
onButton() {
Window wnd;
wnd.create();
wnd.show();
// wnd is destroyed at this point.
}
Because ~Window() contained the following code, the window object was destroyed:
~Window() { DestroyWindow(hWNd);}

To avoid this, i had to use some pointer operations:
onButton() {
Window *wnd;
wnd->create();
wnd->show();
// wnd is lost and memory leak will occur
}
now memory leak is a problem but i can fix this.

thanks for the comment eero
You didn't understand, what posted eero is not a comment, is THE SOLUTION. You should follow his advice.