home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- * OPENDLG.C - Open File dialog box routines. *
- * *
- * Notes - *
- * This following functions will have to be modified in order to *
- * support OS/2 v1.2 long file names : *
- * *
- * FillListBoxes() *
- * *
- * Modifications - *
- * 11-Aug-1989 : Initial version. *
- * 07-Sep-1989 : Added file find function. *
- * 21-Sep-1989 : Cleaned up code to make it a little more readable. *
- * Separated open file and find file dialog procedures *
- * into separate files. *
- * Forced OPEN button to be default button whenever *
- * the focus passes to a non-pushbutton control. *
- * Eliminated duplicate error messages when enter key *
- * is used to select a list box item. *
- * 11-Oct-1989 : Changed to DLL version of ErrMessageBox function. *
- * 19-Nov-1989 : Fixed bug causing protection violation when the *
- * pszSearchSpec string is located in a read-only *
- * segment. *
- * *
- * (c)Copyright 1989 Rick Yoder *
- ****************************************************************************/
-
- #define INCL_WIN
- #define INCL_DOS
- #define INCL_DOSERRORS
- #include <os2.h>
-
- #include <string.h>
- #include <errmsg.h>
-
- #include "filedlg.h"
- #include "dialog.h"
- #include "tools.h"
- #include "static.h"
- #include "opendata.h" // definition of structure holding dialog box
- // static data (DATA & PDATA types).
-
- /****************************************************************************
- * Procedure declarations *
- ****************************************************************************/
- /* Open file dialog box procedures */
- MRESULT CALLBACK _OpenDlgProc( HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2 );
- static MRESULT near OpenInit( HWND hwnd,MPARAM mp2 );
- static MRESULT near DriveListbox( HWND hwnd,USHORT msg,
- MPARAM mp1,MPARAM mp2 );
- static MRESULT near DirListbox( HWND hwnd,USHORT msg,
- MPARAM mp1,MPARAM mp2 );
- static MRESULT near FileListbox( HWND hwnd,USHORT msg,
- MPARAM mp1,MPARAM mp2 );
- static MRESULT near FnameEditCtrl( HWND hwnd,USHORT msg,
- MPARAM mp1,MPARAM mp2 );
- static MRESULT near OpenButton( HWND hwnd,PDATA pData );
- static void near FillListBoxes( HWND hDlg,PDATA pData );
- static USHORT near OpenFile( HWND hDlg,PDATA pData );
- static void near ResetDefaultButton( HWND hwnd,PDATA pData );
-
- /* Find file dialog box procedures */
- extern MRESULT CALLBACK _FindDlgProc( HWND hwnd,USHORT msg,
- MPARAM mp1,MPARAM mp2 );
- /****************************************************************************/
-
-
- /****************************************************************************
- * FileOpenDlg() *
- ****************************************************************************/
- USHORT CALLBACK FileOpenDlg( HWND hwndOwner,
- PSZ pszTitle,PSZ pszIns,
- PSZ pszShowSpec,USHORT usShowAttr,
- void (CALLBACK *pfnHelpProc)(HWND hDlg),
- PSZ pszFile,
- PHFILE phf,
- ULONG ulFileSize,
- PUSHORT pusAction,
- USHORT usAttribute,
- USHORT fsOpenFlags,
- USHORT fsOpenMode,
- ULONG ulReserved )
- {
- USHORT usMaxPathLen;
- SEL sel;
- PDATA pData;
- USHORT rc;
- HMODULE hmod;
-
- /* Set pszTitle and pszIns to default if NULL */
- if ( pszTitle == NULL ) pszTitle = szDefOpenTitle;
- if ( pszIns == NULL ) pszIns = szDefOpenIns;
-
- /* Get maximum pathname length */
- DosQSysInfo( 0,(PBYTE)&usMaxPathLen,sizeof(USHORT) );
-
- /* Get module handle for filedlg dynamic-link library */
- if ( (rc = DosGetModHandle(szDLLName,&hmod)) )
- {
- ErrMessageBox( hwndOwner,pszTitle,rc,NULL,0 );
- return FDLG_CANCEL;
- }
-
- /* Allocate memory for dialog data */
- if ( (rc = DosAllocSeg(sizeof(DATA),&sel,SEG_NONSHARED)) )
- {
- ErrMessageBox( hwndOwner,pszTitle,rc,NULL,0 );
- return FDLG_CANCEL;
- }
- pData = MAKEP(sel,0);
-
- /* Allocate memory for search spec */
- if ( (rc = DosAllocSeg(usMaxPathLen,&sel,SEG_NONSHARED)) )
- {
- DosFreeSeg( SELECTOROF(pData) );
- ErrMessageBox( hwndOwner,pszTitle,rc,NULL,0 );
- return FDLG_CANCEL;
- }
- pData->pszShowSpec = MAKEP(sel,0);
-
- /* Allocate scratch data area */
- if ( (rc = DosAllocSeg(usMaxPathLen+3,&sel,SEG_NONSHARED)) )
- {
- DosFreeSeg( SELECTOROF(pData->pszShowSpec) );
- DosFreeSeg( SELECTOROF(pData) );
- ErrMessageBox( hwndOwner,pszTitle,rc,NULL,0 );
- return FDLG_CANCEL;
- }
- pData->pszScratch = MAKEP(sel,0);
-
- /* Set current drive and directory to drive and directory listed */
- /* in show file specification, and store filename portion of spec. */
- strcpy( pData->pszShowSpec,pszShowSpec );
- if ( rc = ParseFileName(pData->pszShowSpec,
- pData->pszScratch,
- szStarDotStar) )
- {
- ErrMessageBox( hwndOwner,pszTitle,rc,NULL,0 );
- strcpy( pData->pszShowSpec,szStarDotStar );
- }
- else
- strcpy( pData->pszShowSpec,strrchr(pData->pszScratch,'\\')+1 );
-
- /* Initialize contents of dialog box data structure */
- pData->pszTitle = pszTitle;
- pData->pszIns = pszIns;
- pData->pfnHelpProc = pfnHelpProc;
- pData->pszFile = pszFile;
- pData->phf = phf;
- pData->ulFileSize = ulFileSize;
- pData->pusAction = pusAction;
- pData->usAttribute = usAttribute;
- pData->fsOpenFlags = fsOpenFlags;
- pData->fsOpenMode = fsOpenMode;
- pData->ulReserved = ulReserved;
- pData->usShowAttr = usShowAttr;
- pData->usMaxPathLen = usMaxPathLen;
- pData->hmod = hmod;
- pData->usFocus = OPEN_FNAME;
-
- /* Activate open file dialog box */
- rc = WinDlgBox( HWND_DESKTOP,hwndOwner,_OpenDlgProc,
- hmod,IDD_OPEN,pData );
-
- /* Free resources */
- DosFreeSeg( SELECTOROF(pData->pszShowSpec) );
- DosFreeSeg( SELECTOROF(pData->pszScratch) );
- DosFreeSeg( SELECTOROF(pData) );
-
- return rc;
- }
- /****************************************************************************/
-
-
- /****************************************************************************
- * _OpenDlgProc() *
- ****************************************************************************/
- MRESULT CALLBACK _OpenDlgProc( HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2 )
- {
- PDATA pData;
-
- switch ( msg ) {
- case WM_INITDLG:
- return OpenInit( hwnd,mp2 );
-
- case WM_CHAR:
- if ( CHARMSG(&msg)->fs & KC_ALT )
- switch ( CHARMSG(&msg)->chr ) {
- case 'n':
- case 'N': WinSetFocus(HWND_DESKTOP,WinWindowFromID(hwnd,OPEN_FNAME));
- return 0;
-
- case 'r':
- case 'R': WinSetFocus(HWND_DESKTOP,WinWindowFromID(hwnd,OPEN_DRIVES));
- return 0;
-
- case 'd':
- case 'D': WinSetFocus(HWND_DESKTOP,WinWindowFromID(hwnd,OPEN_DIRLIST));
- return 0;
-
- case 'f':
- case 'F': WinSetFocus(HWND_DESKTOP,WinWindowFromID(hwnd,OPEN_FILELIST));
- return 0;
- }
- break;
-
- case WM_CONTROL:
- switch ( SHORT1FROMMP(mp1) ) {
- case OPEN_DRIVES:
- return DriveListbox( hwnd,msg,mp1,mp2 );
-
- case OPEN_DIRLIST:
- return DirListbox( hwnd,msg,mp1,mp2 );
-
- case OPEN_FILELIST:
- return FileListbox( hwnd,msg,mp1,mp2 );
-
- case OPEN_FNAME:
- return FnameEditCtrl( hwnd,msg,mp1,mp2 );
- }
- break;
-
- case WM_COMMAND:
- pData = (PDATA)WinQueryWindowULong( hwnd,QWL_USER );
- switch (COMMANDMSG(&msg)->cmd) {
- case OPEN_OK:
- return OpenButton( hwnd,pData );
-
- case DID_CANCEL:
- case OPEN_CANCEL:
- WinDismissDlg( hwnd,FDLG_CANCEL );
- return 0L;
-
- case OPEN_FIND:
- if ( FDLG_OK == WinDlgBox(HWND_DESKTOP,hwnd,
- _FindDlgProc,pData->hmod,
- IDD_FIND,pData)
- ) WinDismissDlg( hwnd,FDLG_OK );
- WinSetFocus( HWND_DESKTOP,
- WinWindowFromID(hwnd,OPEN_FNAME) );
- return 0L;
- }
- break;
-
- case WM_HELP:
- pData = (PDATA)WinQueryWindowULong( hwnd,QWL_USER );
- if ( pData->pfnHelpProc != NULL )
- {
- (*pData->pfnHelpProc)( hwnd );
- return 0L;
- }
- break;
- }
- return WinDefDlgProc( hwnd,msg,mp1,mp2 );
- }
- /****************************************************************************/
-
-
- /****************************************************************************
- * OpenInit() -- Process WM_INITDLG message for the open file dialog *
- * box. *
- ****************************************************************************/
- static MRESULT near OpenInit( HWND hwnd,MPARAM mp2 )
- {
- PDATA pData;
-
- pData = PVOIDFROMMP( mp2 );
- WinSetWindowULong( hwnd,QWL_USER,(ULONG)pData );
- if ( pData->pfnHelpProc == NULL )
- WinDestroyWindow( WinWindowFromID(hwnd,OPEN_HELP) );
- WinSetWindowText( WinWindowFromID(hwnd,FID_TITLEBAR),pData->pszTitle );
- WinSetDlgItemText( hwnd,OPEN_HLPTEXT,pData->pszIns );
- WinSendDlgItemMsg( hwnd,OPEN_FNAME,EM_SETTEXTLIMIT,
- MPFROMSHORT(pData->usMaxPathLen),NULL );
- FillListBoxes( hwnd,pData );
- return 0L;
- }
- /****************************************************************************/
-
-
- /****************************************************************************
- * DriveListbox() -- Handle messages sent by the disk drive list box to *
- * the open file dialog. *
- ****************************************************************************/
- static MRESULT near DriveListbox( HWND hwnd,USHORT msg,
- MPARAM mp1,MPARAM mp2 )
- {
- PDATA pData;
- USHORT usResult;
-
- pData = (PDATA)WinQueryWindowULong( hwnd,QWL_USER );
- switch ( SHORT2FROMMP(mp1) ) {
- case LN_ENTER:
- pData->usFocus = OPEN_DRIVES;
- WinSendDlgItemMsg( hwnd,OPEN_DRIVES,LM_QUERYITEMTEXT,
- MPFROM2SHORT(pData->usSelectDrive,pData->usMaxPathLen),
- MPFROMP(pData->pszScratch) );
- usResult = DosSelectDisk(pData->pszScratch[0]-'@');
- if ( usResult )
- ErrMessageBox( hwnd,pData->pszTitle,usResult,NULL,0 );
- else
- WinSendDlgItemMsg( hwnd,OPEN_OK,BM_CLICK,0L,0L );
- WinSendDlgItemMsg( hwnd,OPEN_DRIVES,LM_SELECTITEM,
- MPFROMSHORT(pData->usSelectDrive),
- MPFROMSHORT(TRUE) );
- return 0L;
-
- case LN_SETFOCUS:
- ResetDefaultButton( hwnd,pData );
- usResult = (USHORT)WinSendDlgItemMsg( hwnd,OPEN_DRIVES,
- LM_QUERYTOPINDEX,
- 0L,0L );
- if ( usResult != LIT_NONE )
- {
- if ( pData->usSelectDrive < usResult )
- pData->usSelectDrive = usResult;
- else if (pData->usSelectDrive > usResult+5)
- pData->usSelectDrive = usResult+5;
-
- WinSendDlgItemMsg( hwnd,OPEN_DRIVES,LM_SELECTITEM,
- MPFROMSHORT(pData->usSelectDrive),
- MPFROMSHORT(TRUE) );
- }
- return 0L;
-
- case LN_KILLFOCUS:
- WinSendDlgItemMsg( hwnd,OPEN_DRIVES,LM_SELECTITEM,
- MPFROMSHORT(pData->usSelectDrive),
- MPFROMSHORT(FALSE) );
- return 0L;
-
- case LN_SELECT:
- usResult = (USHORT)WinSendDlgItemMsg( hwnd,OPEN_DRIVES,
- LM_QUERYSELECTION,
- 0L,0L );
- if ( usResult != LIT_NONE ) pData->usSelectDrive = usResult;
- return 0L;
- }
-
- return WinDefDlgProc( hwnd,msg,mp1,mp2 );
- }
- /****************************************************************************/
-
-
- /****************************************************************************
- * DirListbox() -- Handle messages sent by directory list box to the *
- * open file dialog. *
- ****************************************************************************/
- static MRESULT near DirListbox( HWND hwnd,USHORT msg,
- MPARAM mp1,MPARAM mp2 )
- {
- PDATA pData;
- USHORT usResult;
-
- pData = (PDATA)WinQueryWindowULong( hwnd,QWL_USER );
- switch ( SHORT2FROMMP(mp1) ) {
- case LN_ENTER:
- pData->usFocus = OPEN_DIRLIST;
- WinSendDlgItemMsg( hwnd,OPEN_DIRLIST,
- LM_QUERYITEMTEXT,
- MPFROM2SHORT(pData->usSelectDir,pData->usMaxPathLen),
- MPFROMP(pData->pszScratch) );
- usResult = DosChDir(pData->pszScratch,0L);
- if ( usResult )
- ErrMessageBox( hwnd,pData->pszTitle,usResult,NULL,0 );
- else
- WinSendDlgItemMsg( hwnd,OPEN_OK,BM_CLICK,0L,0L );
- WinSendDlgItemMsg( hwnd,OPEN_DIRLIST,LM_SELECTITEM,
- MPFROMSHORT(pData->usSelectDir),
- MPFROMSHORT(TRUE) );
- return 0L;
-
- case LN_SETFOCUS:
- ResetDefaultButton( hwnd,pData );
- usResult = (USHORT)WinSendDlgItemMsg( hwnd,OPEN_DIRLIST,
- LM_QUERYTOPINDEX,
- 0L,0L );
- if ( usResult != LIT_NONE )
- {
- if ( pData->usSelectDir < usResult )
- pData->usSelectDir = usResult;
- else if (pData->usSelectDir > usResult+5)
- pData->usSelectDir = usResult+5;
-
- WinSendDlgItemMsg( hwnd,OPEN_DIRLIST,LM_SELECTITEM,
- MPFROMSHORT(pData->usSelectDir),
- MPFROMSHORT(TRUE) );
- }
- return 0L;
-
- case LN_KILLFOCUS:
- WinSendDlgItemMsg( hwnd,OPEN_DIRLIST,LM_SELECTITEM,
- MPFROMSHORT(pData->usSelectDir),
- MPFROMSHORT(FALSE) );
- return 0L;
-
- case LN_SELECT:
- usResult = (USHORT)WinSendDlgItemMsg( hwnd,OPEN_DIRLIST,
- LM_QUERYSELECTION,
- 0L,0L );
- if ( usResult != LIT_NONE ) pData->usSelectDir = usResult;
- return 0L;
- }
-
- return WinDefDlgProc( hwnd,msg,mp1,mp2 );
- }
- /****************************************************************************/
-
-
- /****************************************************************************
- * FileListbox() -- Handle messages sent by file list box the open dialog. *
- ****************************************************************************/
- static MRESULT near FileListbox( HWND hwnd,USHORT msg,
- MPARAM mp1,MPARAM mp2 )
- {
- PDATA pData;
- USHORT usResult;
-
- pData = (PDATA)WinQueryWindowULong( hwnd,QWL_USER );
- switch ( SHORT2FROMMP(mp1) ) {
- case LN_SELECT:
- usResult = (USHORT)WinSendDlgItemMsg( hwnd,OPEN_FILELIST,
- LM_QUERYSELECTION,
- 0L,0L );
- if ( usResult != LIT_NONE ) pData->usSelectFile = usResult;
- WinSendDlgItemMsg( hwnd,OPEN_FILELIST,
- LM_QUERYITEMTEXT,
- MPFROM2SHORT(pData->usSelectFile,pData->usMaxPathLen),
- MPFROMP(pData->pszScratch) );
- WinSetDlgItemText( hwnd,OPEN_FNAME,
- pData->pszScratch );
- return 0L;
-
- case LN_ENTER:
- pData->usFocus = OPEN_FILELIST;
- WinSendDlgItemMsg( hwnd,OPEN_FILELIST,
- LM_QUERYITEMTEXT,
- MPFROM2SHORT(pData->usSelectFile,pData->usMaxPathLen),
- MPFROMP(pData->pszScratch) );
- WinSetDlgItemText( hwnd,OPEN_FNAME,pData->pszScratch );
- WinSendDlgItemMsg( hwnd,OPEN_OK,BM_CLICK,0L,0L );
- return 0L;
-
- case LN_SETFOCUS:
- ResetDefaultButton( hwnd,pData );
- usResult = (USHORT)WinSendDlgItemMsg( hwnd,OPEN_FILELIST,
- LM_QUERYTOPINDEX,
- 0L,0L );
- if ( usResult != LIT_NONE )
- {
- if ( pData->usSelectFile < usResult )
- pData->usSelectFile = usResult;
- else if (pData->usSelectFile > usResult+8)
- pData->usSelectFile = usResult+8;
-
- WinSendDlgItemMsg( hwnd,OPEN_FILELIST,LM_SELECTITEM,
- MPFROMSHORT(pData->usSelectFile),
- MPFROMSHORT(TRUE) );
- }
- return 0L;
-
- case LN_KILLFOCUS:
- WinSendDlgItemMsg( hwnd,OPEN_FILELIST,LM_SELECTITEM,
- MPFROMSHORT(pData->usSelectFile),
- MPFROMSHORT(FALSE) );
- return 0L;
- }
-
- return WinDefDlgProc( hwnd,msg,mp1,mp2 );
- }
- /****************************************************************************/
-
-
- /****************************************************************************
- * FnameEditCtrl() -- Handles messages sent by OPEN_FNAME edit control *
- * to open file dialog box. *
- ****************************************************************************/
- static MRESULT near FnameEditCtrl( HWND hwnd,USHORT msg,
- MPARAM mp1,MPARAM mp2 )
- {
- USHORT usResult;
- PDATA pData;
-
- pData = (PDATA)WinQueryWindowULong( hwnd,QWL_USER );
-
- if ( SHORT2FROMMP(mp1) == EN_SETFOCUS )
- {
- ResetDefaultButton( hwnd,pData );
- usResult = WinQueryDlgItemTextLength( hwnd,OPEN_FNAME );
- WinSendDlgItemMsg( hwnd,OPEN_FNAME,EM_SETSEL,
- MPFROM2SHORT(0,usResult),0L );
- return 0L;
- }
-
- return WinDefDlgProc( hwnd,msg,mp1,mp2 );
- }
- /****************************************************************************/
-
-
- /****************************************************************************
- * OpenButton() - Procedure to executed when OPEN button is clicked. *
- ****************************************************************************/
- static MRESULT near OpenButton( HWND hwnd,PDATA pData )
- {
- HWND hwndButton;
-
- hwndButton = WinWindowFromID( hwnd,OPEN_OK );
-
- if ( hwndButton == WinQueryFocus(HWND_DESKTOP,FALSE) )
- {
- switch ( pData->usFocus ) {
- case OPEN_FNAME:
- case OPEN_FILELIST:
- WinQueryDlgItemText( hwnd,OPEN_FNAME,
- pData->usMaxPathLen,
- pData->pszScratch );
- if ( !OpenFile(hwnd,pData) ) WinDismissDlg( hwnd,FDLG_OK );
- break;
-
- case OPEN_DRIVES:
- case OPEN_DIRLIST:
- FillListBoxes( hwnd,pData );
- break;
- }
- WinSetFocus( HWND_DESKTOP,WinWindowFromID(hwnd,pData->usFocus) );
- pData->usFocus = OPEN_FNAME;
- }
-
- return 0L;
- }
- /****************************************************************************/
-
-
- /****************************************************************************
- * FillListBoxes() - Fill drive, directory, and file list boxes, and *
- * display the name of the current drive and directory *
- * in the OPEN_CURDIR control. *
- * *
- * This function uses the scratch data area. *
- * *
- * Currently, this function does not support OS/2 v1.2 *
- * long file names. To fix this, recompile using the *
- * OS/2 1.2 header files so as to use the updated *
- * definition of the FILEFINDBUF structure. *
- ****************************************************************************/
- static void near FillListBoxes( HWND hDlg,PDATA pData )
- {
- USHORT usDriveNum;
- ULONG ulMap;
- USHORT usResult;
- HDIR hdir;
- FILEFINDBUF findbuf;
- USHORT usCount;
-
- /* Clear current contents of list boxes and text controls */
- WinSendDlgItemMsg( hDlg,OPEN_DRIVES,LM_DELETEALL,NULL,NULL );
- WinSendDlgItemMsg( hDlg,OPEN_DIRLIST,LM_DELETEALL,NULL,NULL );
- WinSendDlgItemMsg( hDlg,OPEN_FILELIST,LM_DELETEALL,NULL,NULL );
- WinSetDlgItemText( hDlg,OPEN_CURDIR,"" );
- WinSetDlgItemText( hDlg,OPEN_FNAME,pData->pszShowSpec );
-
- pData->usSelectDrive = 0;
- pData->usSelectDir = 0;
- pData->usSelectFile = 0;
-
- /* Fill in disk drive list box */
- if ( usResult = DosQCurDisk(&usDriveNum,&ulMap) )
- {
- ErrMessageBox( hDlg,pData->pszTitle,usResult,NULL,0 );
- return;
- }
-
- pData->pszScratch[1] = ':';
- pData->pszScratch[2] = '\0';
- for ( usCount = 0; usCount < 26; usCount++ )
- if ( ulMap & 1L << usCount )
- {
- pData->pszScratch[0] = (CHAR)usCount + 'A';
-
- usResult = SHORT1FROMMR(
- WinSendDlgItemMsg( hDlg,OPEN_DRIVES,
- LM_INSERTITEM,
- MPFROMSHORT(LIT_END),
- MPFROMP(pData->pszScratch) )
- );
- if ( usCount == usDriveNum-1 )
- {
- WinSendDlgItemMsg( hDlg,OPEN_DRIVES,
- LM_SETTOPINDEX,
- MPFROMSHORT(usResult),
- 0L );
- pData->usSelectDrive = usResult;
- }
- }
-
- /* Set OPEN_CURDIR static text control to current drive/directory */
- usCount = pData->usMaxPathLen-3;
- if ( usResult = DosQCurDir(0,pData->pszScratch+3,&usCount) )
- {
- ErrMessageBox( hDlg,pData->pszTitle,usResult,NULL,0 );
- return;
- }
- pData->pszScratch[0] = (CHAR)usDriveNum + '@';
- pData->pszScratch[1] = ':';
- pData->pszScratch[2] = '\\';
- WinSetDlgItemText( hDlg,
- OPEN_CURDIR,
- FitPathToBox(hDlg,OPEN_CURDIR,pData->pszScratch) );
-
- /* Fill list box with subdirectories of current directory */
- hdir = HDIR_CREATE;
- usCount = 1;
- usResult = DosFindFirst( szStarDotStar,&hdir,FILE_DIRECTORY,&findbuf,
- sizeof(findbuf),&usCount,0L );
-
- while ( !usResult )
- {
- if ( (findbuf.attrFile & FILE_DIRECTORY)
- && (findbuf.achName[0] != '.' || findbuf.achName[1]) )
- {
- WinSendDlgItemMsg( hDlg,OPEN_DIRLIST,LM_INSERTITEM,
- MPFROMSHORT(LIT_END),
- MPFROMP(findbuf.achName) );
- }
- usResult = DosFindNext( hdir,&findbuf,sizeof(findbuf),&usCount );
- }
-
- if ( usResult != ERROR_NO_MORE_SEARCH_HANDLES ) DosFindClose(hdir);
- if ( usResult && usResult != ERROR_NO_MORE_FILES )
- {
- ErrMessageBox( hDlg,pData->pszTitle,usResult,NULL,0 );
- return;
- }
-
- /* Fill file list box with list of files that match search specs. */
- hdir = HDIR_CREATE;
- usCount = 1;
- usResult = DosFindFirst( pData->pszShowSpec,&hdir,
- pData->usShowAttr,&findbuf,
- sizeof(findbuf),&usCount,0L );
-
- while ( !usResult )
- {
- WinSendDlgItemMsg( hDlg,OPEN_FILELIST,LM_INSERTITEM,
- MPFROMSHORT(LIT_END),
- MPFROMP(findbuf.achName) );
-
- usResult = DosFindNext( hdir,&findbuf,sizeof(findbuf),&usCount );
- }
-
- if ( usResult != ERROR_NO_MORE_SEARCH_HANDLES ) DosFindClose(hdir);
- if ( usResult && usResult != ERROR_NO_MORE_FILES )
- ErrMessageBox( hDlg,pData->pszTitle,usResult,NULL,0 );
-
- /* Done. Return to caller. */
- return;
- }
- /****************************************************************************/
-
-
- /****************************************************************************
- * OpenFile() - This function attempts to open the file specified *
- * in the scratch data area, or if the file is a search *
- * specification, updates the contents of the list boxes. *
- * *
- * This function returns a non-zero value if an error occured *
- * or the input string was a search specification. *
- ****************************************************************************/
- static USHORT near OpenFile( HWND hDlg,PDATA pData )
- {
- USHORT usResult;
-
- usResult = ParseFileName( pData->pszScratch,
- pData->pszFile,
- pData->pszShowSpec );
- if ( usResult )
- {
- ErrMessageBox( hDlg,pData->pszTitle,usResult,NULL,0 );
- return 1;
- }
-
- if ( NULL != strpbrk(pData->pszFile,szWildCardChars) )
- {
- strcpy( pData->pszShowSpec,strrchr(pData->pszFile,'\\')+1 );
- FillListBoxes( hDlg,pData );
- return 1;
- }
- else
- {
- usResult = DosOpen( pData->pszFile,
- pData->phf,
- pData->pusAction,
- pData->ulFileSize,
- pData->usAttribute,
- pData->fsOpenFlags,
- pData->fsOpenMode,
- pData->ulReserved );
- if ( usResult )
- {
- ErrMessageBox( hDlg,pData->pszTitle,usResult,NULL,0 );
- return 1;
- }
- else
- return 0;
- }
- }
- /****************************************************************************/
-
-
- /****************************************************************************
- * ResetDefaultButton() - Makes the OPEN button the default pushbutton *
- * whenever the focus is passed to a non-pushbutton *
- * control. *
- ****************************************************************************/
- static void near ResetDefaultButton( HWND hwnd,PDATA pData )
- {
- ULONG ulStyle;
-
- ulStyle = WinQueryWindowULong( WinWindowFromID(hwnd,OPEN_OK),
- QWL_STYLE );
- if ( !(ulStyle & BS_DEFAULT) )
- {
- /* Make OPEN button default */
- WinSendDlgItemMsg( hwnd,OPEN_OK,BM_SETDEFAULT,
- MPFROMSHORT(TRUE),0L );
-
- /* Remove default attribute from CANCEL button */
- ulStyle = WinQueryWindowULong( WinWindowFromID(hwnd,OPEN_CANCEL),
- QWL_STYLE );
- if ( ulStyle & BS_DEFAULT )
- WinSendDlgItemMsg( hwnd,OPEN_CANCEL,BM_SETDEFAULT,
- MPFROMSHORT(FALSE),0L );
-
- /* Remove default attribute from FIND button */
- ulStyle = WinQueryWindowULong( WinWindowFromID(hwnd,OPEN_FIND),
- QWL_STYLE );
- if ( ulStyle & BS_DEFAULT )
- WinSendDlgItemMsg( hwnd,OPEN_FIND,BM_SETDEFAULT,
- MPFROMSHORT(FALSE),0L );
-
- /* Remove default attribute from HELP button */
- if ( pData->pfnHelpProc != NULL )
- {
- ulStyle = WinQueryWindowULong( WinWindowFromID(hwnd,OPEN_HELP),
- QWL_STYLE );
- if ( ulStyle & BS_DEFAULT )
- WinSendDlgItemMsg( hwnd,OPEN_HELP,BM_SETDEFAULT,
- MPFROMSHORT(FALSE),0L );
- }
- }
-
- return;
- }
- /****************************************************************************/
-