If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

WINAPI windows management question

Hello everyone.
First of all I want to introduce myself as I am new to this forum.
I am a Software developer who loves programming and who likes to learn a lot of languages. So I am in search of gathering basic knowledge for the most significant languages to have some basic clue in case I need them someday.

Now my question:

I'm learning to develop windows applications using WINAPI and plain C.
Now I got a bit confused with all those handles and would like to ask if you guys could teach me some good practices to structure and handle controls and windows.

Here's where I get confused:

Using the IDs declared in the resources for each object, we can get their handles using GetDlgItem(). Now what if we don't know their parent, which is needed by this function.

One example: We have the main window created at launch. Then we register two new window classes and create a window for each new class and we create a message function for each too. Now if inside one of the children windows I create a button and inside the other child window I create a text label. Now when we click the button inside of child window A the label in child window B shall be modified to whatever.

The WM_COMMAND for the button is interpreted inside the message loop for child window A. Now what would be the best and more elegant way to access the text label inside the child window B?

I am in the process of learning the WINAPI and just want to learn it right from the start instead of producing Hacked code that someday becomes unreadable and to later have to adapt to a new way of programing.

Re: WINAPI windows management question

Now if inside one of the children windows I create a button and inside the other child window I create a text label. Now when we click the button inside of child window A the label in child window B shall be modified to whatever.

Child window should send a custom message to its parent about wanting to change the label. Only parent window knows whether the other child has been created to the moment. If yes, the parent sends another custom message to the other child instructing it to change the label for corresponding control.

Note, parent is a message broker in this scheme able to route/transform the messages, and child windows just need to follow some special protocol for sending commands or responding to those. Looks a bit tedious, though flexible and reliable.

BTW, this approach generally has nothing specific to do with Win32 API.

EDIT: Of course there may be other ways to implement this behavior. Feel free to develop your own one.

Re: WINAPI windows management question

Now I may be complicating myself but I'm still a bit confused. Also I may not being explaining myself correctly.
I made a picture where I state my problem:

Now where I'm confused:
When hButton is clicked, hLabel should be changed.
I get a bit confused on which messages go where and how to know the parents etc.

So normally hwndControls being the parent of hButton, should be the one receiving the message from hButton right?
Now hwndControls doesn't know that hwndContent exists! so it can't send it a message.
What I also don't know is if it is good practice to pass all the handles by parameter or declare them as global so they are visible. I don't know if you see where I get confused?
And I don't think that parent of parent of parent of child is a good practice is it?

Maybe you could post some more specific example or maybe some simple code for this problem so I can actually see what I'm missing to understand, If you wouldn't mind.

This example is just an example I've created so I can understand how to handle that kind of problem. Understanding this would help me understand how to do it for all other contexts.

Hope I am not asking for too much. I really just want to learn it the right way on the first run so I use good practices from the beginning on.

Re: WINAPI windows management question

Originally Posted by gekod

I made a picture where I state my problem:
...
Now where I'm confused:
When hButton is clicked, hLabel should be changed.
I get a bit confused on which messages go where and how to know the parents etc.

As Igor stated, this has nothing to do with win32. You should forget about the windows and start talking in terms of classes and objects. Basically, your problem is:
You have an object a of class A and an object b of class B. Now in some function of a, you want to call a function of b. Therefore, a needs to have a reference to b. That's it; no windows, no messages.

Cheers, D Drmmr

Please put [code][/code] tags around your code to preserve indentation and make it more readable.

As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

Re: WINAPI windows management question

Re: WINAPI windows management question

Originally Posted by D_Drmmr

As Igor stated, this has nothing to do with win32. You should forget about the windows and start talking in terms of classes and objects. Basically, your problem is:
You have an object a of class A and an object b of class B. Now in some function of a, you want to call a function of b. Therefore, a needs to have a reference to b. That's it; no windows, no messages.

That's true for object oriented frameworks. But in plain Win32 API you need to invent some routine mechanism based on some kind of messaging.

Re: WINAPI windows management question

Hello,

Sir, I really want to thank you for taking time to help me out! This is in deed very kind of you and I really appreciate it! If all forums had people like you, people would be able to learn so much more!

Re: WINAPI windows management question

A little bit developed concept of custom message protocol, sample attached. Now it makes use of the single message WM_MYCOMMAND encapsulating a number of commands based on corresponding command parameter structures. In fact, this way the message based Win API part works.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.