Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

DRVLIST.C

Go to the documentation of this file.
00001 /****************************************************************************************/
00002 /*  DrvList.c                                                                           */
00003 /*                                                                                      */
00004 /*  Author: Mike Sandige                                                                */
00005 /*  Description:  Dialog control logic for driver/mode selection dialog                 */
00006 /*                 (rewritten from previous version)                                    */
00007 /*  Copyright (c) 1997, 1999, Eclipse Entertainment; All rights reserved.               */
00008 /*                                                                                      */
00009 /*  See the accompanying file LICENSE.TXT for terms on the use of this library.         */
00010 /*  This library is distributed in the hope that it will be useful but WITHOUT          */
00011 /*  ANY WARRANTY OF ANY KIND and without any implied warranty of MERCHANTABILITY        */
00012 /*  or FITNESS FOR ANY PURPOSE.  Refer to LICENSE.TXT for more details.                 */
00013 /*                                                                                      */
00014 /****************************************************************************************/
00015 #define WIN32_LEAN_AND_MEAN
00016 #include        <windows.h>
00017 #include        <stdio.h>
00018 #include        <stdlib.h>
00019 #include        <assert.h>
00020 
00021 #include        "genesis.h"
00022 
00023 #include        "resource.h"
00024 #include        "drvlist.h"
00025 
00026 
00027 #define DRVLIST_OK              1
00028 #define DRVLIST_CANCEL  2
00029 
00030 #define DRVLIST_MAX_DISPLAY_MODES (40)
00031 typedef struct 
00032 {
00033         ModeList *ModeList;
00034         int               ModeListLength;
00035         int               ModeListDriverCount;
00036         geDriver *IndexTable[DRVLIST_MAX_DISPLAY_MODES];
00037         int               Selection;
00038 }       DrvList_LocalStruct;
00039 
00040 
00041 static DrvList_LocalStruct DrvList_Locals;
00042 
00043 static geBoolean DrvList_FillModeList(HWND hwndDlg,int DriverNumber,DrvList_LocalStruct *DL)
00044 {
00045         int             i;
00046         int             MaxCX = 0;
00047         SIZE    extents;
00048         HWND    ListBox;
00049         HDC             hDC;
00050         
00051         ListBox = GetDlgItem(hwndDlg, IDC_DRIVERLIST);
00052         if (ListBox ==NULL)
00053                 return GE_FALSE;
00054                 
00055         hDC = GetDC(ListBox);
00056         if (hDC == NULL)
00057                 return GE_FALSE;
00058         
00059         SendDlgItemMessage(hwndDlg, IDC_DRIVERLIST2, LB_RESETCONTENT, (WPARAM)0, (LPARAM)0);
00060 
00061         for (i=0; i<DL->ModeListLength; i++)
00062                 {
00063                         if (DL->IndexTable[DriverNumber] == DL->ModeList[i].Driver)
00064                                 {
00065                                         int index;
00066                                         index = SendDlgItemMessage(hwndDlg, IDC_DRIVERLIST2, LB_ADDSTRING, (WPARAM)0, 
00067                                                                                                 (LPARAM)(DL->ModeList[i].ModeNamePtr));
00068                                         SendDlgItemMessage(hwndDlg, IDC_DRIVERLIST2, LB_SETITEMDATA, (WPARAM)index,(LPARAM)i);
00069                                         GetTextExtentPoint32(hDC, DL->ModeList[i].ModeNamePtr, strlen(DL->ModeList[i].ModeNamePtr), &extents);
00070                                         if      (extents.cx > MaxCX)
00071                                                 MaxCX = extents.cx;
00072                                 }
00073                 }       
00074         SendDlgItemMessage(hwndDlg, IDC_DRIVERLIST2, LB_SETCURSEL, (WPARAM)0, (LPARAM)0);
00075         SendDlgItemMessage(hwndDlg, IDC_DRIVERLIST2, LB_SETHORIZONTALEXTENT, (WPARAM)MaxCX, (LPARAM)0);
00076         ReleaseDC(ListBox, hDC);
00077         return GE_TRUE;
00078 }
00079 
00080 
00081 
00082 static  BOOL    CALLBACK        DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
00083 {
00084         DrvList_LocalStruct *DL = &DrvList_Locals;
00085                         
00086         switch  (uMsg)
00087         {
00088         case    WM_INITDIALOG:
00089                 {
00090                         HWND                    DriverListBox;
00091                         HDC                             hDC;
00092                         int                             MaxCX;
00093                         SIZE                    extents;
00094                         int                             DriverNumber;
00095                         int                             i,j;
00096 
00097                         DriverListBox = GetDlgItem(hwndDlg, IDC_DRIVERLIST);
00098                         hDC = GetDC(DriverListBox);
00099 
00100                         MaxCX = 0;
00101 
00102                         DriverNumber = 0;
00103                         for (i=0; i<DL->ModeListLength; i++)
00104                                 {
00105                                         int AlreadyAdded=0;
00106                                         
00107                                         for (j=0; j<i; j++)
00108                                                 {
00109                                                         if (DL->ModeList[j].Driver == DL->ModeList[i].Driver)   // only add one entry for each driver.
00110                                                                 AlreadyAdded = 1;
00111                                                 }
00112                                         
00113                                         if (!AlreadyAdded)
00114                                                 {
00115                                                         int index;
00116                                                         index = SendDlgItemMessage(hwndDlg, IDC_DRIVERLIST, LB_ADDSTRING, (WPARAM)0, (LPARAM)(DL->ModeList[i].DriverNamePtr));
00117                                                         SendDlgItemMessage(hwndDlg, IDC_DRIVERLIST, LB_SETITEMDATA, (WPARAM)index,(LPARAM)DriverNumber);
00118                                                         GetTextExtentPoint32(hDC, DL->ModeList[i].DriverNamePtr, strlen(DL->ModeList[i].DriverNamePtr), &extents);
00119                                                         if      (extents.cx > MaxCX)
00120                                                                 MaxCX = extents.cx;
00121                                                         DL->IndexTable[DriverNumber] = DL->ModeList[i].Driver;
00122                                                         DriverNumber ++;
00123                                                 }
00124                                         if (DriverNumber >= DRVLIST_MAX_DISPLAY_MODES)
00125                                                 break;
00126                                 }
00127                         DL->ModeListDriverCount = DriverNumber;
00128                 
00129                         SendDlgItemMessage(hwndDlg, IDC_DRIVERLIST, LB_SETCURSEL, (WPARAM)0, (LPARAM)0);
00130                         SendDlgItemMessage(hwndDlg, IDC_DRIVERLIST, LB_SETHORIZONTALEXTENT, (WPARAM)MaxCX, (LPARAM)0);
00131 
00132                         ReleaseDC(DriverListBox, hDC);
00133 
00134                         DrvList_FillModeList(hwndDlg,0,DL);
00135 
00136                         return TRUE;
00137                 }
00138                 break;
00139 
00140         case    WM_COMMAND:
00141                 switch (LOWORD(wParam))
00142                         {
00143                                 case IDC_DRIVERLIST:
00144                                         if (HIWORD(wParam) == LBN_SELCHANGE)
00145                                                 {
00146                                                         int Driver;
00147                                                         Driver = SendDlgItemMessage(hwndDlg, IDC_DRIVERLIST, LB_GETCURSEL, (WPARAM)0, (LPARAM)0);
00148                                                         if (Driver>=0)
00149                                                                 DrvList_FillModeList(hwndDlg,Driver,DL);
00150                                                 }
00151                                         break;
00152                                 case IDC_DRIVERLIST2:
00153                                         if (HIWORD(wParam) == LBN_DBLCLK)
00154                                                 {
00155                                                         int             index;
00156                                                         index = SendDlgItemMessage(hwndDlg, IDC_DRIVERLIST2, LB_GETCURSEL, (WPARAM)0, (LPARAM)0);
00157                                                         if (index>=0)
00158                                                                 {
00159                                                                         DL->Selection = SendDlgItemMessage(hwndDlg, IDC_DRIVERLIST2, LB_GETITEMDATA, index, 0);
00160                                                                         EndDialog(hwndDlg, DRVLIST_OK);
00161                                                                 }
00162                                                 }
00163                                         break;
00164                                 case IDOK:
00165                                         {
00166                                                 int             index;
00167                                                 index = SendDlgItemMessage(hwndDlg, IDC_DRIVERLIST2, LB_GETCURSEL, (WPARAM)0, (LPARAM)0);
00168                                                 if (index>=0)
00169                                                         {
00170                                                                 DL->Selection = SendDlgItemMessage(hwndDlg, IDC_DRIVERLIST2, LB_GETITEMDATA, index, 0);
00171                                                                 EndDialog(hwndDlg, DRVLIST_OK);
00172                                                         }
00173                                         }
00174                                         break;
00175                                 case IDCANCEL:
00176                                         EndDialog(hwndDlg, DRVLIST_CANCEL);
00177                                         break;
00178                         }
00179                 break;
00180         }
00181 
00182         return 0;
00183 }
00184 
00185 geBoolean DrvList_PickDriver(HANDLE hInstance, HWND hwndParent, 
00186                 ModeList *List, int ListLength, int *ListSelection)
00187 {
00188         int                             res;
00189         DrvList_LocalStruct *DL = &DrvList_Locals;
00190 
00191         assert( hInstance != 0 );
00192         assert( List  != NULL );
00193         assert( ListLength >=0 );
00194         assert( ListSelection != NULL );
00195 
00196         
00197         DL->ModeList                    = List;
00198         DL->ModeListLength              = ListLength;
00199         DL->ModeListDriverCount = 0;
00200         DL->Selection                   = -1;
00201 
00202         res = DialogBoxParam(hInstance,
00203                                                  MAKEINTRESOURCE(IDD_DRIVERDIALOG),
00204                                                  hwndParent,
00205                                                  DlgProc,
00206                                                  (LPARAM)0);
00207 
00208         *ListSelection = DL->Selection;
00209 
00210         if      (res == DRVLIST_OK || res == DRVLIST_CANCEL)
00211                 {
00212                         return GE_TRUE;
00213                 }
00214 
00215         return GE_FALSE;
00216 }

Generated on Tue Sep 30 12:35:40 2003 for GTestAndEngine by doxygen 1.3.2