Hello,
I have been reading tutorials on c++ for a while, and made a few simple applications. Now I've started looking at win32, and while all the tutorials I've looked at are quite good, they miss out on some simple points. I know how to make a window, a menu, message boxes etc, but how do you just write text on to your application? How do you make textboxes to get information from the keyboard?

It uses operator overloading, so you should be able to use the stream operators e.g. you should be able to >> and << data to and from controls

You can write text strings to any window for which you have its hWnd with TextOut() or DrawText(). For edit controls, i.e., text boxes, you put text in them with SetWindowText()....

void MessageHandlingProcedure(HWND hWnd)
{
 char szBuffer[]="Some Text To Go In A Text Box";
 SetWindowText(hWnd, szBuffer);
}

If you use SetWindowText() with an ordinary top level window that has a title bar, the text will go in the Window Caption. Various windows respond differently to the call. Hope this helps. If you are trying to learn Win32 I'd recommend you get a book.

I agree with Frederik2, partly.
A book would be great, but there are also some nice tutorials online, for free, sometimes with video's. (You probably already did that, just read on).

I've been programming for about 1,5 months, (I started with straight c++ in Windows Visual Basic, free version (you should try it). Then I started following some Win32 tutorials, just like you, and I got stuck at exactly your point.

When you are in Visual C++, click new project, Win32 project, with a name. Click empty project. Then, click on the solution explorer tab, and right click the folder resources. Click dialog. From there, use the toolbox to make bottons, and other controls. Write your code in your .cpp file, and open your dialog as your main window. Then use your DialogProc to handle your messages.
You can use static text windows in your main window to print text on, straight from the dialog editor.

Good luck, post if you have any questions, which you probably will ;)

hiddepolen, in my opinion what you have just described is the absolute worst way possible to start Win32 programming. It is very quick and dirty, I know. What you have described is use of the Windows Dialog Engine to create an application. Further, you are going to become addicted to 'drag and drop' programming that way. Real programmers start with RegisterClassEx() Frame Windows.

In my opinion Windows Drag And Drop Dialog Engine Programming using C++ represents the antithesis of whatever virtue adheres in the language. Might as well just switch to Visual Basic and be done with it.

Well, It's true it's a lot easier, and I know how to use RegisterClassEx (), and CreateWindow () etc...
Since some time I started making dialogs, and my windows with the Drag and Drop, and I really like it. Maybe a waste of C++ (you're right), but much more efficient.

I do though have the knowledge to solve errors 'manually' if they occur... So I'm not completely wasted !-)

Thanks for not taking it the wrong way what I posted hiddepolen. After I posted it I thought I was being pretty nasty.

The reason I reacted the way I did though is that I've seen folks did themselves into a hole they weren't able to get themselves out of by over concentrating on Dialog Box programming. First thing newcommers start doing is trying to make them the basis of major applications, and they soon run into trouble.

For quick and dirty though, as you discovered, it works.

Yes you're totally right. I've helped quite some people trying to use the Resource Editor, or whatever other program, to make their Win32 Program. They ran into many problems...

And for me, yes, it works ;)...

This article has been dead for over six months. Start a new discussion instead.