So, You Want To Write Windows Apps (V) A step-by-step guide | ||||||||||||
By Jim Guerber | ||||||||||||
| ||||||||||||
Previous Chapter | Table of Contents | Next Chapter | ||||||||||||
What we have learned so far is that to create a Windows control, you need to tell Windows the kind of control you want to create, how to locate it (row and column), what its size should be (height and width), and what style elements to apply to it. It’s the style that gets complicated. You see, every control is just a window with added style elements. Sometimes controls, like the combo box, are made up of several controls themselves. The combo box is an edit box above a list box. The style elements tell Windows how it should look and act. I encourage you to play with the styles in these programs to see how the changes affect the look and feel of the controls.
Combo Box styles
Of course I had to play with the locations of the check boxes to accommodate the new control, but changing the style is all I really did. Notice on the same lines that when creating a control, you also must specify some windows styles. Those are the “WS.” things. Since controls are windows too, these things control some aspects of every kind of control. I just copied these from an example program. I don’t really know exactly what they do, but I am confident that I can look them up and find out if I really wanted to know. To look them up, I would just do a Google search for them on the internet, substituting an underline for that period in their name. Here is an example: That’s the documentation you have been looking for. Just like almost everything else, it's on the web. An alternative is experimentation. Try different styles in your program and examine what they do. How do you find out what all the possibilities for a particular style are? Open windows.inc in the WDL directory and do a find with Ultra Edit for “ws.”. Or for combo box styles, look for “cbs.”, for Button styles, look up “bs.”. Once you see all the styles that are possible for the control you are interested in, try them and see what they do. Another alternative is just to copy those few lines of style specs from another example program and leave it at that.
List Box Font and Tab Stops Instead of making the comet window larger to accommodate all of that data in the list box, I made the list box font smaller.
Group Box I am sorry I put so many changes in one program, but the temptation to go from one thing to the next was just too much to resist. This kind of programming really gets to be FUN once a few concepts are understood. Oh, let me say something about those gosubs you see in these programs. I have been criticized for making parts of the program into subroutines. Some of those subroutines are only called from one place. People say that this looks too much like Brian’s coding style. Well, thanks for the compliment. The reason I grouped the modules into subroutines was so I could treat each routine as a module. This way it is clear to me (and you) what things belong together. Another reason I did this was so I could change the order in which things happened in the program without moving a bunch of code around. I suggest you start coding this way too. It makes working on the programs much more pleasant. By the way, do you know about the f5 key in Ultra Edit? If you highlight a block of code and then hit f5, the editor will convert all of the text to “title case”. This is much easier to read than that old upper case stuff. If you need some piece of text in upper case just highlight it and hit alt-f5. Transparent Text
The only change I made in this program was to add a new routine called MakeLogo. This uses the GDI routines to put a title on top of the window. Notice that I specified that the text be transparent. This means that whatever is beneath the text will show through. In subsequent programs I intend to play around with the font face etc of this area. Logo Image
You can see from lines 130 through 138 that displaying an image is really simple. Comet will even stretch or squash the image to fit a rectangle you define (in CentiUnits of course).
List Control vs. List Box
The list control is another compound control like the combo box. It is composed of a series of buttons above a list box. The list control is really much more than that. It is the control that Windows uses to display a folder. It can take on all of the different looks that are selectable when you click on the view menu item. I am only going to work with the view that you see when you select “Details”. This is selected by specifying LVS.REPORT as a style. The create code starts at line 349. The reason for all of the additional code is because we must specify the size and contents of those header buttons, and tell the control how to sort the contents of the list box. That’s right – the control itself (with a little help from comet) will automatically sort the list box any way you want. Note in lines 370 through 428 that I tell the list control several things about each column. I specify (in CentiUnits the size of the column, I give the column a title, and I tell the control how to justify the contents of the column. For example, I want the first column to be titled “File Name” and it should be based on CentiUnits of the current font.
For my final experiment I changed my fonts to Arial, which is a proportional font. So, as I did in Win11.ibs with the list box, I had to use tab stops to properly position the DirCat fields in my list control.
So, that's the end of the beginning of my adventures programming Windows apps in Internet Basic. There are many controls other than the ones I used here. You can make Radio Buttons, Tab Controls, Edit Controls, Tree Controls, Date/Time Pickers, and more. In the next chapter, Barbara will show you how easy it is to use them. She's written a demo program for each control so you can learn just the ones you need. Have fun with it. I sure am! |