<h1>Tech Notes</h1><h2>Building and Using Sheet Windows</h2><p>It only takes a few lines to build a sheet window and a few lines to dispose of it. I'll cover that in just a second. The problem is that we do not freeze our computers while we are waiting for input. For example, if a sheet window over one document displays the "Save before closing?" dialog, there is no reason that other documents should not be useable. The same is true of anything that might be asked of a single document. In fact, there may be a dozen "Save before closing?" sheets visible at one time and you should technically be ready to service each of them independantly. I bet that makes your brain hurt!</p>
<p>Why don't we start with the simple steps required for building a sheet window. I will ignore sheet <i>alerts</i>. They're for whimps. Real mean don't drink wine coolers and they don't freeze up a program with alerts.</p>
<p>At some point in time, Bubba Q. Citizen is going to get tired of this sheet and click a button. Here is how we push the flush lever:</p>
<pre>
dim as windowRef @ sheetW
dim as OSStatus err
dim as long sheetNum
sheetNum = window ( _outputWnd )
get window sheetNum , sheetW
err = fn HideSheetWindow( sheetW )
window close sheetNum
</pre>
<p>Here's the $64 question: How did we know that Bubba clicked in a sheet window? And how did we know what window that sheet belonged to?</p>
<p>The answer is going to be a simple one: We set each sheet window to have an ID number equal to the window that it covered <i>plus </i> 50,000. We can deal with the dialog events by looking at the output window (which will be greater than 50,000). <i>Or...</i></p>
<p>I have a slightly different style of programming. I enumerate my windows in increments of 1000. My first window is 1000, then 2000, etc. All controls and fields inside of those windows are numbered inside of the window's range (i.e. 1001 , 1002 , 1003...). I know if button number 4007 is clicked that it belongs to window number 4000. I know if button number 51003 is clicked, it belongs to button #3 in a sheet window that is over document number 1000. Know what I mean, Vern?</p>
<p>The enumeration is easy:</p>
<pre>
begin enum 1000, 1000
_myfirstWindow
_mySecondWindow
end enum
begin enum
_okFirst = _myfirstWindow + 1
_cancelFirst
_entryField
_promptField
end enum
_sheetWindowAdd = 50000
begin enum
_sheetSave = _sheetWindowAdd + 1
_sheetDontSave
_SheetCancel
_sheetOk
_sheetDeletePage
end enum
</pre>
<p>The pieces are falling into place now. If we receive a dialog event, and it is a button click, we know (because of the button's ID) that it is in a sheet window. If you do not use this enumeration system, then you <i>still </i>know it is in the sheet window because of the number of the output window. It is higher than <span class="pre">_sheetWindowAdd</span>. Given this information, you can branch to your sheet window handler and prossible/probably close the sheet window.</p>
<p>I've built a complete project for your inspection. No matter what methodology you use, fancy enumeration, high numbered output windows, spagettie code... you can still work sheet windows into your application.</p>
<p>Click <a href = "http://www.stazsoftware.com/downloads/sheets.sit">here</a> to download the file.</p>