--- pmsdk/samples/dlgsamp/dlgsamp.c 2018/08/09 12:28:12 1.1 +++ pmsdk/samples/dlgsamp/dlgsamp.c 2018/08/09 12:28:18 1.1.1.2 @@ -1,62 +1,7 @@ -/*************************************************************************** -* -* MODULE NAME: DLGSAMP -* -* Presentation Manager Dialog Sample Application -* -* Created by Microsoft Corp., 1988 -* -**************************************************************************** - -/*************************************************************************** -* -* CALL NAME COUNT -* ========= ===== -* -* GpiCharStringAt 4 -* GpiSetColor 1 -* WinBeginPaint 1 -* WinCreateMsgQueue 1 -* WinCreateStdWindow 1 -* WinDefDlgProc 6 -* WinDefWindowProc 1 -* WinDestroyMsgQueue 1 -* WinDestroyWindow 3 -* WinDismissDlg 4 -* WinDispatchMsg 1 -* WinDlgBox 1 -* WinEndPaint 1 -* WinFillRect 1 -* WinGetMsg 1 -* WinInitialize 1 -* WinInvalidateRect 6 -* WinIsWindow 1 -* WinLoadDlg 1 -* WinLoadString 2 -* WinMessageBox 2 -* WinPostMsg 20 -* WinQueryDlgItemShort 1 -* WinQuerySysValue 2 -* WinQueryWindow 1 -* WinQueryWindowPos 1 -* WinQueryWindowText 4 -* WinRegisterClass 1 -* WinSendDlgItemMsg 5 -* WinSendMsg 1 -* WinSetFocus 1 -* WinSetWindowPos 1 -* WinTerminate 1 -* WinWindowFromID 16 -* -* Number of unique calls = 34 -* -***************************************************************************/ - -/*************************************************************************** -* -* Include relevant sections of the PM header file. -* -***************************************************************************/ +/* + DLGSAMP -- Dialog Box Sample Application + Created by Microsoft Corporation, 1989 +*/ #define INCL_WINBUTTONS #define INCL_WINDIALOGS @@ -73,72 +18,40 @@ #define M_I86L #include -/*************************************************************************** -* -* Include C library routine header files -* -***************************************************************************/ - #include #include -/*************************************************************************** -* -* Include application header files -* -* dlgsamp.h is header for dialog editor ids -* dlgsamp.h1 is standard application header for everything not in .h -* -***************************************************************************/ - #include "dlgsamp.h" #include "dlgsamp1.h" -/*************************************************************************** -* -* Function prototypes for private C functions -* -***************************************************************************/ - -VOID NEAR cdecl main( VOID ); - -VOID cdecl CentreDlgBox( HWND hwnd ); -VOID cdecl CheckColor( HWND hwndDlg, SHORT iDlgItem, COLOR *colorClient ); -VOID cdecl EnableModality( HWND hwnd, BOOL bModal ); -BOOL cdecl IsIntInRange( HWND hwndDlg, SHORT idEntryField, - SHORT iLoRange, SHORT iHiRange, - SHORT idErrMsg, SHORT idMessageBox ); -VOID cdecl LoadDialog( HWND hwndParent, HWND hwndOwner, - SHORT idDlg, PFNWP fnwpDlgProc, - BOOL bModality ); -VOID cdecl MainWndCommand( HWND hwnd, USHORT command, BOOL *bModality ); -VOID cdecl MainWndPaint( HWND hwnd ); -VOID cdecl SetModality( HWND hwnd, BOOL bModal ); -VOID cdecl Trace( PSZ szCaption, PSZ szMessage ); - -/************************************************************************** -* -* Function protypes for private WinProcs. -* -**************************************************************************/ - -MRESULT EXPENTRY fnwpMainWnd( HWND hwnd, USHORT message, - MPARAM mp1, MPARAM mp2 ); -MRESULT EXPENTRY fnwpEntryFieldDlg( HWND hwnd, USHORT message, - MPARAM mp1, MPARAM mp2 ); -MRESULT EXPENTRY fnwpAutoRadioButtonDlg( HWND hwnd, USHORT message, - MPARAM mp1, MPARAM mp2 ); -MRESULT EXPENTRY fnwpCheckBoxDlg( HWND hwnd, USHORT message, - MPARAM mp1, MPARAM mp2 ); -MRESULT EXPENTRY fnwpListBoxDlg( HWND hwnd, USHORT message, - MPARAM mp1, MPARAM mp2 ); - -/************************************************************************* -* -* Global variables -* -*************************************************************************/ - +/* + Function Prototypes +*/ + +VOID NEAR cdecl main(VOID); + +/* Local Routines */ +VOID cdecl CenterDlgBox(HWND); +VOID cdecl CheckColor(HWND, SHORT, COLOR *); +VOID cdecl EnableModality(HWND, BOOL); +BOOL cdecl IsIntInRange(HWND, SHORT, SHORT, SHORT, SHORT, SHORT); +VOID cdecl LoadDialog(HWND, HWND, SHORT, PFNWP, BOOL); +VOID cdecl MainWndCommand(HWND, USHORT, BOOL *); +VOID cdecl MainWndPaint(HWND); +VOID cdecl SetModality(HWND, BOOL); +VOID cdecl Trace(PSZ, PSZ); + +/* Window Procedures */ +MRESULT CALLBACK fnwpMainWnd(HWND, USHORT, MPARAM, MPARAM); +MRESULT CALLBACK fnwpEntryFieldDlg(HWND, USHORT, MPARAM, MPARAM); +MRESULT CALLBACK fnwpAutoRadioButtonDlg(HWND, USHORT, MPARAM, MPARAM); +MRESULT CALLBACK fnwpCheckBoxDlg(HWND, USHORT, MPARAM, MPARAM); +MRESULT CALLBACK fnwpListBoxDlg(HWND, USHORT, MPARAM, MPARAM); +MRESULT CALLBACK fnwpAboutBoxDlg(HWND, USHORT, MPARAM, MPARAM); + +/* + Global variables +*/ COLOR colorClient = CLR_RED | CLR_BLUE; /* Color of client area */ CHAR szEntryField1[10] = ""; /* Used to pass back info */ @@ -161,17 +74,11 @@ HWND hwndModelessDlg; * * FUNCTION: main * -* Typical PM main function which initialises PM, creates a message queue, +* Typical PM main function which initializes PM, creates a message queue, * registers a window class, creates a window, gets and dispatches * messages to its winproc until its time to quit, and then tidies up * before terminating. * -* Side effects: -* -* Sets the values of the following globals:- -* -* hab, hwndClient, hwndFrame. -* **************************************************************************/ VOID NEAR cdecl main( ) @@ -180,24 +87,22 @@ VOID NEAR cdecl main( ) QMSG qmsg; /* Message */ ULONG flCreate; - hab = WinInitialize( NULL ); /* Initialise PM */ + hab = WinInitialize( NULL ); /* Initialize PM */ hmq = WinCreateMsgQueue( hab, 0 );/* Create application msg queue */ WinRegisterClass( /* Register Window Class */ hab, /* Anchor block handle */ "DlgSamp Class", /* Window Class name */ fnwpMainWnd, /* Address of Window Procedure */ - NULL, /* No special class style */ + (ULONG) NULL, /* No special class style */ 0 /* No extra window words */ ); - flCreate = FCF_STANDARD; + flCreate = FCF_STANDARD & ~FCF_ACCELTABLE; hwndFrame = WinCreateStdWindow( HWND_DESKTOP, /* Desktop Window is parent */ - WS_VISIBLE | - FS_TASKLIST | - FS_ICON, /* Window styles */ + WS_VISIBLE, /* Window styles */ (PVOID)&flCreate, /* Window creation parameters */ "DlgSamp Class", /* Window Class name */ "", /* Window Text */ @@ -208,9 +113,11 @@ VOID NEAR cdecl main( ) ); + /* Message Loop */ while( WinGetMsg( hab, (PQMSG)&qmsg, (HWND)NULL, 0, 0 ) ) WinDispatchMsg( hab, (PQMSG)&qmsg ); + /* Cleanup code */ WinDestroyWindow( hwndFrame ); WinDestroyMsgQueue( hmq ); WinTerminate( hab ); @@ -224,15 +131,9 @@ VOID NEAR cdecl main( ) * dialogs will be modal or modeless depending on the setting of the * Modality menuitem. * -* Side Effects. -* -* Modifies the values of the following globals:- -* -* szEntryField1, szEntryField2, szSelection -* ***********************************************************************/ -MRESULT EXPENTRY fnwpMainWnd( hwnd, message, mp1, mp2 ) +MRESULT CALLBACK fnwpMainWnd( hwnd, message, mp1, mp2 ) HWND hwnd; USHORT message; MPARAM mp1; @@ -251,7 +152,7 @@ MPARAM mp2; * * This will be received when either:- * -* 1. The user depresses F1 +* 1. The user hits the F1 key * 2. The user clicks on the action bar item F1=Help * *********************************************************************/ @@ -312,13 +213,9 @@ MPARAM mp2; * A dialog proc which captures and validates the contents of two * entry fields. * -* Side effects. -* -* Modifies the globals szEntryField1, szEntryField2. -* ***********************************************************************/ -MRESULT EXPENTRY fnwpEntryFieldDlg( hwndDlg, message, mp1, mp2 ) +MRESULT CALLBACK fnwpEntryFieldDlg( hwndDlg, message, mp1, mp2 ) HWND hwndDlg; USHORT message; MPARAM mp1; @@ -327,7 +224,7 @@ MPARAM mp2; switch (message) { case WM_INITDLG: - CentreDlgBox( hwndDlg ); + CenterDlgBox( hwndDlg ); break; case WM_COMMAND: switch( SHORT1FROMMP( mp1 ) ) @@ -397,13 +294,9 @@ MPARAM mp2; * A dialog procedure which uses auto radio buttons to change the * color of the Client Area window. * -* Side effects. -* -* Modifies the Client Area color and the global colorClient -* ***********************************************************************/ -MRESULT EXPENTRY fnwpAutoRadioButtonDlg( hwndDlg, message, mp1, mp2 ) +MRESULT CALLBACK fnwpAutoRadioButtonDlg( hwndDlg, message, mp1, mp2 ) HWND hwndDlg; USHORT message; MPARAM mp1; @@ -413,7 +306,25 @@ MPARAM mp2; { case WM_INITDLG: colorSave = colorClient; - CentreDlgBox( hwndDlg ); + CenterDlgBox( hwndDlg ); + if ( colorClient == CLR_RED ) + WinPostMsg( WinWindowFromID( hwndDlg, RB_RED ), + BM_SETCHECK, + MPFROM2SHORT( TRUE, 0 ), + 0L ); + + if ( colorClient == CLR_GREEN ) + WinPostMsg( WinWindowFromID( hwndDlg, RB_GREEN ), + BM_SETCHECK, + MPFROM2SHORT( TRUE, 0 ), + 0L ); + + if ( colorClient == CLR_BLUE ) + WinPostMsg( WinWindowFromID( hwndDlg, RB_BLUE ), + BM_SETCHECK, + MPFROM2SHORT( TRUE, 0 ), + 0L ); + break; case WM_CONTROL: if( SHORT2FROMMP( mp1 ) == BN_CLICKED ) @@ -466,13 +377,9 @@ MPARAM mp2; * A dialog procedure to which use checkboxes to change the color * of the Client Area Window. * -* Side effects -* -* Modifies the Client Area color and the global colorClient -* ***********************************************************************/ -MRESULT EXPENTRY fnwpCheckBoxDlg( hwndDlg, message, mp1, mp2 ) +MRESULT CALLBACK fnwpCheckBoxDlg( hwndDlg, message, mp1, mp2 ) HWND hwndDlg; USHORT message; MPARAM mp1; @@ -481,7 +388,7 @@ MPARAM mp2; switch (message) { case WM_INITDLG: - CentreDlgBox( hwndDlg ); + CenterDlgBox( hwndDlg ); colorSave = colorClient; if( (colorClient & CLR_RED) == CLR_RED ) WinPostMsg( WinWindowFromID( hwndDlg, CB_RED ), @@ -533,13 +440,9 @@ MPARAM mp2; * * DlgProc: fnwpListBoxDlg * -* Side effects -* -* Modifies the global szSelection -* ***********************************************************************/ -MRESULT EXPENTRY fnwpListBoxDlg( hwndDlg, message, mp1, mp2 ) +MRESULT CALLBACK fnwpListBoxDlg( hwndDlg, message, mp1, mp2 ) HWND hwndDlg; USHORT message; MPARAM mp1; @@ -552,11 +455,11 @@ MPARAM mp2; switch (message) { case WM_INITDLG: - CentreDlgBox( hwndDlg ); + CenterDlgBox( hwndDlg ); /************************************************************************* * -* Initialise the listbox with a set of strings loaded from a +* Initialize the listbox with a set of strings loaded from a * resource file. * *************************************************************************/ @@ -565,9 +468,9 @@ MPARAM mp2; { WinLoadString( hab, NULL, - LBI_1 + i, /****** WARNING *********/ - LEN_LISTBOXENTRY, /* Differs */ - (PSZ)szBuffer /* from spec */ + LBI_1 + i, + LEN_LISTBOXENTRY, + (PSZ)szBuffer ); WinSendDlgItemMsg( hwndDlg, LB_1, @@ -586,7 +489,7 @@ MPARAM mp2; /*********************************************************************** * -* Find out which item if any was selected and return the selected +* Find out which item (if any) was selected and return the selected * item text. * ***********************************************************************/ @@ -626,13 +529,13 @@ MPARAM mp2; /************************************************************************* * -* PRIVATE FUNCTION : CentreDlgBox +* FUNCTION : CenterDlgBox * -* Positions the dialog box in the centre of the screen +* Positions the dialog box in the center of the screen * *************************************************************************/ -VOID cdecl CentreDlgBox( hwnd ) +VOID cdecl CenterDlgBox( hwnd ) HWND hwnd; { SHORT ix, iy; @@ -649,7 +552,7 @@ HWND hwnd; /*************************************************************************** * -* PRIVATE FUNCTION: CheckColor +* FUNCTION: CheckColor * * Toggle the Checked/UnChecked state of a checkbox and add/remove * the corresponding CLR color component of the Client Area Color. @@ -695,9 +598,9 @@ COLOR *colorClient; /************************************************************************** * -* PRIVATE FUNCTION: EnableModality +* FUNCTION: EnableModality * -* Enable or disable the Modality menuitems depending on the value +* Enable or disable the Modality menuitems depending on the value * of modal. This is done to prevent the user from altering the * modality setting while a modeless dialog is active. * @@ -733,7 +636,7 @@ BOOL bModal; /*************************************************************************** * -* PRIVATE FUNCTION: IsIntInRange. +* FUNCTION: IsIntInRange. * * Checks whether the value of a dialog item is in an integer in * a given range. @@ -787,15 +690,11 @@ SHORT idMessageBox; /*********************************************************************** * -* PRIVATE FUNCTION: LoadDialog +* FUNCTION: LoadDialog * * Use the appropriate functions to put up a modal or modeless * dialog box depending on the setting of the bModality parameter. * -* Side Effects -* -* Stes the value of the global hwndModelessDlg -* ***********************************************************************/ VOID cdecl LoadDialog( hwndParent, hwndOwner, idDlg, fnwpDlgProc, bModality ) @@ -841,7 +740,7 @@ BOOL bModality; /************************************************************************* * -* PRIVATE FUNCTION: MainWndCommand +* FUNCTION: MainWndCommand * * Take the appropriate action when a WM_COMMAND message is received by * MainWndProc. Issues calls which load dialogs in the prevailing state @@ -866,11 +765,6 @@ BOOL *bModality; SetModality( WinQueryWindow( hwnd, QW_PARENT, FALSE ), *bModality ); WinInvalidateRect( hwnd, NULL, FALSE ); return; - case MI_EXIT: - WinPostMsg( hwnd, WM_QUIT, 0L, 0L ); - return; - case MI_RESUME: - return; case MI_ENTRYFIELDEXAMPLE: idDlg = DLG_ENTRYFIELDEXAMPLE; pfnDlgProc = (PFNWP)fnwpEntryFieldDlg; @@ -887,6 +781,9 @@ BOOL *bModality; idDlg = DLG_LISTBOXEXAMPLE; pfnDlgProc = (PFNWP)fnwpListBoxDlg; break; + case MI_ABOUTBOX: + WinDlgBox(HWND_DESKTOP, hwnd, fnwpAboutBoxDlg, NULL, DLG_ABOUT, NULL); + return; default: return; } @@ -901,7 +798,7 @@ BOOL *bModality; /************************************************************************ * -* PRIVATE FUNCTION: MainWndPaint +* FUNCTION: MainWndPaint * * An unsophisticated window painting routine which simply repaints the * entire window when a WM_PAINT message is received. In a real @@ -920,7 +817,23 @@ HWND hwnd; CHAR string[50]; hps = WinBeginPaint( hwnd, (HPS)NULL, (PRECTL)&rcl ); - WinFillRect( hps, (PRECTL)&rcl, colorClient ); + /* + Color in the background + */ + switch ((int) colorClient) { + case 0: /* (r,g,b) = (0,0,0) */ + WinFillRect( hps, (PRECTL)&rcl, CLR_BLACK ); + break; + case 7: /* (r,g,b) = (1,1,1) */ + WinFillRect( hps, (PRECTL)&rcl, CLR_WHITE ); + break; + default: + WinFillRect( hps, (PRECTL)&rcl, colorClient ); + break; + } + /* + Set the text character colors + */ GpiSetColor( hps, (colorClient == 0L) ? CLR_WHITE : CLR_BLACK ); pointl.x = 10L; pointl.y = 70L; @@ -945,7 +858,7 @@ HWND hwnd; /************************************************************************** * -* PRIVATE FUNCTION: SetModality +* FUNCTION: SetModality * * Check or uncheck Modal and Modeless menu items as appropriate. * @@ -968,3 +881,23 @@ BOOL bModal; : ( MIA_CHECKED) ) ); } + +MRESULT CALLBACK fnwpAboutBoxDlg(hDlg, msg, mp1, mp2) +/* + About... dialog procedure +*/ +HWND hDlg; +USHORT msg; +MPARAM mp1; +MPARAM mp2; +{ + switch(msg) { + case WM_COMMAND: + switch(COMMANDMSG(&msg)->cmd) { + case DID_OK: WinDismissDlg(hDlg, TRUE); break; + default: break; + } + default: return WinDefDlgProc(hDlg, msg, mp1, mp2); + } + return FALSE; +}