I have a main window and I need to create a child window. When I close (and destroy ) it the main window goes below all others windows on the screen.
The main window is created like this:
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, 0
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hInstance
pop wc.hInstance
mov wc.hbrBackground, COLOR_ACTIVECAPTION +1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, ClassMain
INVOKE LoadIcon, NULL,IDI_APPLICATION
mov wc.hIcon, eax
mov wc.hIconSm, eax
mov wc.hCursor, 0
INVOKE RegisterClassEx, addr wc
INVOKE CreateWindowEx, NULL,ADDR ClassMain,ADDR AppName,\
WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN,\
100, 50, 700,600,NULL,NULL,hInst,NULL
mov hWndMain, eax
or .eax, eax
jz GetOut
invoke InitApp
or eax, eax
jz Iesire
INVOKE ShowWindow, hWndMain,CmdShow
INVOKE UpdateWindow, hWndMain
.WHILE TRUE
INVOKE GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg
.ENDW
mov eax, msg.wParam
GetOut:
ret
WinMain endp
When a certain event occures, the child window is created, using CreateThread:
CreareAfisareAux1 proc Dummy1:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL LGB :LOGBRUSH
INVOKE EnableWindow, hWndMain,FALSE
mov LGB.lbStyle, BS_SOLID
mov LGB.lbColor, 00FF2222h
mov LGB.lbHatch, 0
INVOKE CreateBrushIndirect, addr LGB
mov hBRSFundalAux1, eax
mov wc.hbrBackground, eax
mov wc.cbSize, SIZEOF WNDCLASSEX
mov wc.style, 0
mov wc.lpfnWndProc, OFFSET WndProcAux1
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
push hInstance
pop wc.hInstance
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, OFFSET ClassAux1
mov wc.hIcon, 0
mov wc.hIconSm, 0
mov wc.hCursor, 0
INVOKE RegisterClassEx, addr wc
INVOKE CreateWindowEx, WS_EX_PALETTEWINDOW,ADDR ClassAux1,ADDR Aux1Name,\
WS_OVERLAPPED or WS_CAPTION or WS_VISIBLE or WS_SYSMENU or WS_CLIPCHILDREN,\
PozAux1.left, PozAux1.top, PozAux1.right,PozAux1.bottom,hWndMain,NULL,hInstance,NULL
mov hWndAux1, eax
or eax, eax
jz GetOut
invoke InitiAux1
or eax, eax
jz GetOut
INVOKE ShowWindow, hWndAux1,SW_SHOW
INVOKE UpdateWindow, hWndAux1
.WHILE TRUE
INVOKE GetMessage, ADDR msg,0,0,0
.BREAK .IF (!eax)
INVOKE TranslateMessage, ADDR msg
INVOKE DispatchMessage, ADDR msg
.ENDW
mov eax, msg.wParam
GetOut:
ret
CreareAfisareAux1 endp
Of course, there is a <<INVOKE EnableWindow, hWndMain,TRUE >> and <<INVOKE SetActiveWindow,hWndMain>> in WndProcAux1.
How can I keep the main window on top?
PS: sorry for the aspect of code.
Well what's the
Quote
INVOKE EnableWindow, hWndMain, FALSE
for?
Plus, you should make sure your
Quote
jz GetOut
Appropriately returns the correct EAX.
Anyway, I don't think it's so much that your main window is "hiding", but that your child window is just always on top
Note that WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE or WS_EX_TOOLWINDOW or WS_EX_TOPMOST
With that said, try "WS_EX_WINDOWEDGE or WS_EX_TOOLWINDOW" instead of WS_EX_PALETTEWINDOW
INVOKE EnableWindow, hWndMain, FALSE - we are stopping the user input to the main window
When the auxiliary window recives a WM_DESTROY message, we are using INVOKE EnableWindow, hWndMain, TRUE to allow user input to the main window.
Don't worry about <<jz GetOut>>. It's OK.
What you are saing, savage, is that when one uses WS_EX_PALETTEWINDOW the main window will be hidden when the uses closes the secondary one? I don't think so. There must be a way arround..
Thank for your post anyway!
The main window will act normal. Just the child window is always on top regardless.
But anyway, what exactly are you trying to make it do?
I am trying to make a main window and a secondary window wich is created when the user clicks on the client area of the main window. When the secondary window is created, I don't want to allow user input to main window. When the secondary window is destroied, I want to allow user input to main window.
But, most of all, I dont want that main window to go beneath all other windows on the screen when the user closes (destroy) the secondary window!! <- this is the problem
I think enablewindow is the problem. You should find a different way to disable the window.
For example, dialogs dont disable the main window, they just prevent you from focusing on it, which is different from being disabled.
Hello,
your main windows as NULL style
mov wc.style, CS_BYTEALIGNCLIENT or CS_BYTEALIGNWINDOW ;
The ClassMain is not in the source , ClassMain db "?",0
If you have take a too much common name,it is possible it is duplicate and don't work properly.
Other's windows can be TOPMOST (style) windows,and you can do only one thing,add this style to your window.
ToutEnMasm
Use ShowWindow, at least the Window will be able to process it's message loop, but not seen.
Regards, P1 :8)
QuoteI am trying to make a main window and a secondary window wich is created when the user clicks on the client area of the main window. When the secondary window is created, I don't want to allow user input to main window. When the secondary window is destroied, I want to allow user input to main window.
well for this Im using
DialogBoxParam function to create a modal dialog box , this function displays the dialog box, disables the owner window, and starts its own message loop to retrieve and dispatch messages for the dialog box ...
to close it call the
EndDialog function,then DialogBoxParam destroys the dialog box, ends the message loop, enables the owner window...
hope it helps...
Here it it the source code and the executable. Just open Windows explorer, then run the executable and click in the client area. When you will close the second window, you will have a little surprise ... :'(
savage - yes, you may be right. But why was this function been invented if not for this case?
ToutEnMasm - class name is unique; I can not add TOPMOST to my winmain style.
P1 - as you can see in attached example, main window doesn't have any problem in processing messages (EnableWindow stops Windows from sending messages to that window? I think not ...)
dancho -if DialogBoxParam can, I can (with your help, of course!) :bg
[attachment deleted by admin]
Hello,
You used two waiting loop,one is enough.
End of the child windows is incorrect......
A sample that work is better.
ToutEnMasm
[attachment deleted by admin]
QuoteYou used two waiting loop,one is enough.
you are right.
QuoteEnd of the child windows is incorrect......
I can't see why, but I don't have time anymore today. I will analyse your code. Thanks!
Quote from: savage on August 03, 2006, 03:25:51 PM
I think enablewindow is the problem. You should find a different way to disable the window.
For example, dialogs dont disable the main window, they just prevent you from focusing on it, which is different from being disabled.
Quote
savage - yes, you may be right. But why was this function been invented if not for this case?
Well EnableWindow is useful for things like buttons you don't want to click on... or edit boxes you don't want to be edited.
P.S. I have had tons of trouble with this in this past. I wanted to make a custom popup box that was a "modal" window, like MessageBox's are. I've never really been able to figure out how MessageBoxes do their thing, and I've tried using Spy++ to figure it out. I would like to hack into the workings of MessageBox to figure out how he does it. Perhaps it is EnableWindow, or perhaps it simply refocuses itself when it is unfocused. But I've pondered it for years.
UPDATE: Using Spy++ I can confirm that MessageBox *does* disable the main window, so perhaps you were on the right track. =P
Apparently when the child window is closed, the main window loses it's z-order.
Another weird thing. If you have another window that is "always on top", even if its not part of the program, it will receive focus and the main window won't lose z-order. Very odd.
With several applications launched, the parent window only goes behind one window.
This is probably due to process switching. SetActiveWindow sets the active window of the CURRENT PROCESS. Each process that has windows has an active window. Alt-Tab is another way of bringing up the active window of a process.
It's not clear whether it's the thread exit or the WM_QUIT handling that causes the OS to switch to the PREVIOUS process. This would probably be the reason a different window will jump in front of the expected window.
I was under the impression that ExitThread should be invoked to terminate a thread, rather than a simple return.
Maybe just send a SetFocus to the main window when the child window is closed?
Sorry for this delay.
savage: SetFocus doesn't work :(
But I think it may work for replacing the EnableWindow function. Anyway, this is not a practical solution if you are creating a large aplication, with many diffrent "modal" windows.
tenkey: I see now that you are right
QuoteWith several applications launched, the parent window only goes behind one window.
But I can swear that another times it was the last.
About CreateThread-ExitThread: (Win32.hlp)
QuoteThe thread execution begins at the function specified by the lpStartAddress parameter. If this function returns, the DWORD return value is used to terminate the thread in an implicit call to the ExitThread function
Thanks for your posts anyway. In the end, we will find the answer! ... I hope :8)
Just want to remind to all posters that I'm still in trouble with this!!!!! :boohoo:
DialogBoxParam example:
Download-Link: http://rapidshare.de/files/28798269/DBox.7z.html
***RadASM dialog as main project***
The answer is, of course, <<INVOKE SetForegroundWindow,hWndMain>>.
:)