Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.


Is there really no one able to give me some advice?

share|improve this question
add comment

2 Answers

About a year ago I stumbled on a book at work that was about to be thrown away. It was called Windows Wisdom: For C and C++ Programmers ISBN: 0471940046

The book presents a problem, and then provides a number of different approaches and solutions to the problem. If it were published today it would most likely be called "WINAPI Recipes" or "WINAPI Cookbook". Its that type of book.

The book is out of print but you should be able to find a used copy for cheap.

Instead of regurgitating the contents of the book, I wanted to point you at the source. I believe it may provide the general guidance that you are looking for.

share|improve this answer
    
Thank you for the tip. I'll try to find me a copy of that book. Allthough until I have it I would still appreciate some advice. If anyone could help I would appreciate it –  gekod Sep 15 '12 at 10:41
    
Thanks for submitting your first answer on Stack Exchange Programmers. Please keep in mind the guidelines for questions published at programmers.stackexchange.com/questions/how-to-answer . These suggestions will help you get more up votes and higher reputation on the site. You can also read the FAQ programmers.stackexchange.com/faq which includes the reward of the Analytical badge for even more suggestions. –  DeveloperDon Sep 24 '12 at 23:21
add comment

First thing to have in mind when writing programs for Windows using the Plain Old Win32 API is that every control on screen is a WINDOW on its own. Which means each have their own "HANDLES" and the like. I think you're using an easy way out by creating controls on a DialogBox using Win32 RES editor(which is fine for a beginner). But when you go into more advanced programming on Win32, I would suggest you use CreateWindow() function.

To answer your question you could just get the handle of the control like so: GetDlgItem(HWND hParent,int nIDDLGITEM) function, and SetWindowText() over it. Make sure that the Static label has SS_LEFT property.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.