So, You Want To Write Windows Apps (IX) A step-by-step guide |
| By Barbara Brazil |
|
|
| | | |
|
So, it's time for your first event. You don't need to worry about what you'll wear, but you should consider a few "do's" and "don'ts". "Do's" It's kind of the same thing in your Windows app. Whenever you get an event, you need to look around and decide if what just happened changes what events you should allow to follow. Remember, one of the tricks to thinking like a Windows app is to present to the user only choices that make sense. Here's an example from ViewMgr. This is a piece of the Print Field Selector tab:
Notice that when a field on the "Select from" list is highlighted that only the "Add" button is enabled. Now look how this changes if the highlight is moved to the "Selected" list:
Now the "Add" button is disabled, the "Remove" button is enabled, the "Up" button is enabled, but the "Down" button remains disabled. If a field other than the last one in the list had been selected, the "Down" button would have been enabled too. The IB code to change the state of a button is easy. Here's the code to disable the "Add" button:
cosCltId = IDC.FIELDADD ! The control id of the "Add" button There may also be times when you'll want to disable the entire app to give yourself time to do some
processing without being interrupted by user events. In this case you want to change the state of the
window, not just a single control. If you're going to do this, I suggest you turn on the wait cursor
(you know, the hourglass) so the user has a visual clue that they're supposed to stand by. Again,
this is an easy thing to do. Here's the code:
print (BeginWaitCursor) ! Displays the hourglass Then, when you're ready to receive events again, you need to re-enable the window and turn off the
wait cursor:
cosCWnd$ = cosDlghDlg$ That's all there is to it! These are easy ways to make your programs smarter. "Don'ts" Another thing you really shouldn't do from inside your Windows app is a RUN unless you've either destroyed your dialog or deleted all your free-form controls first. These things take up resources in COSW and it's just good housekeeping to cleanup after yourself before you leave. Violating this rule of etiquette is more forgiving than doing an INPUT from your dialog. When you finally get back to either QMONITOR or QENDITOR, Comet will cleanup after you, but it's just bad manners not to do it yourself. |