473,473 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Further to child windows...

Further to my last post, I have managed to get a child window to display. But its messages are routed to the same WNDPROC that the main window's messages are routed to - what is the way of identifying from the lParam or wParam whether the message came from a child window or the parent? And what if the message uses some other data in the wParam or lParam? Is it better to use one wndproc for the parent window, and one wndproc for all child windows of the same type

Also I am having an issue whereby the child window doesn't seem to be able to gain the focus - i.e. have its caption bar blue instead of grey. But I suspect this is due to its sharing of the wndproc.... is it
Nov 17 '05 #1
4 2002
"Bonj" <an*******@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
Further to my last post, I have managed to get a child window to display. But its messages are routed to the same WNDPROC that the main
window's messages are routed to

The messages are routed to whatever function you specified in WNDCLASSEX
structure when calling RegisterClassEx. If you create two windows from
the same window class, or use the same window proc in two window
classes, then of course messages will come to the same proc.
- what is the way of identifying from the lParam or wParam whether the message came from a child window or the parent?

What's wrong with HWND parameter?
And what if the message uses some other data in the wParam or lParam? Is it better to use one wndproc for the parent window, and one wndproc
for all child windows of the same type?

Yep, that's the idea. You use the same proc for all windows that behave
similarly, and different procs for windows that should behave
differently.
Also I am having an issue whereby the child window doesn't seem to be

able to gain the focus - i.e. have its caption bar blue instead of grey.
But I suspect this is due to its sharing of the wndproc.... is it?

A child window is not supposed to have a caption. When it does, it never
gets active. Except in MDI - are you maybe trying to create an MDI
interface?
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
Nov 17 '05 #2
Thanks for posting Igor...
What's wrong with HWND parameter?
Oh yes. Forgot that. A case of not seeing the wood for the trees I think!
A child window is not supposed to have a caption. When it does, it never
gets active.
OK then - what about the sort of window that you get when you click 'Tools,
Options' or 'Project, Settings' in Visual Studio, is that not a child window
with a caption that is active?
Except in MDI - are you maybe trying to create an MDI
interface?
Yes, I think I am. Basically I wrote some generic code that performs the
very basic function of encapsulating the process of creating a window into a
class, and it seemed to work quite well for the program that I'm developing,
but was generic enough to be reusable - so I posted in on
planetsourcecode.com (C++ under 'ClassDialog') for others to look at. But
it's only designed for a single window, in a single threaded application...
somebody emailed me to ask him to help with his efforts at using it in a
project of his. What it seems like he's trying to do is to create a main
window, then create some child windows in different threads. What he's done
is basically copied and pasted the WNDCLASSEX-registering code from the
class into a thread function, which I thought was a bad idea generally both
from a maintenance point of view because there's no point in wrapping the
code in a class and then just duplicating it somewhere else. So I decided to
try to get the class to be able to instantiate a child window (using the
same class that the parent was itself), and putting the code that
instantiates the extra classes for the child windows in a thread function...
but with regards to the threads issue, I thought it seemed a bit 'cramped' -
I didn't like the sound of several threads accessing the same wndproc router
at the same time, aswell as the fact that the window appeared to be having
to kind of 'bootstrap' itself - it needed a pointer to itself and that just
didn't seem good to me. So I tried a different approach today, I created a
separate class for the child windows, and kept it as one thread. The child
window class registered its own WNDCLASSEX, but used the same wndproc - and
it worked (even though the child window never got focus as I expected - but
see my previous paragraph as to this). However, I am in two minds as to
whether the downloader of my code is using extra threads because he
genuinely needs separate UI threads - or just because he happens to like
multithreading, possibly because he believes it always improves an app's
performance, and as such makes it one of the first things he codes at the
start of any application as a matter of course. I originally wanted to post
back to him a working example that uses child windows in their own threads
from the same class. But I guess it's probably going to be different classes
for the child windows, and single threaded - with a note that he should
perhaps evaluate the threading needs of the application more thoroughly and
that an extra UI thread is a whole different beast from an extra worker
thread, and that it might make cleaner code to only use threads for specific
long operations.

So to cut a long story short, my class has fulfilled its purpose for the
program I intent to write - but it's led onto "well what if I wanted it to
do x, y and z aswell?" !
So I guess I would really like to know something about the difference
between (and how to create) a window that is like an options dialog
(possibly non-modal, but confined to the application) and a window that is
an MDI window....
any pointers?
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken

Nov 17 '05 #3
"Bonj" <a@b.com> wrote in message
news:e1****************@TK2MSFTNGP11.phx.gbl...
A child window is not supposed to have a caption. When it does, it never gets active.
OK then - what about the sort of window that you get when you click

'Tools, Options' or 'Project, Settings' in Visual Studio, is that not a child window with a caption that is active?
No, it's a popup window, with WS_POPUP style. Just check with Spy++. A
child window is the one having WS_CHILD style. Typically, a dialog is a
popup window, controls are its children.
What it seems like he's trying to do is to create a main
window, then create some child windows in different threads.
Very, very, very bad idea. Don't do that. If at all possible, keep all
UI in a single thread. In some cases, it may be useful to keep
independent top-level windows in different threads. But having a child
window and its parent window in different threads is simply a recipe for
deadlock.
So I guess I would really like to know something about the difference
between (and how to create) a window that is like an options dialog
(possibly non-modal, but confined to the application)
What do you mean, confined? A dialog is not confined within its parent.
You can drag it outside - just try it.
and a window that is
an MDI window....


They are different, the same way apples and oranges are different. I'm
not sure I understand this question.
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
Nov 17 '05 #4
> No, it's a popup window, with WS_POPUP style. Just check with Spy++. A
child window is the one having WS_CHILD style. Typically, a dialog is a
popup window, controls are its children.
Right, thanks. This is the information I was looking for.
What it seems like he's trying to do is to create a main
window, then create some child windows in different threads.
Very, very, very bad idea. Don't do that. If at all possible, keep all
UI in a single thread. In some cases, it may be useful to keep
independent top-level windows in different threads. But having a child
window and its parent window in different threads is simply a recipe for
deadlock.


I thought so, and have advised him of this.
So I guess I would really like to know something about the difference
between (and how to create) a window that is like an options dialog
(possibly non-modal, but confined to the application)
What do you mean, confined? A dialog is not confined within its parent.
You can drag it outside - just try it.


No, I suppose it's not....if that isn't the expected behaviour of them then
I suppose there's little point trying to make one confined.
and a window that is
an MDI window....
They are different, the same way apples and oranges are different. I'm
not sure I understand this question.


Yes, I see that now, thanks. I thought that all windows other than top level
windows had WS_CHILD style, and they each had extra code to handle the
behaviour typical of popup windows and MDI-child windows. I've since
discovered an example that indicates that MDI children are created with
separate API functions, and learned from you that WS_POPUP is the style to
use for an options dialog, so I guess I'm content with that... cheers for
your help.

--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken

Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: CJack | last post by:
hy, I have an mdi application, i create a child form and I want to know when a button is pressed while that child form is loaded. I have this code: private void frmTestBaby_KeyUp(object sender,...
3
by: James Spibey | last post by:
Hi, I have an MDI application which has aboout 10 child windows. The way the app needs to work is that only one window should be visible at a time and it should be maximized within the parent...
3
by: Maheshkumar.R | last post by:
Hi groups, How i can command over the MDI CHIlD forms created dynamically at runtime from PARENT. Let say, i have generated 5 mdichild forms, but i want to work with child form1 from MDI...
3
by: Isabel | last post by:
How can you close all child browser windows that where open by a parent browser window? I have links on a parent (main) page that opens the child page as a separate browser. However, I need to be...
8
by: Brent White | last post by:
If you need more information, I'd be glad to give it, but I am developing an ASPX page so that the user can select multiple values for a specific field, then pass them on (using Crystal Reports 10...
3
by: Lance | last post by:
I've noticed that controls that are contained in MDI child forms fail to raise MouseLeave events if the MDI child form's MdiParent property is set to Nothing (after it was set to an existing MDI...
0
by: Bruin | last post by:
Hi All, I'm having a problem with MDI child forms when the reference to the MDI Parent is set in a Control library. (Sorry for the long post) I have an control library assembly which holds all...
2
by: Lenster | last post by:
Environment --------------- Visual Studio.NET 2003 Version 7.1.3088 ..NET Framework 1.1 Version 1.1.4322 SP1 XP Professional 5.1.2600 SP2 Build 2600 Problem Description...
2
by: =?Utf-8?B?a2VubmV0aG1Abm9zcGFtLm5vc3BhbQ==?= | last post by:
vs2005, c# Trying to understand why one way works but the other doesnt. I have not tried to create a simpler mdi/child/showdialog app for posting purposes (I think even this would not be so small...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.