简体   繁体   中英

Windows in Win32 API GUI Programming

I am starting GUI programming and I have a question about windows. I have read some tutorials and they create a window by making a new WNDCLASS, calling RegisterClass and then doing CreateWindow with the name of the new class. I also have seen that to create a Button or something, you use the class name Button when you CreateWindow. So this leads me to this conclusion: to create a window (the kind with a border and minimize/maximize buttons, etc.) you create a new WNDCLASS. Otherwise, you don't need to make a WNDCLASS and you use one of the predefined class names, such as BUTTON. Is this correct?

Correct. The main reason you need to define your own WNDCLASS for your windows is to assign your own window procedure that handles messages sent to your window. Standard controls such as buttons and edit controls already have well-defined behaviour as defined by their standard window procedures, hence you can just use the pre-defined class names.

If you're going with old-school Win API programming, I can't recommend Programming Windows by Charles Petzold enough. The latest version is out of print, which IMO is insane. This is the classic book on the subject. Because it's out of print, it costs more for used versions. If you want to go cheaper, get the previous edition , which you can get for $0.01 used. The basics are all the same.

You are absolutely correct. The window class defines the appearance and behavior of a window; you can override these to a certain extent by changing the styles and responding to the window messages, but it's best to define your own window class if one of the predefined ones doesn't work.

There's a list of predefined window classes in the CreateWindowEx documentation.

.

Yes, you're correct. There are several predefined controls\\windows with predefined (look and) behaviours. These are called System Classes .

For example,

"Button" is this class you can use to create a button.

Please look at the table from MSDN

Button :: The class for a button.

ComboBox :: The class for a combo box.

Edit :: The class for an edit control.

ListBox :: The class for a list box.

MDIClient :: The class for an MDI client window.

ScrollBar :: The class for a scroll bar.

Static :: The class for a static control.

Now, you can read yourself at MSDN. Click this : About Window Classes

Hope it helps you.

.

Remember, creating a new "Dialog", like "About" Window doesn't require a new RegisterClass(). I don't agree with John Dibling about learning MFC before or instead of Windows API.

MFC is built on top of Windows API, in other words, MFC IS Windows API but wrapped in C++ classes, so by all means, if you need to learn MFC, you will have to know Windows API.

Good Luck.

To begin, you are learning Windows GUI programming starting with the WINAPI. This is not what I would recommend. Instead, I'd start by learning a Windows GUI library first, such as MFC. Windows GUI programming is hard enough. Don't make it harder than it has to be when you're first learning.

A Window Class is to a Window on the screen as a C++ class is to a C++ object. It is a blueprint for how to construct the Window on the screen, and it contains information about things like where the function that handle's messages is, what kind of device context to use, etc.

Different kinds of windows need different window classes. There are many window classes predefined in so-called "common controls libraries." The common controls include most all the controls that you find on a typical window. Buttons, sliders, text boxes, grids, etc. You can create these common controls without having to register the class yourself, because the common control library has already done it for you when it was initialized.

Everything on the screen is a window of some kind. This web browser, the "back" button, the edit box I'm typing in -- each is a seperate window. And each must be associated with an appropriate window class. Most of the controls you use will be associated with a common control window class. If the wondow you're creating, such as the applicaton's main window isn't a common control or some other type of window with a predefined window class, you'll have to register that class yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM