text:
Windows Programming/Window Creation

On the Windows operating system, most user-interfacable objects are known as "windows". Each window is associated with a particular class, and once the class is registered with the system, windows of that class can be created.

WNDCLASS
To register a windows class, you need to fill out the data fields in a WNDCLASS structure, and you need to pass this structure to the system. First, however, you need to provide your class with a name, so that Windows (the system) can identify it. It is customary to define the window class name as a global variable:

You can name it anything you want to name it, this is just an example.

After you have the class name, you can start filling out the WNDCLASS structure. WNDCLASS is defined as such:

For more information on this structure, see this Microsoft Developer's Network article.

Notice the last data field is a pointer to a string named "lpszClassName"? This is where you point to your class name that you've just defined. The field named "hInstance" is where you supply the instance handle for your program. We will break the rest of the fields up into a few different categories.

The HANDLEs
There are a number of different data types in the WNDCLASS structure that begin with the letter "h". As we remember from our discussion of Hungarian notation, if a variable starts with an "h", the variable itself holds a HANDLE object.

 * HICON hIcon: This is a handle to the icon that your program will use, as located in the top left, and in the taskbar. We will discuss icons more later. However, in our example below, we will use a default value for this item.
 * HCURSOR hCursor: This is a handle to the standard mouse pointer that your window will use. In our example, we will use a default value for this also.
 * HBRUSH hbrBackground: This is a handle to a brush (a brush is essentially a color) for the background of your window. Here is a list of the default colors supplied by Windows (these colors will change depending on what 'theme' is active on your computer):

COLOR_ACTIVEBORDER COLOR_ACTIVECAPTION COLOR_APPWORKSPACE COLOR_BACKGROUND COLOR_BTNFACE COLOR_BTNSHADOW COLOR_BTNTEXT COLOR_CAPTIONTEXT COLOR_GRAYTEXT COLOR_HIGHLIGHT COLOR_HIGHLIGHTTEXT COLOR_INACTIVEBORDER COLOR_INACTIVECAPTION COLOR_MENU COLOR_MENUTEXT COLOR_SCROLLBAR COLOR_WINDOW COLOR_WINDOWFRAME COLOR_WINDOWTEXT

Because of a software issue, a value of 1 must be added to any of these values to make them a valid brush.

Another value that is worth mentioning in here is the "lpszMenuName" variable. lpszMenuName points to a string that holds the name of the program menu bar. If your program does not have a menu, you may set this to NULL.

Extra Fields
There are 2 "extra" data members in the WNDCLASS structure that allow the programmer to specify how much additional space (in bytes) to allocate to the class (cbClsExtra) and to allocate to each specific window instance (cbWndExtra). In case you are wondering, the prefix "cb" stands for "count of bytes".

If you don't know how to use these members, or if you don't want to use them, you may leave both of these as 0. We will discuss these members in more detail later.

Window Fields
There are 2 fields in the WNDCLASS that deal specifically with how the window will operate. The first is the "style" field, which is essentially a set of bitflags that will determine some actions that the system can take on the class. These flags can be bit-wise OR'd (using the | operator) to combine more then one into the style field. The MSDN WNDCLASS documentation has more information.

The next (and arguably most important) member of the WNDCLASS is the lpfnWndProc member. This member points to a WNDPROC function that will control the window, and will handle all of the window's messages.

Registering the WNDCLASS
After the fields of the WNDCLASS structure have been initialized, you need to register your class with the system. This can be done by passing a pointer to the WNDCLASS structure to the RegisterClass function. If the RegisterClass function returns a zero value, the registration has failed, and your system has failed to register a new window class.

Creating Windows
Windows are generally created using the "CreateWindow" function, although there are a few other functions that are useful as well. Once a WNDCLASS has been registered, you can tell the system to make a window from that class by passing the class name (remember that global string we defined?) to the CreateWindow function.

(See this MSDN article for more information.)

The first parameter, "lpClassName" is the string associated with our window class. The "lpWindowName" parameter is the title that will be displayed in the titlebar of our window (if the window has a titlebar).

"dwStyle" is a field that contains a number of bit-wise OR'd flags, that will control window creation.

Window Dimensions
The "x" and "y" parameters specify the coordinates of the upper-left corner of your window, on the screen. If x and y are both zero, the window will appear in the upper-left corner of your screen. "nWidth" and "nHeight" specify the width and height of your window, in pixels, respectively.

The HANDLEs
There are 3 HANDLE values that need to be passed to CreateWindow: hWndParent, hMenu, and hInstance. hwndParent is a handle to the parent window. If your window doesn't have a parent, or if you don't want your windows to be related to each other, you can set this to NULL. hMenu is a handle to a menu, and hInstance is a handle to your programs instance value.

Passing Values to the New Window
To pass a value to the new window, you may pass a generic, LPVOID pointer (a 32-bit value) in the lpParam value of CreateWindow. Generally, it is a better idea to pass parameters via this method than to make all your variables global. If you have more than 1 parameter to pass to the new window, you should put all of your values into a struct, and pass a pointer to that struct to the window. We will discuss this in more detail later.

An Example
Finally, we are going to display a simple example of this process. This program will display a simple window on the screen, but the window won't do anything. This program is a bare-bones program, and it encompasses most of the framework necessary to make any Windows program do anything. Beyond this, it is easy to add more functionality to a program.

-EX members
The Win32 API gains more functionality with each generation, although Microsoft faithfully maintains the API to be almost completely backwards-compatible with older versions of windows. To add more functionally, therefore, Microsoft needed to add new functions and new structures, to make use of new features. An extended version of the WNDCLASS structure is known as the "WNDCLASSEX" structure, which has more fields, and allows for more options. To register a WNDCLASSEX structure, you must use the RegisterClassEx function instead.

Also, there is a version of the CreateWindow function with extended functionality: CreateWindowEx. To learn more about these extensions, you can do a search on MSDN.

Dialog Boxes
Dialog Boxes are special types of windows that get created and managed differently from other windows. To create a dialog box, we will use the CreateDialog, DialogBox, or DialogBoxParam functions. We will discuss these all later. It is possible to create a dialog box by defining a WNDCLASS and calling CreateWindow, but Windows already has all the definitions stored internally, and provides a number of easy tools to work with. For the full discussion, see: Dialog Boxes.

Default Window Classes
There are a number of window classes that are already defined and stored in the Windows system. These classes include things like buttons and edit boxes, that would take far too much work to define manually. Here is a list of some of the pre-made window types:

 * BUTTON: A BUTTON window can encompass everything from a push button to a check box and a radio button. The "title" of a button window is the text that is displayed on a button.
 * SCROLLBAR: SCROLLBAR windows are slider controls that are frequently used on the edge of a larger window to control scrolling. SCROLLBAR types can also be used as slider controls.
 * MDICLIENT: This client type enables Multiple Document Interface (MDI) applications. We will discuss MDI applications in a later chapter.
 * STATIC: STATIC windows are simple text displays. STATIC windows rarely accept user input. However, a STATIC window can be modified to look like a hyperlink, if necessary.
 * LISTBOX, COMBOBOX: LISTBOX windows are drop-down list boxes, that can be populated with a number of different choices that the user can select. A COMBOBOX window is like a LISTBOX, but it can contain complex items.
 * EDIT, RichEdit: EDIT windows allow text input with a cursor. Basic EDIT windows also allow for copy+paste operations, although you need to supply the code to handle those options yourself. RichEdit controls allow for text editing and formatting. Consider an EDIT control being in Notepad.exe, and a RichEdit control being in WordPad.exe.

Menus
There are a number of different menus that can be included in a window or a dialog box. One of the most common (and most important) is the drop-down menu bar that is displayed across the top of a window of a dialog box. Also, many programs offer menus that appear when the mouse is right-clicked on the window. The bar across the top of the window is known as the "Menu Bar", and we will discuss that first. For some information about creating a menu in a resource script, see The Resource Script Reference Page, in the appendix to this book.

Menu Bar: From Resource Script
The easiest and most straightforward method to create a menu is in a resource script. Let's say that we want to make a menu with some common headings in it: "File", "Edit", "View", and "Help". These are common menu items that most programs have, and that most users are familiar with.

We create an item in our resource script to define these menu items. We will denote our resource through a numerical identifier, "IDM_MY_MENU":

IDM_MY_MENU MENU DISCARDABLE BEGIN POPUP "File" POPUP "Edit" POPUP "View" POPUP "Help" END

The keyword POPUP denotes a menu that opens when you click on it. However, let's say that we don't want the "Help" menu item to pop up, but instead we want to click on the word "Help", and immediately open the help window. We can change it as such:

IDM_MY_MENU MENU DISCARDABLE BEGIN POPUP "File" POPUP "Edit" POPUP "View" MENUITEM "Help" END

The MENUITEM designator shows that when we click on "Help", another menu won't open, and a command will be sent to the program.

Now, we don't want to have empty menus, so we will fill in some common commands in the "File" and "Edit" menus, using the same MENUITEM keyword as we used above:

IDM_MY_MENU MENU DISCARDABLE BEGIN POPUP "File" BEGIN MENUITEM "Open" MENUITEM "Save" MENUITEM "Close" END POPUP "Edit" BEGIN MENUITEM "Cut" MENUITEM "Copy" MENUITEM "Paste" END POPUP "View" MENUITEM "Help" END

Now, in the "View" category, we want to have yet another popup menu, that says "Toolbars". When we put the mouse on the "Toolbars" command, a submenu will open to the right, with all our selections on it:

IDM_MY_MENU MENU DISCARDABLE BEGIN POPUP "File" BEGIN MENUITEM "Open" MENUITEM "Save" MENUITEM "Close" END POPUP "Edit" BEGIN MENUITEM "Cut" MENUITEM "Copy" MENUITEM "Paste" END POPUP "View" BEGIN POPUP "Toolbars" BEGIN MENUITEM "Standard" MENUITEM "Custom" END END MENUITEM "Help" END

This is reasonably easy, to start with, except that now we need to provide a method for interfacing our menu with our program. To do this, we must assign every MENUITEM with a command identifier, that we can define in a headerfile. It is customary to name these command resources with an "IDC_" prefix, followed by a short text saying what it is. For instance, for the "File > Open" command, we will use an id called "IDC_FILE_OPEN". We will define all these ID tags in a resource header script later. Here is our menu with all the ID's in place:

IDM_MY_MENU MENU DISCARDABLE BEGIN POPUP "File" BEGIN MENUITEM "Open", IDC_FILE_OPEN MENUITEM "Save", IDC_FILE_SAVE MENUITEM "Close", IDC_FILE_CLOSE END POPUP "Edit" BEGIN MENUITEM "Cut", IDC_EDIT_CUT MENUITEM "Copy", IDC_EDIT_COPY MENUITEM "Paste", IDC_EDIT_PASTE END POPUP "View" BEGIN POPUP "Toolbars" BEGIN MENUITEM "Standard", IDC_VIEW_STANDARD MENUITEM "Custom", IDC_VIEW_CUSTOM END END MENUITEM "Help", IDC_HELP END

When we click on one of these entries in our window, the message loop will receive a WM_COMMAND message, with the identifier in the WPARAM parameter.

We will define all our identifiers in a header file to be numerical values in an arbitrary range that does not overlap with the command identifiers of our other input sources (accelerator tables, push-buttons, etc):

And we will then include this resource header both into our main program code file, and our resource script. When we want to load a menu into our program, we need to create a handle to a menu, or an HMENU. HMENU data items are identical in size and shape to other handle types, except they are used specifically for pointing to menus.

When we start our program, usually in the WinMain function, we will obtain a handle to this menu using an HMENU data item, with the LoadMenu function:

We will discuss how to use this handle to make the menu appear in another section, below.

Menu Bar: Loading a Menu
To associate a menu with a window class, we need to include the name of the menu into the WNDCLASS structure. Remember the WNDCLASS structure:

It has a data field called "lpszMenuName". This is where we will include the ID of our menu:

Remember, we need to use the MAKEINTRESOURCE keyword to convert the numerical identifier (IDM_MY_MENU) into an appropriate string pointer.

Next, after we have associated the menu with the window class, we need to obtain our handle to the menu:

And once we have the HMENU handle to the menu, we can supply it to our CreateWindow function, so that the menu is created when the window is created:

We pass our HMENU handle to the hMenu parameter of the CreateWindow function call. Here is a simple example:

As a quick refresher, notice that we are using default values for all the position and size attributes. We are defining the new window to be a WS_OVERLAPPEDWINDOW, which is a common, ordinary window type. Also the title bar of the window will say "Menu Test Window!". We also need to pass in the HINSTANCE parameter as well, which is the second-to-last parameter.

Next Chapter

 * User Interface Controls

title: Windows Programming/Window Creation


text:
Windows Programming/Dialog Boxes

People are familiar with dialog boxes. They are the grey windows that pop up on Windows systems to display messages, and allow the user to set parameters. There are 3 types of dialog boxes: modeless, modal, and system modal.

 * Modal: Modal dialog boxes are generally used inside a program, to display messages, and to set program parameters. Modal dialog boxes come to the front of the screen, and you may not use the program while the modal dialog box is open. to continue using the program, the modal dialog box must be closed.
 * System Modal: System modal dialog boxes are like modal boxes, except that they supersede the entire desktop area. When a system modal dialog box is open, nothing else on the screen can be clicked or selected.
 * Modeless: Modeless dialog boxes are able to be deselected, and control can be taken away from a modeless dialog box and transferred to some other window. Modeless dialog boxes are frequently used as a fast and easy way to create a window, without having to register a window class. Modeless dialog boxes are common in the Windows control panel.

MessageBox
The most simple type of dialog box is the MessageBox function. The MessageBox function takes 5 parameters: a handle to a parent, a message, a title, and an option. If the parent handle is NULL, the message box is modeless. If you provide a handle for a parent window, the MessageBox can become Modal to the parent window.

MessageBox dialog boxes have a number of different options that can be specified: Button types, Icons, modality (modal/modeless), and text justification. These options are specified as bit flags, that can be used by bitwise ORing them together.

Buttons
Message boxes can have standard OK or Cancel buttons, or they can have a "Yes, No, Cancel" configuration, or a number of derivatives. Only one primary button scheme can be used per message box:
 * MB_ABORTRETRYIGNORE: The message box contains three push buttons: Abort, Retry, and Ignore.
 * MB_CANCELTRYCONTINUE: Same as MB_ABORTRETRYIGNORE, but preferred on Windows 2000/XP.
 * MB_OK: The message box contains an "OK" button. This is the default.
 * MB_OKCANCEL: The message box contains two push buttons: OK and Cancel.
 * MB_RETRYCANCEL: The message box contains two push buttons: Retry and Cancel.
 * MB_YESNO: The message box contains two push buttons: Yes and No.
 * MB_YESNOCANCEL: The message box contains three push buttons: Yes, No, and Cancel.

To display an icon in the message box, specify one of the following values. In addition, a message box can add an additional "Help" button by specifying the "MB_HELP" flag. A "Default Button", a concept that we will see frequently in this chapter, is the button that is automatically selected when a dialog box is opened. Windows provides the ability to set the default button to any of the buttons on a message box, by using the MB_DEFBUTTONx macro. Here is an example:

MessageBox(NULL, "This is a Test", "Test", MB_OKCANCEL|MB_HELP|MB_DEFBUTTON2);

This will have a message box with an "OK", a "Cancel", and a "Help" button, and the "Cancel" button will be automatically selected.

Icons
A message box may have no icons, or it may have one. You shouldn't specify a message box to have multiple icons. The different icons, according to MSDN are:

 * MB_ICONEXCLAMATION: An exclamation point icon appears in the message box.
 * MB_ICONWARNING: An exclamation point icon appears in the message box.
 * MB_ICONINFORMATION: An icon consisting of a lowercase letter i in a circle appears in the message box.
 * MB_ICONASTERISK: An icon consisting of a lowercase letter i in a circle appears in the message box.
 * MB_ICONQUESTION: A question mark icon appears in the message box. The question mark message icon is no longer recommended because it does not clearly represent a specific type of message and because the phrasing of a message as a question could apply to any message type. In addition, users can confuse the message symbol question mark with Help information. Therefore, do not use this question mark message symbol in your message boxes. The system continues to support its inclusion only for backward compatibility.
 * MB_ICONSTOP: A stop sign icon appears in the message box.
 * MB_ICONERROR: A stop sign icon appears in the message box.
 * MB_ICONHAND: A stop sign icon appears in the message box.

Modality
Finally, the MessageBox can be defined as being Modal, Modeless, or System Modal, by using another identifier: MB_APPLMODAL, MB_SYSTEMMODAL, or MB_TASKMODAL. MB_APPLMODAL is the default value, and only works if a parent window handle was specified to the function. There are a number of other options available, check out MSDN for more details.

Dialog Box Procedures
Dialog box procedures are slightly different from window procedures. Specifically, they return BOOL values, instead of LRESULT values. Also, dialog boxes do not have a default message processing function, because messages don't always need to be handled. Specifically, Windows manages dialog boxes, and Windows will handle the unused messages. If a dialog box processes a certain message, it should return TRUE. If the message is not processed, the function should return FALSE. Also, Dialog boxes do not get a WM_CREATE message, but instead get a WM_INITDIALOG message. Furthermore, when a dialog box has finished its business, it should call the EndDialog function.

Here is an example of a skeleton dialog box function:

BOOL CALLBACK MyDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) {   switch(msg) {       case WM_INITDIALOG: return TRUE; case WM_DESTROY: EndDialog(hDlg, 0); return TRUE; }   return FALSE; }

Creating Modal Dialog Boxes
Once a dialog box procedure has been defined, a dialog box can be created by calling either the DialogBox or DialogBoxParam function. These functions return an NRESULT value, that is the integer number passed to the EndDialog function in the dialog box procedure.

The DialogBox function will not return until the dialog box is closed. This means, essentially, that the program is frozen in time until we close the dialog box. The DialogBox function requires 2 handles: the module instance handle and the handle of the parent window. Also, the DialogBox function requires that a string be passed naming the resource where the dialog box is defined. The last argument to DialogBox is a pointer to the dialog box procedure function, that you have already defined.

To pass a parameter to a dialog box, the function DialogBoxParam can be used. DialogBoxParam has all the same parameters as the regular version, except it takes a fifth argument as a 32-bit pointer. This 32 bit value will be passed as the LPARAM element of the WM_INITDIALOG message.

Indirect Dialog Boxes
DialogBox and DialogBoxParam both require that the dialog box be defined in a resource. However, if you want to make the dialog box on the fly, you can use the DialogBoxIndirect or the DialogBoxIndirectParam functions. When defining a dialog box indirectly, we need to fill out a DLGTEMPLATE structure, and pass a pointer to that structure to the function, in place of a resource identifier. The DLGTEMPLATE contains fields for determining some of the characteristics of the dialog box, such as the dimensions and screen location.

The DLGITEMTEMPLATE structure is used to define individual dialog box items. For more information on this subject, search MSDN.

Creating Modeless Dialog Boxes
Modeless dialog boxes are a breed of a different color, and are more like windows than dialog boxes. First, we need to modify the message loop, to ensure that dialog box messages are routed correctly:

while(GetMessage(&msg, NULL, 0, 0)) {   if(!IsDialogMessage(hDlg, &msg)) {       TranslateMessage(&msg); DispatchMessage(&msg); } }

Now, there are 2 ways we can define a message box in a resource script, with a class or without. We will discuss each in turn.

Without Class
We can define a dialog box in a resource script with the DIALOG keyword. The resource will have an ID associated with it (either a number or a string), and this ID can be passed directly to the CreateDialog function.

With Class
If we want to define a modeless dialog box in terms of a window class, we can use a few additions to make the job easier. First, we create a WNDCLASS structure with the information about our dialog box. However, there is one difference, in that we must set the cbWndExtra field to the value DLGWINDOWEXTRA value:

wnd.cbWndExtra = DLGWINDOWEXTRA;

Then, we register the class like normal. Since we are registering our window classes like normal windows, it shouldn't come as a surprise that Modeless dialog boxes use a regular window procedure, and not a dialog box procedure. Now, Windows identifies classes by name, so we should remember the name of our class. Let's say we named our class "MyDlgClass". We could create a dialog box resource as such:

MYDLGCLASS DIALOG DISCARDABLE 100, 100, 200, 200 CAPTION "My Dialog Box" CLASS "MyDlgClass" FONT 8, "MS Sans Serif" BEGIN ... END

Notice the field that says "CLASS"? This is the same string that we used in our WNDCLASS structure to name the class. It is important that these two strings be identical, because Windows needs this string to link the WNDCLASS and the dialog box resource together. Notice also that we used the string "MYDLGCLASS" to identify the dialog resource. This isn't mandatory, but it does make things convenient later on.

Now, instead of calling CreateWindow, we will call the easier-to-use function CreateDialog. We do not use the DialogBox function, because CreateDialog returns immediately, and doesn't halt program execution.

Here is an example:

HWND hDlg; hDlg = CreateDialog(hInst, "MyDlgClass", hwndParent, MyDlgProc);

Here, we are saying that "hInst" is the instance handle of the application, and "hwndParent" is the handle to the parent window of our dialog box. If the hwndParent parameter is NULL, the dialog box won't have a parent. When the modeless dialog box is finished, it calls "DestroyWindow", not "EndDialog", like a modal dialog box would.

Common Dialog Boxes
The Common Dialogs is a library of functions that automatically produce some of the most common dialog boxes in Windows. This is an effort to make some amount of continuity between different programs, so that each different program doesn't create its own proprietary "File Open" dialog, for instance.

Each Common Dialog generally has a single function that takes a pointer to a structure. This structure is defined specifically for each different control. The common controls can be added to a project by including the  header file, and linking to the comdlg32.dll library.

Some of the common controls available through this library are the "Choose Font" dialog box, the "File open" and "File save" boxes, and the "Color Palette" dialog box.

MSDN

ChooseColor
The ChooseColor function brings up the color palette window, and returns a 32-bit color value to your program.

BOOL ChooseColor(LPCHOOSECOLOR lpcc);

ChooseColor takes a single argument, in the form of a pointer to a CHOOSECOLOR structure. This structure is initialized with various values, and when the function returns, the CHOOSECOLOR structure contains the color value code.

GetOpenFileName and GetSaveFileName
These two functions bring up the familiar file open and file save dialog boxes that are found in nearly every Windows application.

BOOL GetOpenFileName(LPOPENFILENAME lpofn); BOOL GetSaveFileName(LPOPENFILENAME lpofn);

Both of these functions take a pointer to an OPENFILENAME structure. This structure controls such things as the file extensions that may be loaded, and the starting path to look in. When the function returns, the structure will contain the name of the file selected. Once your program has this information, you can use the File I/O API to access the file.

ChooseFont
The ChooseFont function brings up a familiar dialog box that allows the user to select a font and various font attributes such as size, underline/bold/italics, color, etc. This function takes a pointer to a CHOOSEFONT structure.

BOOL ChooseFont(LPCHOOSEFONT lpcf);

Dialog Box Resources
Dialog boxes can be specified in a resource script, to handle the tricky task of creating all the various child windows (buttons and editboxes, etc.) that a dialog box may contain. This process is described in detail in the Resource Script Reference in the appendix. Here, we will discuss some of the basics of using a resource script to define a dialog box.

The DIALOG keyword
A dialog box resource is specified with the DIALOG (must be all caps) keyword. The DIALOG keyword is preceded by the resource identifier, and is followed by a series of dimension values: ID_DLGBOX DIALOG X, Y, CX, CY

X and Y are the location coordinates of the upper-left corner of the dialog box, in relation to the upper-left corner of the screen. Remember, all the coordinates start at (0,0) in the upper-left hand corner. The next set of numbers, CX and CY, are the dimensions of the dialog box. These dimensions do not include the title bar (if any), so setting your Y value to 0 will make a dialog box that is only a title bar. +---> X      ["DialogBox"   [_][O][x]] +  |                       |   |   |                       |   |   |                       |   |   |                       |   |   |                       |   |   |                       |   v   |                       | Y  |                       | |                      |       |                       |       |                       |        +---+

After the DIALOG declaration, there are a number of other fields that can be filled in, to provide information about your dialog box:

ID_DLGBOX DIALOG 100, 100, 200, 150 STYLE WS_OVERLAPPED | WS_CAPTION | WS_VISIBLE CAPTION "Title Bar Text" FONT 8, "MS Sans Serif" The STYLE declaration contains all the window styles, bitwise OR'd, that you would have used in the WNDCLASS structure, or in the style field of the CreateWindow function. All the same values are available. The CAPTION is the title of the dialog box. The FONT is the point-size and the TrueType font to be used on all the surfaces of the dialog box. Any font and size can be specified, although if the font is too big, your dialog box will be very annoying.

Now, once we have our dialog box sized and shaped the way we want it, we can start to fill it with control buttons and edit boxes, and all sorts of other goodies. First, we use the BEGIN and END tags:

ID_DLGBOX DIALOG 100, 100, 200, 150 STYLE WS_OVERLAPPED | WS_CAPTION | WS_VISIBLE CAPTION "Title Bar Text" FONT 8, "MS Sans Serif" BEGIN ... END

Next, we can start to fill in the dialog box with buttons, checkboxes, or whatever we want, using the following format:

ID_DLGBOX DIALOG 100, 100, 200, 150 STYLE WS_OVERLAPPED | WS_CAPTION | WS_VISIBLE CAPTION "Title Bar Text" FONT 8, "MS Sans Serif" BEGIN PUSHBUTTON "OK", IDOK,      10, 10, 50,  15, WS_TABSTOP CHECKBOX "Box 1", IDC_CB1,  10, 30, 50,  15, WS_TABSTOP EDITTEXT         IDC_EDIT1, 10, 50, 100, 100 END

After the declaration, you may optionally include one or more style flags, to specify how you want a particular control to appear. The WS_TABSTOP identifier specifies which controls can be selected when you press the TAB key on the keyboard. When you press the TAB key, control switches among the dialog box controls in the same order that they are specified in the resource script (top to bottom).

Next Chapter

 * Input/Output

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

title: Windows Programming/Dialog Boxes


text:
Statistics/Numerical Methods/Numerical Comparison of Statistical Software

Introduction
Statistical computations require extra accuracy and are open to errors such as truncation and cancellation error. These errors occur as a result of binary representation and finite precision and may cause inaccurate results. In this work we are going to discuss the accuracy of statistical software, different tests and methods available for measuring the accuracy and the comparison of different packages.

Accuracy of Software
Accuracy can be defined as the correctness of the results. When a statistical software package is used, it is assumed that the results are correct in order to comment on these results. However, it must be accepted that computers have some limitations. The main problem is that the available precision typically provided by computer systems is limited. It is clear that statistical software can not deliver such accurate results, which exceed these limitations. However statistical software should recognize its limits and give clear indication that these limits are reached. We have two types of precision generally used today:
 * Single precision
 * Double precision

Binary Representation and Finite Precision
Binary representation and finite precision cause inaccuracy NIKHIL. Computers don’t have real numbers -- we represent them with a finite approximation.

Example: Assume that we want to represent 0.1 in single precision floating point. The result will be as follows:

0.1 = .00011001100110011001100110 = 0.99999964 (McCullough,1998)

It is clear that we can only approximate to 0.1 in binary form. This problem grows, if we try to subtract two large numbers which differ only in the lowest precision digits. For instance 100000.1-100000 = .09375

With single precision floating point we can only represent 24 significant binary digits, in other words 6-7 decimal digits. In double precision it is possible to represent 53 significant binary digits equivalent to 15-17 significant decimal digits. Limitations of binary representation create five distinct numerical ranges, which cause loss of accuracy: Overflow means that values have grown too large for the representation. Underflow means that operands are so small and so close to zero that the result must be set to zero. Single and double precision representations have different ranges.
 * negative overflow
 * negative underflow
 * zero
 * positive underflow
 * positive overflow

Results of Binary Representation
These limitations cause different errors in different situations:
 * Cancellation errors result from subtracting two nearly equal numbers.
 * Accumulation errors are successive rounding errors in a series of calculations summed up to a total error. In this type of error it is possible that only the rightmost digits of the result are affected or that the result has no single accurate digits.
 * Another result of binary representation and finite precision is that two formulas which are algebraically equivalent may not be equivalent numerically. For instance:

 * $$\sum_{n=1}^{10000} n^{-2}$$   $$\sum_{n=1}^{10000} (10001-n)^{-2}$$

The first formula adds the numbers in ascending order, whereas the second adds them in descending order. In the first formula the smallest numbers are reached at the very end of the computation, so that these numbers are all lost to rounding error. The error is 650 times greater than the second.(McCullough,1998) Example:
 * Truncation errors are approximation errors which result from the limitations of binary representation.

 * $$\sin x = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \cdots$$

The difference between the true value of sin(x) and the result achieved by summing up finite number of terms is the truncation error. (McCullough,1998)

 * Algorithmic errors are another source of inaccuracies. There can be different ways of calculating a quantity and these different methods may vary in accuracy. For example according to Sawitzki (1994) in a single precision environment using the following formula in order to calculate variance :

 * $$S^2 = (1/(1-n)(\sum x_i^2 - n \bar x^2))$$

Measuring Accuracy
Due to limits of computers some problems occur in calculating statistical values. We need a measure which shows us the degree of accuracy of a computed value. This measurement is based on the difference between the computed value (q) and the real value (c). An often used measure is Log Relative Error or LRE (the number of the correct significant digits)(McCullough,1998)

 * $$LRE = -\log_{10} {\left[ |q-c|/|c| \right]}$$

Rules:
 * q should be close to c (by less than 2 digits). If they are not, set LRE to zero
 * If LRE is greater than number of the digits in c, set LRE to number of the digits in c.
 * If LRE is less than unity, set it to zero.

Testing Statistical Software
In this part we are going to discuss two different tests which aim to measure the accuracy of the software: Wilkinson Test (Wilkinson, 1985) and NIST StRD Benchmarks.

Wilkinson's Statistic Quiz
The Wilkinson dataset “NASTY” which is employed in Wilkinson’s Statistic Quiz is a dataset created by Leland Wilkinson (1985). This dataset consists of different variables such as “Zero” which contains only zeros, “Miss” with all missing values, etc. NASTY is a reasonable dataset in the sense of values it contains. For instance the values of “Big” in “NASTY” are less than U.S. Population, and “Tiny” is comparable to many values in engineering. On the other hand the exercises of the “Statistic Quiz” are not meant to be reasonable. These tests are designed to check some specific problems in statistical computing. Wilkinson’s Statistics Quiz is an entry level test.

NIST StRD Benchmarks
These benchmarks consist of different datasets designed by National Institute of Standards and Technology with different levels of difficulty. The purpose is to test the accuracy of statistical software with regard to different topics in statistics and different levels of difficulty. In the webpage of “Statistical Reference Datasets” Project there are five groups of datasets: In all groups of benchmarks there are three different types of datasets: Lower level difficulty datasets, average level difficulty datasets and higher level difficulty datasets. By using these datasets we are going to explore whether the statistical software deliver accurate results to 15 digits for some statistical computations.
 * Analysis of Variance
 * Linear Regression
 * Markov Chain Monte Carlo
 * Nonlinear Regression
 * Univariate Summary Statistics

There are 11 datasets provided by NIST among which there are six datasets with lower level difficulty, two datasets with average level difficulty and one with higher level difficulty. Certified values to 15 digits for each dataset are provided for the mean (μ), the standard deviation (σ), and the first-order autocorrelation coefficient (ρ).

In the group of ANOVA-datasets there are 11 datasets with levels of difficulty, four lower, four average and three higher. For each dataset certified values to 15 digits are provided for between treatment degrees of freedom, within treatment degrees of freedom, sums of squares, mean squares, the F-statistic, the $$R^2$$, and the residual standard deviation. Since most of the certified values are used in calculating the F-statistic, only its LRE $$\lambda_F$$ will be compared to the results from statistical software packages.

For testing the linear regression results of statistical software NIST provides 11 datasets with levels of difficulty two lower, two average and seven higher. For each dataset we have the certified values to 15 digits for coefficient estimates, standard errors of coefficients, the residual standard deviation, $$R^2$$, the analysis of variance for linear regression table, which includes the residual sum of squares. LREs for the least accurate coefficients $$\lambda_\beta$$, standard errors $$\lambda_\sigma$$ and Residual sum of squares $$\lambda_r$$ will be compared. In nonlinear regression dataset group there are 27 datasets designed by NIST with difficulty eight lower, eleven average and eight higher. For each dataset we have certified values to 11 digits provided by NIST for coefficient estimates, standard errors of coefficients, the residual sum of squares, the residual standard deviation, and the degrees of freedom.

In the case of calculation of nonlinear regression we apply curve fitting method. In this method we need starting values in order to initialize each variable in the equation. Then we generate the curve and calculate the convergence criterion (e.g. sum of squares). Then we adjust the variables to make the curve closer to the data points. There are several algorithms for adjusting the variables: One of these methods is applied repeatedly, until the difference in the convergence criterion is smaller than the convergence tolerance.
 * The method of Marquardt and Levenberg
 * The method of linear descent
 * The method of Gauss-Newton

NIST provides also two sets of starting values: Start I (values far from solution), Start II (values close to solution). Having Start II as initial values makes it easier to reach an accurate solution. Therefore Start I solutions will be preferred.

Other important settings are as follows: We can also choose between numerical and analytic derivatives.
 * the convergence tolerance (ex. 1E-6)
 * the method of solution (ex. Gauss Newton or Levenberg Marquardt)
 * the convergence criterion (ex. residual sum of squares (RSS) or square of the maximum of the parameter differences)

Testing Software Package: SAS, SPSS and S-Plus
In this part we are going to discuss the test results of three statistical software packages applied by M.D. McCullough. In McCullough’s work SAS 6.12, SPSS 7.5 and S-Plus 4.0 are tested and compared in respect to certified LRE values provided by NIST. Comparison will be handled according to the following parts:
 * Univariate Statistics
 * ANOVA
 * Linear Regression
 * Nonlinear Regression

Univariate Statistics

All values calculated in SAS seem to be more or less accurate. For the dataset NumAcc1 p-value can not be calculated because of the insufficient number of observations. Calculating standard deviation for datasets NumAcc3 (average difficulty) and NumAcc 4 (high difficulty) seems to stress SAS.

All values calculated for mean and standard deviation seem to be more or less accurate. For the dataset NumAcc1 p-value can not be calculated because of the insufficient number of observations. Calculating the standard deviation for datasets NumAcc3 and -4 seems to stress SPSS, as well. For p-values SPSS represents results with only 3 decimal digits which understates the accuracy of the first p-value and overstates the last.

All values calculated for mean and standard deviation seem to be more or less accurate. S-Plus also hs problems in calculating the standard deviation for datasets NumAcc3 and -4. S-Plus shows poor performance in calculating the p-values.

Analysis of Variance

Results:
 * SAS can solve only the ANOVA problems of lower level difficulty.
 * F-Statistics for datasets of average or higher difficulty can be calculated with very poor performance and zero digit accuracy.
 * SPSS can display accurate results for datasets with lower level difficulty, like SAS.
 * Performance of SPSS in calculating ANOVA is poor.
 * For dataset “AtmWtAg” SPSS displays no F-Statistic which seems more logical instead of displaying zero accurate results.
 * S-Plus handles ANOVA problem better than other software packages.
 * Even for higher difficulty datasets S-Plus can display more accurate results than the others. But still results for datasets with high difficulty are not accurate enough.
 * S-Plus can solve the average difficulty problems with sufficient accuracy.

Linear Regression

SAS delivers no solution for dataset Filip which is a ten degree polynomial. Apart from Filip, SAS displays more or less accurate results. But the performance seems to decrease for higher difficulty datasets, especially in calculating coefficients.

SPSS has also Problems with “Filip” which is a 10 degree polynomial. Many packages fail to compute values for it. Like SAS, SPSS delivers lower accuracy for high level datasets.

S-Plus is the only package which delivers a result for dataset “Filip”. The accuracy of the result for Filip seems not to be poor but average. Even for higher difficulty datasets S-Plus can calculate more accurate results than other software packages. Only coefficients for datasets “Wrampler4” and “-5” are under the average accuracy.

Nonlinear Regression

For the nonlinear regression, two setting combinations are tested for each software package, because different settings make a difference in the results. As we can see in the table in SAS preferred combination produce better results than the default combination. In this table results produced using the default combination are in parentheses. Because 11 digits are provided for certified values by NIST, we are looking for LRE values of 11.

Preferred combination :
 * Method:Gauss-Newton
 * Criterion: PARAM
 * Tolerance: 1E-6

Also in SPSS the preferred combination shows a better performance than default options. All problems are solved with initial values “start I” whereas in SAS higher level datasets are solved with Start II values.

Preffered Combination:
 * Method:Levenberg-Marquardt
 * Criterion:PARAM
 * Tolerance: 1E-12

As we can see in the table, the preferred combination is also better in S-Plus than default the combination. All problems except “MGH10” are solved with initial values “start I”. We may say that S-Plus showed better performance than other software in calculating nonlinear regression.

Preferred Combination:
 * Method:Gauss-Newton
 * Criterion:RSS
 * Tolerance: 1E-6

Results of the Comparison
All packages delivered accurate results for mean and standard deviation in univariate statistics. There are no big differences between the tested statistical software packages. In ANOVA calculations SAS and SPSS can not pass the average difficulty problems, whereas S-Plus delivered more accurate results than others. But for high difficulty datasets it also produced poor results. Regarding linear regression problems, all packages seem to be reliable. If we examine the results for all software packages, we can say that the success in calculating the results for nonlinear regression greatly depends on the chosen options.

Other important results are as follows:
 * S-Plus solved from Start II one time.
 * SPSS never used Start II as initial values, but once produced zero accurate digits.
 * SAS used Start II three times and produced zero accurate digits each time.

Comparison of different versions of SPSS
In this part we are going to compare an old version with a new version of SPSS in order to see whether the problems in older version are solved in the new one. In this part we compared SPSS version 7.5 with SPSS version 12.0. LRE values for version 7.5 are taken from an article by B.D. McCullough (see references). We also applied these tests to version 12.0 and calculated regarding LRE values. We chose one dataset from each difficulty groups and applied univariate statistics, ANOVA and linear regression in version 12.0. The source for the datasets is NIST Statistical Reference Datasets Archive. Then we computed LRE values for each dataset by using the certified values provided by NIST in order to compare the two versions of SPSS.

Univariate Statistics
Difficulty: Low

Our first dataset is PiDigits with lower level difficulty which is designed by NIST in order to detect the deficiencies in calculating univariate statistical values. Certified Values for PiDigits are as follows:
 * Sample Mean : 4.53480000000000
 * Sample Standard Deviation : 2.86733906028871

As we can see in the table 13 the results from SPSS 12.0 match the certified values provided by NIST. Therefore our LREs for mean and standard deviation are $$\lambda_\mu$$: 15, $$\lambda_\delta$$: 15. In version 7.5 LRE values were $$\lambda_\mu$$: 14.7, $$\lambda_\delta$$: 15. (McCullough,1998)

Difficulty: Average

Second dataset is NumAcc3 with average difficulty from NIST datasets for univariate statistics. Certified Values for NumAcc3 are as follows:
 * Sample Mean : 1000000.2
 * Sample Standard Deviation : 0.1

In the table 14 we can see that calculated mean value is the same with the certified value by NIST. Therefore our LREs for mean is $$\lambda_\mu$$: 15. However the standard deviation value differs from the certified value. So the calculation of LRE for standard deviation is as follows:

$$\lambda_\delta$$ : -log10 |0,10000000003464-0,1|/|0,1| = 9.5

LREs for SPSS v 7.5 were $$\lambda_\mu$$: 15, $$\lambda_\delta$$: 9.5. (McCullough,1998)

Difficulty: High

Last dataset in univariate statistics is NumAcc4 with high level of difficulty. Certified Values for NumAcc4 are as follows:
 * Sample Mean : 10000000.2
 * Sample Standard Deviation : 0.1

Also for this dataset we do not have any problems with computed mean value. Therefore LRE is $$\lambda_\mu$$: 15. However the standard deviation value does not match to the certified one. So we should calculate the LRE for standard deviation as follows:

$$\lambda_\delta$$ : -log10 |0,10000000056078-0,1|/|0,1| = 8.3

LREs for SPSS v 7.5 were $$\lambda_\mu$$: 15, $$\lambda_\delta$$ : 8.3 (McCullough,1998)

For this part of our test we can say that there is no difference between two versions of SPSS. For average and high difficulty datasets delivered standard deviation results have still an average accuracy.

Analysis of Variance
Difficulty: Low

The dataset which we used for testing SPSS 12.0 regarding lower difficulty level problems is SiRstv. Certified F Statistic for SiRstv is 1.18046237440255E+00

 * LRE : $$\lambda_F$$: -log10 | 1,18046237440224- 1,18046237440255|/ |1,18046237440255| = 12,58
 * LRE for SPSS v 7.5 : $$\lambda_F$$ : 9,6 (McCullough, 1998)

Difficulty: Average

Our dataset for average difficulty problems is AtmWtAg. Certified F statistic value for AtmWtAg is 1.59467335677930E+01.

 * LREs : $$\lambda_F$$ : -log10 | 15,9467336134506- 15,9467335677930|/| 15,9467335677930| = 8,5
 * LREs for SPSS v 7.5 : $$\lambda_F$$: miss

Difficulty: High

We used the dataset SmnLsg07 in order to test high level difficulty problems. Certified F value for SmnLsg07 is 2.10000000000000E+01

 * LREs : $$\lambda_F$$ : -log10 | 21,0381922055595 - 21|/| 21| = 2,7
 * LREs for SPSS v 7.5 : $$\lambda_F$$: 0

ANOVA results computed in version 12.0 are better than those calculated in version 7.5. However the accuracy degrees are still too low.

Linear Regression
Difficulty: Low

Our lower level difficulty dataset is Norris for linear regression. Certified values for Norris are as follows:
 * Sample Residual Sum of Squares : 26.6173985294224
 * [[Image:coefnorris.jpg|center|thumb|550px|Table 17: Coefficient estimates for Norris(www.itl.nist.gov)]]
 * LREs : $$\lambda_r$$ : 9,9 $$\lambda_\beta$$ : 12,3  $$\lambda_\sigma$$ : 10,2
 * LREs for SPSS v 7.5 : $$\lambda_r$$: 9,9, $$\lambda_\beta$$ : 12,3 , $$\lambda_\sigma$$ : 10,2 (McCullough, 1998)

Difficulty: Average

We used the dataset NoInt1 in order to test the performance in average difficulty dataset. Regression model is as follows:

y = B1*x + e

Certified Values for NoInt1 :
 * Sample Residual Sum of Squares : 127,272727272727
 * Coefficient estimate : 2.07438016528926, standard deviation : 0.16528925619834E-0(www.itl.nist.gov)
 * LREs: $$\lambda_r$$:12,8  $$\lambda_\beta$$: 15   $$\lambda_\sigma$$: 12,9
 * LREs for SPSS v. 7.5 : $$\lambda_r$$: 12,8, $$\lambda_\beta$$: 14,7 , $$\lambda_\sigma$$: 12,5 (McCullough, 1998)

Difficulty: High

Our high level difficulty dataset is Longley designed by NIST.
 * Model: y =B0+B1*x1 + B2*x2 + B3*x3 + B4*x4 + B5*x5 + B6*x6 +e
 * LREs :
 * $$\lambda_r$$: -log10 |836424,055505842-836424,055505915|/ |836424,055505915| = 13,1
 * $$\lambda_\beta$$ : 15
 * $$\lambda_\sigma$$ : -log10 | 0,16528925619836E-01 – 0,16528925619834E-01|/ |0,16528925619834E-01| = 12,9
 * LREs for SPSS v. 7.5 : $$\lambda_r$$: 12,8, $$\lambda_\beta$$ : 14,7 , $$\lambda_\sigma$$ : 12,5 (McCullough, 1998)

As we conclude from the computed LREs, there is no big difference between the results of two versions for linear regression.

Conclusion
By applying these test we try to find out whether the software are reliable and deliver accurate results or not. However based on the results we can say that different software packages deliver different results for same the problem which can lead us to wrong interpretations for statistical research questions.

In specific we can that SAS, SPSS and S-Plus can solve the linear regression problems better in comparision to ANOVA Problems. All three of them deliver poor results for F statistic calculation.

From the results of comparison two different versions of SPSS we can conclude that the difference between the accuracy of the results delivered by SPSS v.12 and v.7.5 is not great considering the difference between the version numbers. On the other hand SPSS v.12 can handle the ANOVA Problems much better than old version. However it has still problems in higher difficulty problems.


text:
Introduction to Library and Information Science/Information Policy

Librarians are far from the only players in today's Information Age. A huge number of people and organizations have a say in how information is created, used, stored, accessed, and disseminated. Each of these parties is influenced by widely divergent goals, world views, and professional ethics.

These divergent viewpoints often come to the fore in debates over Information Policy. An information policy is a public law, regulation or policy that encourages, discourages, or regulates the creation, use, storage, access, and communication and dissemination of information.

Librarians and other information workers are often involved in creating and transforming information policy, and invariably feel the effects of these policies. This chapter will discuss a number of Information Policy debates of particular interest to the LIS community.

After reading this chapter, students should be able to articulate how libraries
 * 1) are governed and funded
 * 2) establish and uphold policies
 * 3) develop collection development policies
 * 4) defend access to information in both physical and electronic media
 * 5) navigate restrictions from copyright law
 * 6) protect patron confidentiality
 * 7) navigate policy exceptions
 * 8) establish fine and fee structures
 * 9) make decisions regarding staff tasks and responsibilities

Collection development
Collection development is the process of planning and building a useful and balanced collection of library materials. Collection development policies provide guidelines for people who select Information resources for library collections, and can also be used to evaluate selectors' choices, to see if they were indeed appropriate for the library's collection.

Public libraries particularly face a "quality vs. demand" problem. Librarians are experts in book selection, and have tools, such as professional reviews, to guide them in choosing good books for their collections. However, this does not always mean that their selections are popular with their patrons.

The tension between "quality" and "demand" is often discussed in reference to the case of the Baltimore County Public Library's approach to collection development from the 1980s. When the library considered the fees they were paying to convert to online records, they began to wonder if every item was earning its keep. They checked circulation statistics for each item. Material that didn't circulate frequently enough was withdrawn. More attention was paid to areas of the collection that circulated well. More copies of bestsellers were purchased.

This approach was criticized as not being actual collection development, but just mindless reading of statistics. In an article for Library Journal, Nora Rawlinson, then head of materials selection at Baltimore County Public Library, admitted that it is easy to select popular items, but other material is carefully considered before being purchased for the collection. Esoteric material is rejected and fair service to patrons is considered when selecting. The diverse interests of their patrons can be met because they reduced staff and increased the book budget. The approach was successful: surveys showed that patrons were satisfied, and the library received a significant number more interlibrary loan requests than it made. The fears that the library would devolve into a collection stuffed with bestsellers and little material of real value were unfounded.

Although these collection practices were originally controversial for some libraries, Baltimore County's choice to use a combination of popularity (as represented by circulation statistics) and professional judgement has been widely adopted by many public libraries.

Confidentiality
The 2001 USA PATRIOT Act has changed how the United States Federal Government can obtain information. The Federal Bureau of Investigation has used the act to ask libraries which books patrons checked out, what databases patrons used, and what reference questions they asked. Ultimately, it requires a court order for libraries to turn over such records and information about patrons. A court decision in Colorado ruled that an adversarial hearing was allowed before a search warrant could be enacted. The PATRIOT ACT permits surveillance, allows for searches without probable cause, and enforces secrecy. All the FBI has to assert in its investigation is that terrorism is involved.

Library staff members should keep in mind that they should not turn over records to anyone without a warrant. In an article for Library Journal, Mary Minow suggests that all libraries have a plan involving staff training, supervising, having a lawyer present if a warrant has been issued, and procedures for handling the requests for information. Is library patron record privacy trivial compared to stopping terrorism? Several organizations asked for an account by the Department of Justice of the investigations carried out by the FBI since the passing of the Patriot Act. At the time of Minow's article, the information requested was termed "classified" and not available to the public.

Control of information
This editorial states the situation of three specific libraries in Ohio whose hazardous materials emergency plans were removed without notice and without due cause by agents of the Department of Homeland Security. The pretense given by the agents in viewing the plans was that they were there to update it; instead, they took the plans to be stored at a Homeland Security office, where “proper ID may be required” for viewing. Since the areas affected were at risk for terrorist activities in that there was an oil refinery and a tank manufacturing plant in the area, the affected librarians did not necessarily take offense to the removal of these documents given the political climate, but rather the way the information was unceremoniously taken from them.

To remove information that could be vital to some, yet be used as a dangerous tool by others walks a fine line between looking out for the public good and censorship. The Department of Homeland Security manhandled this situation by treating the librarians, and indirectly their patrons, as bothersome pests because of a need to possess information. In the class discussions, the topic of information as a commodity always comes to the issue of who should control information. All parties involved have their own agenda, and in this case the government may have cloaked their desire to remove potentially damaging environmental data under the guise of preventing another terrorist attack.

Copyright
How does copyright apply to libraries?
 * Libraries are often the only entities that provide access to the vast majority of copyrighted works before the expiration of the copyright, and to works that lose commercial vitality before the copyright expires (i.e. go out of print but are still legally protected).
 * First sale doctrine (1908) enables libraries to lend books and other resource
 * Except software gets dicier, because of End-user license agreements (EULAs)
 * Fair use allows for the use of (usually tiny snippets of) copyrighted works for purposes of criticism, comment, news reporting, scholarship, or research.
 * Libraries are permitted to make reproductions of copyrighted works for preservation and replacement purposes.
 * Libraries can aid in the transformation and reproduction of copyrighted works for users with disabilities.
 * Libraries often play an archival function with print works. Can they do this in the highly copyrighted, license-agreemented world of electronic information?  Electronic resources tend to have a very short shelf life, and may not be archived properly for future use.
 * Digital Rights Management technologies often don't recognize any limitations to copyright, and just go ahead and restrict access.

The Teach Act helps redefine the terms and conditions of copyright laws, focusing on copyright protected materials in distance education. The act puts more pressure on the educational institution, rather than the educator; but there are several benefits because of the Teach Act: expanded range of allowed works, expansion of receiving locations, storage of transmitted content, and digitizing of analog works. It is important for educators to be aware of copyright information, the number of students enrolled in class, and the amount of time allotted to view the material. If they are cognizant of them, they will not have to worry about breaking the law. Since distance education is growing, librarians are expected to deal with interlibrary loans more often, amongst other new opportunities, and need to understand the Teach Act too. Kenneth brings up several points that are essential to remember about the Teach Act. Distance learning is growing rather quickly, and is becoming more popular amongst the student population. Because of this rapid growth, librarians are asked to perform several new tasks that coincide with the act. Librarians need to be familiar with the Teach Act, so no laws are broken, and all materials remain protected.

Digital Rights Management
In this editorial the authors propose that libraries must be involved in the development of digital rights management policies and the selection and implementation of appropriate technologies, because the interests of libraries are different from the interests of commercial information providers. The core mission of libraries is to offer free access to information rather than on a pay-per-use basis as many commercial entities do. Digital rights management for libraries requires identifying and authenticating rights holders and users, while protecting their privacy and confidentiality. The principles of first sale and fair use must be maintained in the digital environment while preserving authors’ rights, as well. As libraries begin to publish more on the web, their interest in digital rights management will increase.

Libraries already offer many products in a digital form accessible to patrons by remote access after identification and authentication. While the library bears the expense of the product, access is open to anyone who has a valid card. In my opinion, the user identifies this service with the library. I agree that libraries need to be involved in digital rights management so information does not become a commodity that can be accessed only by those who can afford it.

International information policy
This article provides a historical perspective on the development of international policies and sanctions regarding the fair and safe trade of information between countries. During the internet’s infancy, the issues regarding keeping privileged information confidential and regulation the economic aspects of electronic information were still being worked out. One of the bodies involved in these issues was called the Organization for Economic Cooperation and Development (OECD). When this editorial article was written in 1985 ways to control and regulate the international flow of information were still being worked out. This article only provides a small glimpse of the issue from a modern vantage point. One would assume that today, more than twenty years later that regulations would now be firmly in place. In order to get a better idea of the evolution of international information policy it would be necessary to read several articles that span the past two decades.

Outsourcing
In recent years, many libraries have explored outsourcing "behind-the-scenes" activities, such as cataloging and book selection, to private companies. A classic example of this was a 1996 decision by Bartholomew Kane, the Hawaii State Librarian, to outsource all cataloging and selection for the libraries in the state to the private company Baker and Taylor. Kane's philosophy in this decision was guided by public surveys which showed a public desire for increased library assistance and longer hours of operation. By outsourcing cataloging and selection, Kane was able to meet both of these public demands.

However, this approach also has its drawbacks. For instance, by outsourcing selection and cataloging, the library loses its autonomy in making differentiated selections to suit their individual populations. Although the State Library argued that it would be in Baker and Taylor's best financial interest to select the appropriate materials, the issue is not entirely resolved. For instance, will the selectors at Baker and Taylor have the same interactions with and knowledge of the public that the librarians would have? Additionally, the state of Hawaii is in a unique situation, as the only state with a state-wide library system, and in a state of geographic semi-isolation from the rest of the country. Applying a blanket solution such as outsourcing some of the traditional roles of the public library is not a catch-all solution for all libraries that need to increase their hours and personnel without increasing their bottom line.

Web content filters
Libraries are one of the primary providers of public Internet access within the United States. American librarians are also ethically bound by the ALA's code of ethics to "resist all efforts to censor library resources." Therefore, when the 2000 Children's Internet Protection Act (CIPA) required libraries and schools to filter web content as a condition for receiving certain federal funding, many in the library community strongly objected. The ALA challenged the act as unconstitutionally blocking access to constitutionally protected information on the Internet. The ALA also noted that E-rate funding, one of the federal funding programs contingent on web filter use, was created to provide Internet access to all communities, including historically underfunded communities. Mandating filters imposes additional financial burdens on the same schools and libraries that the e-rate program was meant to help. Finally, the ALA stated that web filters are notoriously unreliable, with "no filtering software successfully differentiat[ing] constitutionally protected speech from illegal speech on the Internet." The case made it to the Supreme Court, which in 2003, ruled that CIPA was in fact constitutional.

The debate over filtering in the library community is far from over, however. Writing in 2004, Nancy Kranich notes seven reasons filters do not succeed in protecting patrons from offensive Internet material:

 * 1) Filters underblock sites that are banned by CIPA
 * 2) Filters overblock sites that are legal
 * 3) Filter providers cannot review every site
 * 4) Filters do not distinguish between users of different ages
 * 5) Overriding or disabling filters is time-consuming and costly
 * 6) Some users find ways around filters or find access elsewhere
 * 7) Filters do not block email, chat rooms or videos

Kranich argues that the best ways to protect consumers are through education, Internet access policies, links to approved, quality sites, and reference assistance. Requiring parental consent for minors to use the Internet, public monitoring, and the use of privacy screens also help protect consumers.

Many in the library community also worried that federal laws such as CIPA could lead the way to even more restrictive laws on the state level. Some libraries filter because violating certain state laws could lead to criminal charges. Most libraries depend on community support and money, so resisting the public’s requests puts libraries’ futures at risk. Would libraries choose filtering if there were no threats of legal action and eliminated funding? If so, what does this say about the ALA’s mission?

However, Hampton Auld takes a different view of filtering. In Auld's article, the Chesterfield County (Virginia) Public Library began filtering all public Internet-access computers after complaints that adults and children were viewing pornographic images. The library observed a reduction in the number of times pornography had to be cleared from screens, a reduction in the number of reported complaints, and an improved library environment, despite mistakes made by the filtering software. Auld argues that filters work in blocking pornography while only slightly affecting access to protected speech. According to Auld, the ALA should revise its anti-filtering policy because filters are more effective than any other ALA-recommended method and the policy is undermining and dividing the profession.

The following table represents arguments for and against filtering requirements from an earlier supreme court case, Reno v. ACLU. In this case, the supreme court sided with the ACLU, unanimously striking down a portion of the 1996 Communications Decency Act (CDA).

Edwards' commentary focuses on the questionable success of filters meant to block access by young people to websites with pornographic content in libraries and schools. While allowing schools and libraries to maintain access to federal funding under the Children’s Internet Protection Act of 2000 (CIPA), the use of these filters may also be blocking access to sensitive health information. The most frequently blocked sites included the following words: The more the restrictive filters prevented the twelve testers from finding health information on topics such as pregnancy, abortion and drug use, while only marginally improving protection against pornographic sites. Both sides of the filtering debate claim victory. Those for filters advocate their use by applauding the success of the study in blocking between 87-91% of pornography in the study. Those against the use of filters cite the potential 24% of health information sites blocked as the failure inherent in the system. The perplexing portion of CIPA is that the government mandates the use of filtering to remain eligible for federal funding; yet they make no policy as to what should be filtered. The recurring theme with library policy is the information as a commodity, again leaving the question of what information should be available to whom to be an arbitrary decision. One can infer that the debate regarding this topic will remain controversial since there is no way to standardize to a general agreement what issues should be blocked.
 * Gay or lesbian
 * Condoms
 * Safe Sex
 * Abortion


text:
Talk:Ground Ladders/Ground Ladders

GROUND LADDERS

Given specific fire service ground ladders, assemble all materials needed, such as proper PPE (Personnel Protective Equipment) ect... So that the ladders are stable, at the correct climbing angle and deployed in a safe manner.

REQUISITE KNOWLEDGE:

 * All parts of a fire service ground ladder.
 * Safety hazards (Electrical & Natural).
 * Proper use of a ladder for the proper task at hand.

REQUISITE SKILLS:

ladder safety harness.
 * Label the parts of a ground ladder.
 * Identify types of ground ladders.
 * Proper cleaning and inspection of a ground ladder.
 * Ladder safety rules.
 * Proper ladder lifts, carries and placement.
 * Proper raising and lowering of a ground ladder.
 * Properly work and climb from a ground ladder with and without a

title: Talk:Ground Ladders/Ground Ladders


text:
Windows Programming/Resource Scripts

The Windows platform SDK includes a special utility called rc.exe, the Resource Script Compiler. Resource scripts are a powerful part of Windows programming that any good programmer should know how to utilize effectively.

For more information about specific resources, see the Resource Script Reference.

What is a Resource Script
The resource compiler compiles a special type of file known as a Resource Script. Resource scripts contain GUI data, and, when compiled, can be linked into a program. The program then can access the data contained in the resource script. Also interesting to note is that the Windows operating system accesses a program's resources for various purposes. For instance, right-click on a program and click "Properties". If available, click on the "Version" tab. This tab will contain a number of different text strings that describe the program. These text strings are all included from a resource script.

Also, people are all familiar with the fact that usually each program has a distinct icon. If you want your program executable to use a special icon you must include it in a resource script.

There are many different types of resources that can be stored in a program via a resource script. Resource scripts are not the only way to store this information in a program, but they are much easier to write than hard C or VB code to store and access them.

Types of resources
Here is a list of common resources:

 * Drop-down Menus
 * Popup Menus
 * Text Strings
 * Keyboard Accelerators (keypress combinations, such as [Ctrl]+[C] to copy text)
 * Icons
 * Bitmap Images
 * Dialog Boxes
 * Version information
 * Mouse Cursors

Making a Resource Script
The syntax for writing resource scripts is similar to C. For instance, the resource script compiler uses the standard C preprocessor. This is important because you must include the header file  to make a resource script. Also, most resource scripts contain macro values, so programmers will frequently store the related macro definitions in a header file "resource.h". This way, the same macros can be included and used in the main program files.

We will talk more about resources in the following chapters; there's also an appendix where all common resource types are listed including information on how to use them. This appendix is located at Windows Programming/Resource Script Reference.

Using a Resource
Once a resource is stored in your executable there are various methods to access it. These methods differ depending on what type of resource you are trying to access. For instance if you want to access a string resource, you would need to use the LoadString function; correspondingly the LoadIcon function is needed to access an icon.

To access a resource you must have the instance handle of the executable file that contains the resource. This means, that if you obtain an instance handle to another executable (or DLL) file, you can access the resources remotely! Occasionally, programmers will create DLL files that contain nothing but resources for use in other programs.

MAKEINTRESOURCE
The MAKEINTRESOURCE keyword that we will occasionally see when dealing with resources is an important keyword, and a program will crash (or not even compile) if it is not used correctly so taking a minute to understand it is well worth the effort.

Resources are all stored with a name which can be a string or a numerical identifier. If it is numerical, the number must be no larger than an unsigned 16-bit integer (65535, max). Resources are all called by name, that is the system is expecting an unicode string with the name of the resource. However if we use a numerical identifier we need to inform the system that we are doing so, so that it doesn't get confused and try to treat your integer as a string. For that we pass the MAKEINTRESOURCE macro to make. The macro takes a single argument - the numerical identifier - and it returns a string pointer suitable for use in the system. We will demonstrate this later.

Next Chapter

 * Message Loop Architecture

title: Windows Programming/Resource Scripts


text:
Windows Programming/Resource Script Reference

This appendix page will attempt to list the different types of resources, and will attempt to show how to use those resources.

General construction
Resource script files are human-readable text files in either ANSI or Unicode (more strictly: UTF-16 with byte order mark (BOM)) format. To intermix different languages in ANSI format, a quirks  exist to switch the code page in between. Unicode,  switch, and the   statement are only supported for Win32.

A typical small file may look like

100 ICON "ProgIcon.ico" 10 MENU {		// or BEGIN POPUP "&File" {  MENUITEM "&Exit",IDCANCEL } }		// or END
 * 1) include
 * 2) define IDC_STATIC -1

Using curly braces or BEGIN/END depends on your preference. The old, space-wasting style is the BEGIN/END pair, coming from the Pascal heritage of MacOS and Win16 API calls. C programmers typically prefer curly braces. The Visual Studio Resource Editor always generates BEGIN/END pairs, besides lots of housekeeping stuff.

Beginning with some header inclusion and  statements, every resource is included as either

id_of_resource resource_type  [memory management flags]  "filename"

or

id_of_resource resource_type  [memory management flags] BEGIN subsequent data END

An exception from this rule is

 * The  statement, can be placed almost everywhere (Win32 only)
 * The  and the   resource, there are additional statements between heading line and BEGIN
 * The  resource, where no resource ID is before the keyword. Instead, every string is prefixed with an ID

and  can be either a string or a number. No quotes are there! A number is the preferred method for identification. All predefined resource types are numbers. But watch out! If you use an unknown ID for the resource compiler (let's say MANIFEST for Visual Studio 6), you will get neither error nor warning, and the resource is built with string resource type. Windows XP, using, will not find that intended manifest and your program will show up in old visual style.

Conditional compilation with #if / #ifdef / #endif is also supported.

Expressions for IDs are limited to very simple math, no boolean operators are permitted.

Under the hood
Resources are compiled into a three-level directory structure:
 * 1) Resource type (MENU, DIALOG etc.)
 * 2) Resource ID (the number that is ahead the Resource Type – for STRINGTABLE, the ID of a group of up to 16 strings)
 * 3) Resource language (the currently active language, given by command-line option or LANGUAGE statement; Win32 only)

The content of following data depends on actual resource type. Mostly, it's binary.

Read access to the binary data of an arbitrary resource is done with

FindResource		// get a handle LoadResource		// get the binary size LockResource		// get a pointer; Win32: This is a simple macro, Win16: This is a function call. ...			// do something UnlockResource	// Win32: This is a do-nothing macro, Win16: This is a function call. FreeResource		// release

Because bitmap, icon, cursor, dialog, string table, and menu resources are not officially documented and a bit hard to parse, programmers should use specialized resource load functions for these resource types instead. See description and examples for these types below.

Identifiers
Identifiers are generally named in a certain way, although the reader and all programmers are free to alter this naming scheme. It is simply a suggestion. Identifiers generally start with the prefix "ID", followed by a letter that denotes the type of identifier:

 * IDS: A string resource
 * IDM: A menu resource
 * IDC: A command identifier
 * IDD: A dialog box resource
 * IDA: An Accelerator table resource
 * IDI: An Icon or bitmap resource
 * IDB: A Bitmap resource
 * ID: A custom resource, or an uncommon resource type.

Sometimes, the command identifiers in a menu are given an "IDM_" prefix, to distinguish between commands from other sources.

There is no need to use symbolic identifiers. In some cases, identifiers complicate access to numerically adjanced controls in a dialog or menu. In any case, identifiers don't help non-English programmers to read a software source. Numbers never need translation. And both identifiers and numbers need explanation.

IDs are allowed in range 0..65535 and preferred in range 1..32767.

LANGUAGE
This keyword has different scope: 21 MENU LANGUAGE 7,1 // or, LANG_GERMAN, SUBLANG_GERMAN { POPUP "&Datei"  // = "&File" ... This language applies to that menu
 * Local (for one resource) if located below the resource line, like

 * Global (for all next resources) if located somewhere else

Language-neutral resources, like culture-free icons, VersionInfo, and Manifests, should be always set to LANGUAGE 0,0 (or, more verbously, LANG_NEUTRAL,SUBLANG_NEUTRAL).

Note to always check images against culture dependency! A typical mistake is the plug symbol for a mains-supplied notebook: It shows undoubtly an American plug, even in Europe. Obviously, images containing letters or text are culture-dependent.

Memory Management Flags
There are some Memory Management Flags from Win16 heritage, like MOVEABLE, FIXED, etc. See LocalAlloc for some flags.

DISCARDABLE
Resources are loaded into memory when the program is run. However, if a resource is not in use, and if Windows does not need them immediately, resources can be optionally unloaded from memory until needed. To specify that it is okay to unload an unused resource from memory, you may list the DISCARDABLE keyword with the resource. DISCARDABLE resources allow more efficient memory usage, but can slow down your program if they need to be loaded from disk.

The DISCARDABLE keyword is ignored for 32-bit Windows, but remains for compatibility. 32 bit resources are never loaded but mapped into memory.

Icons
Icons can be stored in a resource file using the  keyword. Here is a general example of using an icon in a resource script:

IDI_ICON ICON [DISCARDABLE] "iconfile.ico"

Windows Explorer will display the binary executable with the first icon from the script. For instance, if we load two icons, as such:

IDI_ICON1 ICON DISCARDABLE "icon1.ico" IDI_ICON2 ICON DISCARDABLE "icon2.ico"

And we define our macros as such in the corresponding :

 * 1) define IDI_ICON1 1
 * 2) define IDI_ICON2 2

The executable file will have icon1.ico as its icon.

To load an icon from an executable module, assuming we have an instance handle to the module ( in the following example), we can get a handle to the icon as such:

HICON hIcon; hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1));

This will return a handle to the icon associated with the identifier "IDI_ICON1". Icon identifiers are generally prefixed with an "IDI_" which is short for "ID for an Icon".

The second parameter to the  function is a pointer to a string. String pointers are 32 bit values. However, if the most significant 16 bits are all zero, Windows will treat the value as a resource number, and not a string. To make the conversion between a string and a 16-bit integer, Microsoft provides the MAKEINTRESOURCE macro. Similarly, we could have used a string to define our Icon:

MYICON1 ICON DISCARDABLE "icon1.ico"

And we could load this string by name:

HICON hIcon; hIcon = LoadIcon(hInst, "MYICON1");

String identifiers for resources are case insensitive.

has handle values for two icons: a large icon and a small icon. The small icon is the icon used in the upper-left corner. Small icons are generally 16 pixels square. Larger icons are 32 pixels square. If no small icon handle is provided, the large icon will be shrunk down to fit.

If the  function is supplied with a NULL instance handle, Windows will supply a default icon for use.

Recently, the Win32 API provides the LoadImage function for loading icons, bitmaps, and mouse cursors from a single function. You can find more information about this function on MSDN.

Internally, Icons are stored under numeric resource type RT_ICON == 3, and are grouped under RT_GROUP_ICON == 14.

Bitmaps
Bitmaps can be loaded similarly to Icons in resource files:

(bitmap ID or name) BITMAP [DISCARDABLE] "bitmapfile.bmp"

Bitmaps can be accessed with the aptly named LoadBitmap function (again, new versions of the Win32 API prefer you use LoadImage to load a bitmap, icon, or cursor). LoadBitmap returns an HBITMAP handle type:

HBITMAP hBmp; hBmp = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));

Or, if we have named our bitmap resource:

hBmp = LoadBitmap(hInst, "MyBitmapRes");

Bitmaps are large resources, and if windows can't load the bitmap into memory (or if the ID or name value is invalid), the function will return a NULL value. Make sure you test this value before you use the handle.

Bitmaps must be unloaded from memory by passing the handle to the DeleteObject function. You can find more information about this on MSDN

Bitmap identifiers generally use a "IDB_" prefix, to indicate that it is the ID of a bitmap.

Internally, Bitmaps are stored under numeric resource type RT_BITMAP == 2.

Mouse Cursors
Mouse cursors are specified similarly to icons and bitmaps, and are loaded with the LoadCursor function.

Internally, cursors are stored under numeric resource type RT_CURSOR == 1, and are grouped under RT_GROUP_CURSOR == 12.

As for any resource that implies binary data, the use of an external file with "filename" is recommended. However, most resource compilers allow to inline binary data to the resource file in this way:

42 ICON { 123,4567,0x89AB,0xCDEF '\x01','\x23',"ajx" }

with this rule, coming from Win16 heritage:
 * Numbers (decimal or hexadecimal) are stored contiguously as 16-bit little-endian quantities (unaligned)
 * Characters are stored as 8-bit quantities

String Tables
A resource script can have many string tables, although this is unneccessary: the tables aren't differentiated (i.e. they get merged), and each string object, in any table, must have a unique identifier. Strings in a string table also may not use names, but instead must use numeric identifiers. After all, it doesn't make any sense to have to address a string with a string, does it?

Here is a general string table:

STRINGTABLE DISCARDABLE BEGIN IDS_STRING1, "This is my first string" IDS_STRING2, "This is my second string" ... END

It is important to note that in place of the BEGIN and END keywords, the programmer may also use the more C-like curly brackets, as such:

STRINGTABLE DISCARDABLE {   IDS_STRING1, "This is my first string" IDS_STRING2, "This is my second string" ... }

Some people prefer one over the other, but they are all the same to the resource compiler.

Strings can be loaded using the LoadString function. LoadString is more involved then the LoadBitmap or LoadIcon functions:

int LoadString(HINSTANCE hInstance, UINT uID, LPTSTR lpBuffer, int nBufferMax); The hInstance parameter, as we know, is the instance handle for the module that contains the string. The uID parameter contains the string number that we are trying to access. lpBuffer is the character array variable that will receive the string, and the nBufferMax number tells windows what the maximum number of characters that can be loaded is. This count is a security precaution, so make sure not to allow Windows to write character data beyond the end of the string. MSDN displays a large warning on the page for this function, and it is important that programmers heed this warning. msdn

Windows will automatically zero-terminate the string, once it is written to the buffer. LoadString will return the number of characters that were actually written into the string, in case the number of characters is less than the maximum number allowed. If this return value is 0, the string resource does not exist, or could not be loaded.

Strings can have "\0" in the middle. As strings are saved as counted strings, LoadString returns the number of characters saved, including the zeroes in between. But most Resource Editors fail with such strings.

Internally, stringtables are stored under numeric resource type RT_STRING == 6, in groups of up to 16 adjanced IDs.

Accelerators
Keyboard accelerators are a common part of nearly every windows application, and therefore it is a good idea to simplify the job of creating accelerators by putting them in a resource script. Here is how to create an accelerator table:

(Accelerator Table ID or name) ACCELERATORS [DISCARDABLE] BEGIN (key combination), (Command ID) ... END

Key combinations are specified in terms of either a string literal character ("A" for instance) or a virtual key code value. Here are some examples:

IDA_ACCEL_TABLE ACCELERATORS DISCARDABLE BEGIN "A", IDA_ACTION_A //Shift+A END

Now, when the key combination "Shift+A" is pressed, your window procedure will receive a WM_COMMAND message with the value IDA_ACTION_A in the WPARAM field of the message.

If we want to use combinations of the "Alt" key, or the "Ctrl" key, we can use the ALT and CONTROL keywords, respectively:

IDA_ACCEL_TABLE ACCELERATORS DISCARDABLE BEGIN "a", IDA_ACTION_A, ALT         //Alt+A "b", IDA_ACTION_B, CONTROL     //Ctrl+B "c", IDA_ACTION_C, ALT, CONTROL //Alt+Ctrl+A END

Also, we can use the "^" symbol to denote a CONTROL key code:

IDA_ACCEL_TABLE ACCELERATORS DISCARDABLE BEGIN "^a", IDA_ACTION_A //Control+A END

Similarly, if we want to be super hackers, would could use the ASCII code directly:

IDA_ACCEL_TABLE ACCELERATORS DISCARDABLE BEGIN 65, IDA_ACTION_A, ASCII //65 = "A", Shift+A END

Or, we could refer to keys (including non-alphanumeric keys) with their Virtual Key Code identifiers, by using the VIRTKEY identifier:

IDA_ACCEL_TABLE ACCELERATORS DISCARDABLE BEGIN VK_F12, IDA_ACTION_F12, VIRTKEY            //press the "F12 Key" VK_DELETE, IDA_ACTION_DEL, VIRTKEY, CONTROL //Ctrl+Delete END

Now, If we make an accelerator correspond to a menu command, the menu command will light up when we press the accelerator. That is, the menu will light up unless we specify the "NOINVERT" keyword:

IDA_ACCEL_TABLE ACCELERATORS DISCARDABLE BEGIN "A", IDA_ACTION_A, NOINVERT //Shift+A (non inverted menu selection) END

To Load an accelerator table, we need to use the LoadAccelerators function, as such:

HACCEL hAccel; hAccel = LoadAccelerators(hInst, MAKEINTRESOURCE(IDA_ACCEL_TABLE));

Again, we could have given our resource a string name, and used that string to load the table.

When using accelerators, we need to alter our message loop to intercept the keypress messages, and translate them into command messages according to our accelerator table rules. We use the TranslateAccelerator function, to intercept the keypress messages, and translate them into command messages, as such:

while ( (Result = GetMessage(&msg, NULL, 0, 0)) != 0) {    if (Result == -1) {        // error handling }        else {        if (!TranslateAccelerator(hwnd, haccel, &msg)) {            TranslateMessage(&msg); DispatchMessage(&msg); }        }     }

Also, if we are writing an MDI application, we need to intercept Accelerator messages from the child windows, we use the TranslateMDISysAccel function also:

while ( (Result = GetMessage(&msg, NULL, 0, 0)) != 0) {    if (Result == -1) {        // error handling }        else {        if (  !TranslateMDISysAccel(hwndClient, &msg)            && !TranslateAccelerator(hwndFrame, haccel, &msg) ) {            TranslateMessage(&msg); DispatchMessage(&msg); }        }     }

Where "hwndFrame" is the handle to the frame window, and "hwndClient" is the handle to the MDI client window.

Internally, Accelerators are stored under numeric resource type RT_ACCELERATOR == 9.

Menus
Menus can be defined in a resource script using the MENU keyword. There are 2 types of items that appear in a menu, the top level "POPUP" menu items, and the secondary "MENUITEM" items. These are defined in a menu as such:

(ID or name) MENU [DISCARDABLE] BEGIN POPUP "File" POPUP "Edit" BEGIN MENUITEM "Copy", IDM_EDIT_COPY MENUITEM "Paste", IDM_EDIT_PASTE END ... END

We have included a few examples here, so that you can see the difference between a POPUP and a MENUITEM. When we have a menu with the ID_MENU identifier, we can load it into our program as such:

HMENU hmenu; hmenu = LoadMenu(hInst, MAKEINTRESOURCE(ID_MENU)); Once we have this handle, we can pass it to the CreateWindow function, and apply it to our window.

When a menu item is selected, the host program receives a WM_COMMAND message, with the menu item identifier in the WPARAM parameter. If we have a basic window procedure switch-case statement, we can see this as follows:

case WM_COMMAND: switch(WPARAM) {       case IDM_EDIT_COPY: //handle this action break; case IDM_EDIT_PASTE: //handle this action break; }   break;

In a menu, if we want to associate a menu item with an accelerator, we can define it as such:

ID_MENU MENU DISCARDABLE BEGIN POPUP "File" POPUP "Edit" BEGIN MENUITEM "&Copy", IDM_EDIT_COPY MENUITEM "&Paste", IDM_EDIT_PASTE END ... END

Notice how we put the ampersand (&) in front of the "C" in "Copy" and the "P" in "Paste". This means that those letters will be underlined, but more importantly, if an accelerator key combination is pressed, those items in the menu will be highlighted (unless the NOINVERT tag is specified in the accelerator table). If an ampersand is placed before a POPUP menu item, pressing ALT+ that letter will popup that menu. For instance, lets define our menu:

ID_MENU MENU DISCARDABLE BEGIN POPUP "&File" POPUP "&Edit" BEGIN MENUITEM "Copy", IDM_EDIT_COPY MENUITEM "Paste", IDM_EDIT_PASTE END ... END

Now, if we press ALT+F, we will pop open the File menu, and if we press ALT+E it will open the Edit menu. That's pretty nice functionality for only a single extra character to type.

Internally, Menus are stored under numeric resource type RT_MENU == 4.

Version Information
A program can include certain information about its version, and its author in a resource script. This version information appears when you right-click the executable in Windows, and click "Properties". In the properties dialog box, this information appears on the "Version" tab. BLOCK "StringFileInfo" BEGIN BLOCK "040904E4" BEGIN VALUE "CompanyName",     "My Company.\0" VALUE "FileDescription", "A Win32 program." VALUE "FileVersion",     "1.0.0.0\0" VALUE "ProductName",     "The product name.\0" VALUE "ProductVersion",  "1.0\0" VALUE "LegalCopyright",  "My Company.\0" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x409, 1252 END

Internally, VersionInfo is stored under numeric resource type RT_VERSION == 16. It was introduced with Windows 3.

Dialog Boxes
Dialog box resources follow a general pattern:

(Dialog ID or name) DIALOG [DISCARDABLE] x, y, width, height TITLE "(dialog box title)" [CLASS "(class name)"] FONT "(font name)" BEGIN ... END

if a dialog box is not being associated with a class, the CLASS field does not need to be filled in. All strings listed as being in quotes must be in quotes in the resource script or there will be an error. Individual items in a dialog box are then specified between the BEGIN and END tags.

Internally, Dialogs are stored under numeric resource type RT_DIALOG == 5.

Generic Controls
CONTROL classname,windowname,id,left,top,width,height,windowflags

Manifests
Manifest resources contain UTF-8 encoded XML description of operating system and DLL dependency. Mostly, this resource dictates to use the Windows XP Version 6.0 comctl32.dll, to have Luna style for the standard and common controls.

Internally, Manifests are stored under numeric resource type RT_MANIFEST == 24. It was introduced with Windows 4.1.

User-type resources
User-type resources should use some greater resource type identifiers, or RT_RCDATA == 10.