child win creation in a MDI fails using CreateWindowEx

Started by Rainstorm, August 03, 2011, 11:31:05 PM

Previous topic - Next topic

Rainstorm

dedndave,
of all the the changes you mentioned in your last post, i tried just one, just now.... adding WS_OVERLAPPED to the window style in the Chhild window creation, and the window displayed (left everything else the same as before)
so just that one change displays the window, .....not sure what you meant about the corner painting issue but the window seems to display okay here. its not added to the window menu though.

thx

baltoro

#31
DAMN !!! Mystery solved. I was so tense,... :eek
...And, yet, the original error returned from CreateWindowEx was: 1400,...ERROR_INVALID_WINDOW_HANDLE,...and, not,...ERROR_INVALID_PARAMETER,...

DAVE !!!
Thanks for the investigative work. And, HEY,...I've noticed that you do that alot (solving everyone's problems),...It's vaguely annoying, actually,... :bg

...On a lighter note,...it's nice to know that everything I suggested was WRONG. Even though it's still early morning,...I'm going out to get drunk,... :eek
Baltoro

dedndave

QuoteI've noticed that you do that alot (solving everyone's problems),...It's vaguely annoying, actually

:lol

i am just learning, myself
i wouldn't play with MDI unless someone else had trouble with it
i am still playing with it, too   :P

as for the ERROR_INVALID_HANDLE....
that error makes sense, now that i see what caused it
it wasn't a handle we were passing to CreateWindowEx
it was the handle passed to DefMDIChildProc that was invalid   :P

Quoteof all the the changes you mentioned in your last post, i tried just one, just now....
adding WS_OVERLAPPED to the window style in the Chhild window creation,
and the window displayed (left everything else the same as before)

that may be an OS thing
i am running XP MCE 2005 SP3
to get a proper child, i had to do at least these
1) fill in the MDICREATESTRUCT
2) add WS_OVERLAPPED
3) change CW_USEDEFAULT to 50 (you could probably use CW_USEDEFAULT if you also used it for X)
4) change ID_FIRSTDEFCHILD to NULL
5) remove the child create code from WM_CREATE

after i was done, i tried changing each of those items back individually and there was a problem with each

baltoro

Well,...all kidding aside,...you'd think the MSDN documentation would be clearer. The information about the Multiple Document Interface says nothing about how to structure your code, or system updating of handle values, valid values for the first child window, or the WS_OVERLAPPED flag,...or any of that.   
I noticed. when I was searching for code examples, that almost all the current approaches to MDI (in C++) use either MFC or .NET Framework Forms.
Baltoro

Rainstorm

baltoro wrote..
Quote...On a lighter note,...it's nice to know that everything I suggested was WRONG. Even though it's still early morning,...I'm going out to get drunk,...
have fun baltoro,

dedndave,
I just removed the WS_OVERLAPPED style again

& changed this line in the orginal code of the child win CreateWindowEx..
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT
to this...
50, 50, 100, 100,

so, all the rest of the code is the same as it was in the beginning........ & the window was displayed/shown all the time..just not visible because of the dimensions set with CW_USEDEFAULT (i think)
this win doesn't have a title bar, sizing borders etc..but it now displays properly &  but those styles can be added

WS_overlapped is suuposed to be used as a main window, but the sdk doesn't completely stop one from using it with the ws_child style either, just WS_POPUP isn't supposed to be used with teh child style
WS_OVERLAPPED is a top level window.. & i've wondered why that name was chosen.

some links..
http://msdn.microsoft.com/en-us/library/ms632600(v=vs.85).aspx
http://en.wikipedia.org/wiki/Window_function#Overlapping_windows
thats from signal processing

thx!

dedndave

yah - WS_OVERLAPPEDWINDOW is a collection of several bits OR'ed together
you can probably select the correct ones individually

WS_OVERLAPPEDWINDOW =
WS_BORDER or WS_DLGFRAME or WS_SYSMENU or WS_THICKFRAME or WS_MINIMIZEBOX or WS_MAXIMIZEBOX

0CF0000h =
800000h or 400000h or 80000h or 40000h or 20000h or 10000h


WS_CHILD cannot be used with WS_POPUP

zemtex

If you need many different styles and you're not exactly sure which one you need, it can be a good thing to use Resource Editor by ketil olsen, set the styles you want, then copy the or'ed hex value from the style edit field and paste the raw hex value into your code. It will reduce overview a tad, but you can easily change the styles again by using the same editor.

Personally, I set the hex values in constants. For example:

RIGHT_ALIGNED_BUTTON   = 56473827h
CENTER_ALIGNED_BUTTON = 34534523h

You can have template styles in constants using raw hex values.
I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.

dedndave

i might add....
some of the example code that i have looked at did not use WS_OVERLAPPEDWINDOW for MDI children
with this code, i had to use it to get the child window
that probably means we don't have the right formula, yet   :wink

baltoro

Baltoro

dedndave

ok - got it.....

for the client window, remove MDIS_ALLCHILDSTYLES
then, WS_OVERLAPPEDWINDOW is not required for the children

it appears that MDIS_ALLCHILDSTYLES is intended for the MDI children only

baltoro

DAVE !!!
Congratulations !!! You are unstoppable.
Now that you have gotten the MDI application working correctly,...let's look at an assembly language implementation of an Active Template Library (ATL) version of the traditional Multiple Document Interface (MDI),...
...Wait,...I think there's blood streaming out of my ears,... :eek
Baltoro

zemtex

When people are eager to help one shouldn't try to oppress him, the post button will still be available for anyone to post to the thread.

Experience from other forums however, it CAN become somewhat "irritating" when someone is always at your service, 24 hours a day and that he always has an answer, it can easily become a reminder of a butler in a tv show. But in the end, helping others is a good thing. Dave is helping people. His help is good and should be appreciated.

The problem of learning problems from the same person all the time is that you also inherit his habits, both good and bad, you don't get mixed influence from a wide variety of experienced programmers. It's important that all people get a chance to teach away, you learn a great deal yourself by teaching others, the more you teach away the more you learn yourself also.

The good part of it is that you always get help when needed  :U
I have been puzzling with lego bricks all my life. I know how to do this. When Peter, at age 6 is competing with me, I find it extremely neccessary to show him that I can puzzle bricks better than him, because he is so damn talented that all that is called rational has gone haywire.

dedndave

that is really true
and - i have a certain "style" of writing code - almost noone in here appreciates it   :lol
so, don't use me as the "Do-Bee" example



there are many members that have already figured this stuff out, too
they know the material far better than i do
but, they don't seem to have the time to jump in here
they are probably professional coders - and can get paid for it

but, i saw Rainstorm in here, asking for help, and not really getting anywhere, so i got involved
i don't know this stuff, but - hey - let's figure it out together - i want to learn it also   :U

i got the menu thingy working
before creating the frame (main) window...
        INVOKE  LoadMenu,IDM_MAINMENU
store the value returned in EAX as hMenu and use it as the hMenu parameter in CreateWindowEx
remove the hMenu parameter from the CreateWindowEx call for the client window
set the lpszMenuName of the frame window WNDCLASSEX structure to 0
you can set the menu by passing the ID number that way, but then you have to call GetMenu to get the handle
may as well use LoadMenu and get the handle at the same time

in the resource file...
#define  IDM_MAINMENU                        1000

IDM_MAINMENU MENU DISCARDABLE

and add the EQU to the asm source...
IDM_MAINMENU            EQU 1000
actually, i made a more involved menu
i want to make it fully funtional before posting   :P

in order for the automatic menu updates to occur, the menu has to be associated with the frame window
even though the "Window" submenu handle is passed to the client in the CREATESTRUCT

MichaelW

I have a mental block when it comes to MDI because I have a strong dislike of the interface. I place MDI in the same category as Microsoft's idiotic ribbon interface.
eschew obfuscation

baltoro

MICHAEL,     
I don't think anybody likes it,...which is why MFC introduced the Document/View Architecture. Frankly, this is why I've never liked MFC. If you've ever seen somebody's code in which they are using a MFC class and then create a collision by then calling the underlying Win32 API Window function using a MFC window handle or identifier, you know what I'm talking about.   
When I searched for information about the MDI over at Raymond Chen's The Old New Thing, I discovered that he had absolutely no posts on the subject.
When I was first trying to understand the .NET Framework (because I had a Visual C++ .NET version of Visual Studio), I got a book about programming .NET Forms by Chris Sells: Windows Forms Programming. The book is excellent,...but, Sells gets into this incredibly long, convoluted discussion about MFC and Document View Architecture. This he contrasts to the .NET version which is the Form Class. Both versions try to reduce the complexity of the concept by building classes that integrate most of the techniques and data structures involved with Window management into simple event handlers, properties and attributes. This they did because so many programmers got caught in an abstract situation that they didn't understand, and their applications would hang, for no apparant reason.
....Rant,...continued,...next post,...
Baltoro