Add the IDM_OPEN Case

You need to fill in the IDM_OPEN case for the WM_COMMAND message. When the user chooses the command, the application should display the Open dialog box. Add the following statements to the window function:

case IDM_OPEN:

lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst));

DialogBox(hInst, “Open”, hWnd, lpOpenDlg);

FreeProcInstance(lpOpenDlg);

break;

The MakeProcInstance function creates a procedure-instance address for the OpenDlg function. The function ensures that the data segment for the current instance is used when the dialog function is called. Functions, such as OpenDlg, that are exported by an application may be called only through a procedure-instance address and must not be called directly.

The FreeProcInstance function is used to free a procedure-instance address when it is no longer needed. After the DialogBox function returns, the procedure-instance address, lpOpenDlg, is not needed and can be freed. It will be re-created the next time the dialog box is invoked.

The DialogBox function returns control to WinMain only after the dialog function has terminated the dialog box. This means the dialog box will complete any actions the user requests before the application can continue execution. Such a dialog box is called a modal dialog box, since while it remains on the screen, the application is in a new mode of operation. This means the user can respond only to the dialog box. It also means that commands that apply to the application are not available while the dialog box is present.