|
Splash screens, like the one that Power++ uses when you start it, are a good way to let users know that the program is indeed loading. But other times, like for more lengthy process's, or ones that take place while your program is already running, that might not be enough. I really like the progress bar for this. It is well known by users, and they can see how much longer they have to wait.
I have a database application that requires users to log on. After they log in I display a form that lets them know what's going on until the main form comes up. It is nothing more than a progress bar with the style set to: WProgressBarStyleCaption. After I have that on my form I drop a timer, although this could be done by tying it in to the events of your program, to increment the timer and to change the text in the progress bar. The following code is all it takes:
WBool update::update_Create(
WObject * source,
WCreateEventData * event )
{
timer_1->Start(500, 10);
return FALSE;
}
WBool update::timer_1_Timer(
WObject * source,
WTimerEventData * event )
{
static int i = 0;
WString tmp;
switch (i)
{
case 0:
tmp = "Opening: Databases.";
break;
case 1:
tmp = "Loading: Databases.";
break;
case 2:
tmp = "Validating: UserID.";
break;
case 3:
tmp = "Validating: Password.";
break;
case 4:
tmp = "Loading: Reports";
break;
case 5:
tmp = "Loading: Reports";
break;
case 6:
tmp = "Loading: Images";
break;
case 7:
tmp = "Loading: Databases";
break;
case 8:
tmp = "Loading: Databases";
break;
case 9:
tmp = "Loading: Databases";
break;
case 10:
tmp = "Loading: Databases";
break;
default:
tmp = "";
break;
}
i++;
if( i == 10)
i = 0;
label_update->SetText(tmp);
progb_1->Increment(10);
return FALSE;
}
This is a very simple way to do this. You may want to experiment with how your progress bar gets updated. Like having it updated during events that get called.
Darren Osten has offered to help with this column, so look forward to getting some great new tips in the upcoming weeks!!! Thanks Darren!!!
That's about it for this week. If you have any questions, feel free to e-mail them directly to me at jstrande(at)mail.microserve.net.
P.S. Thanks to all of you who e-mailed me questions/comments last week.
One really neat thing I have been using lately is the WAppObject to get all kinds of cool information. Like, the working directory, the user name (Windows NT 4.0 only) and Computer name.
Start a new blank project and drop 6 TextBox components on your form, then name them the following:
Now drop a button on the form and set the label to say Exit. Right click the button and choose the Click event. Put the following code inside the click event:
// exit
WAppObject.Quit();
Right-click the form and choose the create event. in the create event put the following code:
WString commandLine;
WString computerName;
WString programPath;
WString systemDirectory;
WString windowsDirectory;
WString workingDirectory;
// computer name
computerName = WAppObject.GetComputerName();
textb_ComputerName->SetText( computerName );
// working directory
workingDirectory = WAppObject.GetWorkingDirectory();
textb_WorkingDirectory->SetText( workingDirectory );
// windows directory
windowsDirectory = WAppObject.GetWindowsDirectory();
textb_WindowsDirectory->SetText( windowsDirectory );
// system directory
systemDirectory = WAppObject.GetSystemDirectory();
textb_SystemDirectory->SetText( systemDirectory );
// program path
programPath = WAppObject.GetProgramPath();
textb_ProgramPath->SetText( programPath );
// command line
commandLine = WAppObject.GetCommandLine();
// strip leading and trailing spaces
commandLine = commandLine.Strip();
// check for an empty string
if( commandLine.GetEmpty() ) {
commandLine.SetText( WTEXT("
}
// set the command line textbox
textb_CommandLine->SetText( commandLine );
Now fire it up and let it roll. One thing to keep in mind is that WAppObject is really just a Macro. It is, in effect, the current application's instance of the WApplication class. Take a look at the help for the WApplication component. You'll notice that a lot of the methods are declared as static, meaning that you can often write code like WApplication::GetCommandLine() in place of WAppObject.GetCommandLine().
I am looking for some volunteers to write the Newcomers Corner article, if you have any interest please let me know.
That's about it for this week. If you have any questions, feel free to e-mail them directly to me at jstrande(at)tsagate.com. (Please note my new e-mail address will be jstrande(at)microserve.net by the end of this week).
P.S. Thanks to all of you who e-mailed me questions/comments last week.
See you next week...
As you may or may not know, I'm filling for Jon this week. Trying to stay on the same control-theme that Jon started with his last article, I thought I'd touch on menus. Seeing as almost any non-trivial application is going to need them, it's good to get comfortable with them early on. Luckily, this shouldn't be much of a problem, since they are fairly easy to deal with.
Start a new project, right-click on the form created, and choose "Edit Menu...". What really happens then, is that Power++ takes the WMenu component from the Standard page of the component palette, places it on your form, gives it the name menu_1, and associates the menu with your form. You could have done all these steps manually, but there's really no advantage to that (unless of course you need multiple menu components on your form, but that's another story and shall be told another time).
At this point, you should see in front of you the Menu Editor. Initially there are no menu items at all, so lets add some. But before that, you should realise, that Power++ distinguishes between two types of menu-parts: popups and items (or, more specifically WPopupMenu and WMenuItem). Menu items are, as you might expect, the items you click on in a menu to do something, such as clicking on Open in the File menu. But File itself is not considered an item, but rather a popup since it only serves to hold other items inside it. Similarly, any menu-part that leads to a group of items/popups is also a popup rather than an item. As an example of this, take a look at the New popup at the bottom of the File menu of Power++ which groups together some other menu items.
All that being said, the first thing we would want to do is add a popup menu; say, a File menu. So click the New Popup button in the Menu Editor. The popup that you create will immediately be editable, so type "&File" and press Enter (that & means that the following character will be underlined and serve as a hot-key - this works with almost all controls). Now type "File" into the textbox labelled Variable Name Suffix. This means that, since our menu's name is menu_1, the file popup's name is menu_1_File. If you only have one menu on your form (commonly the case) and you later decided to change it to just 'menu' (by double-clicking on the menu component now on your form), then the file popup's name would reflect the change and become menu_File.
Now we want to create some item's to go under the File menu. Click the New Item button and type "&Hello" and press enter. As before, type Hello into the Variable Name Suffix textbox so that this menu item's name will be menu_1_Hello. Something is weird here. If you look at the form, you will see that Hello is beside File, which isn't quite what we had in mind. To fix this, make sure that Hello is selected in the Menu Editor, and click the right-arrow button to move it under the File popup. Try choosing New Separator from the Menu menu and see what happens. Now click on New Item again and notice that these last two items went where you wanted them to go. (If you had wanted one beside File instead of under it, you could always have clicked the left-arrow button). Type "E&xit", Enter and type Exit into the Variable Name Suffix textbox. You can now close the Menu Editor.
Click on File in your form and take a look at your beautiful creation. It's time to make it do something. Choose Hello from your File menu. Power++ will create an event-handler for the Click event of the menu_1_Hello item, which means that this event will fire every time the user of your program clicks Hello from the File menu. add code to this event-handler such as:
SetText( "Hello Menu!" );
Now choose Exit from your form's File menu. Another event-handler will be created for the Click event of the Exit item. Add some code to it such as:
Close();
Now run your program and see if it works how you expect! Sorry if this was a little longer than one can comfortably take in at one time, but menus are a pretty important topic. Read it over if you need to and try experimenting with different structures. Can you get that same sub-popup menu effect that exists for the New popup in the File menu of Power++? Have fun!
By the way, if you have any comments, you can send them to me at bill(at)orbit.org, or send them to Jon, who will be resuming his regular post next week, at JStrande(at)compuserve.com.
This week I thought we would get into a List Box a little bit and show some of the more common methods and events for the WListBox control.
The first thing is, how do we select an item from the list box? Since the items in the list box are on a Zero-Based Index (in other words the first item's index is 0, the second's is 1...) you could use the following code to select the first item in the list box, then find out which item is selected (if we've done our job right, it will be the first, i.e. 0), and then get the text of that item and store it in the variable named item which is of type WString:
lb_1->SetSelected(0);
int i = lb_1->GetSelected();
WString item = lb_1->GetText( i );
One cool trick I like to do sometimes is to sync up two list boxes so that if you select an item in the first list box, the corresponding item in the second list box is selected as well. This would go in the select event-handler of the listbox named lb_1 (right-click on it, choose Events/Select):
int sel = lb_1->GetSelected();
lb_2->SetSelected(sel);
Lets say you wanted to put a button on your form with your list box that allowed people to move backwards through your list box. It might have an up arrow on it signifying that it moves to the previous item in the list. You could use this code in the click even-handler of the button:
int selec = lb_1->GetSelected();
selec--; // can you guess what you would put here to give users the ability
to move forward?? selec++;
lb_1->SetSelected(selec);
lb_2->SetSelected(selec);
Or lets say you would want to give users the ability to delete the currently selected item in the list box by clicking on some button with the text Delete. You're code in the click event-handler of the button would look something like this:
int i = lb_1->GetSelected();
lb_1->SetSelected(i);
lb_1->Delete(i);
That's it for this week, If you have any suggestions, comments or complaints (hopefully not), e-mail them directly to me at JStrande(at)compuserve.com.
By the way, next week a special treat! Bill Klein will write Week #8's article, while I am on vacation. (Editor's note: have a wonderful vacation, I'll do my best! :)