home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
BKUPINI.ZIP
/
INIPGMS.SAV
< prev
next >
Wrap
Text File
|
1990-05-20
|
45KB
|
1,012 lines
#define EXTERN
#include "INIPGMS.h"
/************************************************************************/
/* */
/* Presentation Manager Program Main Body */
/* */
/* The following routine is the Presentation Manager program Main Body. */
/* The Main Body of a PM program is concerned with associating the */
/* application with the Presentation Manager system, creating its */
/* message queue, registering and displaying its main window, servicing */
/* its message queue during the time that the application is active, */
/* and disassociating the application from PM when the user is finished */
/* with the application. The remaining parts of this source module that */
/* are concerned with the Presentation Manager are the application's */
/* window procedures (main window procedure, child window procedures, */
/* and dialog window procedures) that process the messages associated */
/* with the application's various windows. */
/* */
/************************************************************************/
SHORT cdecl main(argc, argv)
int argc;
char *argv[];
{
QMSG qmsg; // MSG structure to store your messages
PID pid; // Process identifier for adding name to switch list
TID tid; // Thread identifier
// The WinInitialize routine initializes the Presentation Manager
// facilities for use by this application and returns a handle to the
// anchor block assigned to the application by PM.
if((hAB = WinInitialize(NULL)) == NULL)
return(FALSE);
// The WinCreateMsgQueue call creates a message queue for this application.
if((hMQ = WinCreateMsgQueue(hAB, 0)) == NULL)
return(FALSE);
// The following function registers the classes of all application windows.
if(!RegisterClass())
return(FALSE);
// The CreateWindow function creates a frame window for this application's
// top window, and set the window's size and location as appropriate.
hWndFrame = CreateWindow((HWND)HWND_DESKTOP,
FCF_TITLEBAR |
FCF_SYSMENU |
FCF_MINBUTTON |
FCF_MAXBUTTON |
FCF_SIZEBORDER |
FCF_MENU |
FCF_SHELLPOSITION,
szAppName,
"OS2 INI File Management",
ID_INIPGMS,
0, 0,
0, 0,
&hWndClient,
0L, SWP_SHOW);
if(hWndFrame == NULL)
return(FALSE);
// The following in-line routine fills out the application's switch control
// structure with the appropriate information to add the application's name
// to the OS/2 Task Manager List, a list of the jobs currently running on
// the computer.
WinQueryWindowProcess(hWndFrame, &pid, &tid);
pSwctl.hwnd = hWndFrame; // Frame window handle
pSwctl.idProcess = pid; // Process identifier
pSwctl.uchVisibility = SWL_VISIBLE; // visibility
pSwctl.fbJump = SWL_JUMPABLE; // Jump indicator
strcpy(pSwctl.szSwtitle, "OS2 INI File Management"); // Frame window title
hSwitch = WinAddSwitchEntry(&pSwctl);
// The following is the message loop for the application.
while(WinGetMsg(hAB, (PQMSG)&qmsg, NULL, 0, 0))
WinDispatchMsg(hAB,(PQMSG)&qmsg);
// Perform clean up before exiting application.
// The following routine destroys the application's frame window (which
// also destroys its child windows), destroys its message queue, and
// disassociates the application from the Presentation Manager system.
WinDestroyWindow(hWndFrame); // Destroy the frame window
WinDestroyMsgQueue(hMQ); // Destroy this application's message clue
WinTerminate(hAB); // Terminate this application's use of the
// Presentation Manager resources
} // end of main
// The following Dialog box calls are generated for the dialog boxes that
// have been selected as "Client Area" dialog boxes. To use these calls,
// simply copy them to the appropriate location in the application.
#if 0
WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)DSPLGRPSMsgProc,
NULL, IDLG_DSPLGRPS, NULL);
WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)SAVEPGMSMsgProc,
NULL, IDLG_SAVEPGMS, NULL);
WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)BKUPRUNMsgProc,
NULL, IDLG_BKUPRUN, NULL);
#endif
/************************************************************************/
/* */
/* Main Window Procedure */
/* */
/* This procedure provides service routines for the general PM events */
/* (messages) that PM sends to the window, as well as the user */
/* initiated events (messages) that are generated when the user selects */
/* the action bar and pulldown menu controls or the corresponding */
/* keyboard accelerators. */
/* */
/* The SWITCH statement shown below distributes the window messages to */
/* the respective message service routines, which are set apart by the */
/* CASE statements. The window procedures must provide an appropriate */
/* service routine for its end user initiated messages, as well as the */
/* general PM messages (like the WM_CLOSE message). If a message is */
/* sent to this procedure for which there is no programmed CASE clause */
/* (i.e., no service routine), the message is defaulted to the */
/* WinDefWindowProc function, where it is disposed of by PM. */
/* */
/************************************************************************/
MRESULT EXPENTRY WndProc(hWnd, message, mp1, mp2)
HWND hWnd;
USHORT message;
MPARAM mp1;
MPARAM mp2;
{ // Beginning of message processor
HPS hPS; // Handle for the Presentation Space
RECTL rClient; // Handle to rectangle formed by client area
USHORT rc; // common return code value
switch(message)
{
case WM_COMMAND:
// The PM messages for action bar and pulldown menu items are
// processed in this routine.
switch(SHORT1FROMMP(mp1))
{
case IDM_FILE_OPENINIFILE:
// Place User Code to respond to the
// Menu Item Named "~Open .INI file..." here.
rc = WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)OPENINIMsgProc,
NULL, IDLG_OPENINI, NULL);
break;
case IDM_FILE_EXTRACTFROMSYSTEM:
// Place User Code to respond to the
// Menu Item Named "~Extract from system..." here.
/* Extract Function Goes Here */
hiniSource = HINI_USERPROFILE ;
hiniTarget = hiniUser ;
WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)DSPLGRPSMsgProc,
NULL, IDLG_DSPLGRPS, NULL) ;
break;
case IDM_FILE_RELOADTOSYSTEM:
// Place User Code to respond to the
// Menu Item Named "~Reload to System..." here.
/* Reload goes here */
hiniSource = hiniUser;
hiniTarget = HINI_USERPROFILE;
WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)DSPLGRPSMsgProc,
NULL, IDLG_DSPLGRPS, NULL) ;
break;
case IDM_FILE_BACKUPSYSTEMINIS:
// Place User Code to respond to the
// Menu Item Named "~Backup system INIs..." here.
rc = WinDlgBox(HWND_DESKTOP, hWnd, (PFNWP)BKSYSINIMsgProc,
NULL, IDLG_BKSYSINI, NULL);
break;
case IDM_FILE_EXIT:
// Place User Code to respond to the
// Menu Item Named "E~xit" here.
/* Exit Code Goes Here */
WinPostMsg(hWnd, WM_CLOSE, 0L, 0L);
break;
default:
break; // End of default case for switch(mp1)
}
break; // End of WM_COMMAND
case WM_CREATE:
// The WM_CREATE message is sent to a window when an application
// requests that the window be created. The window procedure for
// the new window receives this message after the window is
// created, but before the window becomes visible.
//
/* Allocate Memory for Data Operations */
if( !DosAllocSeg( WORKAREASIZE,
(PSEL)&SELECTOROF( pvoidWorkAreaOrigin ),
SEG_NONSHARED))
OFFSETOF( pvoidWorkAreaOrigin ) = 0;
pvoidWorkArea = pvoidWorkAreaOrigin ;
ulWorkAreaSize = WORKAREASIZE ;
hiniUser = NULL ;
szUserIni[0] = '\0' ;
break; // End of WM_CREATE
case WM_MOUSEMOVE:
return(WinDefWindowProc(hWnd, message, mp1, mp2));
break;
case WM_SIZE: // code for sizing client area
break; // End of WM_SIZE
case WM_PAINT: // code for the window's client area
// Obtain a handle to a cache presentation space
hPS = WinBeginPaint(hWnd, NULL, NULL);
// Determine the size of the client area
WinQueryWindowRect(hWnd, &rClient);
// Fill the background with the default background color
WinFillRect(hPS, &rClient, CLR_BACKGROUND);
// return presentation space to state before WinBeginPaint
WinEndPaint(hPS);
break; // End of WM_PAINT
case WM_CLOSE: // close the window
if(hWnd != hWndClient)
break;
if( hiniUser ) PrfCloseProfile( hiniUser ) ;
DosFreeSeg( SELECTOROF( pvoidWorkAreaOrigin ) );
WinPostMsg(hWnd, WM_QUIT, 0L, 0L);
break; // End of WM_CLOSE
default:
// For any message for which you don't specifically provide a
// service routine, you should return the message to PM using
// the WinDefWindowProc function.
return(WinDefWindowProc(hWnd, message, mp1, mp2));
break; // End of default
}
return(0L);
} // End of WndProc
/************************************************************************/
/* */
/* Dialog Window Procedure */
/* */
/* This procedure is associated with the dialog box that is included in */
/* the function name of the procedure. It provides the service routines */
/* for the events (messages) that occur because the end user operates */
/* one of the dialog box's buttons, entry fields, or controls. */
/* */
/* The SWITCH statement in the function distributes the dialog box */
/* messages to the respective service routines, which are set apart by */
/* the CASE clauses. Like any other PM window, the Dialog Window */
/* procedures must provide an appropriate service routine for their end */
/* user initiated messages as well as for the general PM messages (like */
/* the WM_CLOSE message). If a message is sent to this procedure for */
/* which there is no programmed CASE condition (no service routine), */
/* the message is defaulted to the WinDefDlgProc function, where it is */
/* disposed of by PM. */
/* */
/************************************************************************/
MRESULT EXPENTRY DSPLGRPSMsgProc(hWndDlg, message, mp1, mp2)
HWND hWndDlg;
USHORT message;
MPARAM mp1;
MPARAM mp2;
{
SHORT i;
BOOL fSuccess ;
ULONG ulBufferMax ;
USHORT ulNumPgmEnts, ulPgmEntCtr, sSelect ;
switch(message)
{
case WM_INITDLG:
WinSendDlgItemMsg (hWndDlg, DsplGrps_GrpList,
LM_DELETEALL, NULL, NULL) ;
ulBufferMax = ulWorkAreaSize ;
if( !hiniSource )
{
if( !WinDlgBox(HWND_DESKTOP, hWndDlg,
(PFNWP)OPENINIMsgProc,
NULL, IDLG_OPENINI, NULL) )
{
WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL),0L);
break ;
}
hiniSource = hiniUser ;
}
fSuccess = PrfQueryProfileData( hiniSource,
"PM_ProgramList000", "ProgramEntry",
pvoidWorkArea,
&ulBufferMax ) ;
PgmEntPtr = PgmEntPtrSel = (PROGRAMENTRY *)pvoidWorkArea ;
ulPgmEntSize = ulBufferMax +1 ;
(PBYTE)PgmEntPtrEnd = (PBYTE)pvoidWorkArea + ulPgmEntSize ;
(PBYTE)pvoidWorkArea = (PBYTE)PgmEntPtrEnd +1 ;
ulWorkAreaSize -= ulPgmEntSize+1 ;
for( ulNumPgmEnts = ulBufferMax/sizeof(PROGRAMENTRY),
ulPgmEntCtr = 0 ;
ulPgmEntCtr < ulNumPgmEnts ;
ulPgmEntCtr++, PgmEntPtrSel++ )
{
WinSendDlgItemMsg(hWndDlg, DsplGrps_GrpList, LM_INSERTITEM,
MPFROM2SHORT (LIT_SORTASCENDING, 0),
MPFROMP (PgmEntPtrSel->szTitle)) ;
}
*(PCHAR)pvoidWorkArea = '\0' ;
break; // End of WM_INITDLG
case WM_CONTROL:
switch(SHORT1FROMMP(mp1))
{
case DsplGrps_GrpList: // List box
sSelect = (USHORT) WinSendDlgItemMsg (hWndDlg,
DsplGrps_GrpList,
LM_QUERYSELECTION, 0L, 0L) ;
WinSendDlgItemMsg(hWndDlg, DsplGrps_GrpList,
LM_QUERYITEMTEXT,
MPFROM2SHORT(sSelect, ulWorkAreaSize),
MPFROMP(pvoidWorkArea)) ;
if( SHORT2FROMMP( mp1 ) == LN_ENTER )
WinPostMsg(hWndDlg, WM_COMMAND,
MPFROM2SHORT(DID_OK,0), 0L);
break;
}
break; // End of WM_CONTROL
case WM_COMMAND:
switch(SHORT1FROMMP(mp1))
{
case DID_OK:
if( !strlen( (PSZ)pvoidWorkArea ) ) break ;
for( PgmEntPtrSel = PgmEntPtr ;
strcmp((PSZ)pvoidWorkArea, PgmEntPtrSel->szTitle) ;
PgmEntPtrSel++ ) ;
WinDlgBox(HWND_DESKTOP, hWndDlg, (PFNWP)SAVEPGMSMsgProc,
NULL, IDLG_SAVEPGMS, NULL);
*(PCHAR)pvoidWorkArea = '\0' ;
break ;
WinDismissDlg(hWndDlg, TRUE);
break;
case DID_CANCEL:
// Ignore data values entered into the dialog controls
// and dismiss the dialog window
WinDismissDlg(hWndDlg, FALSE);
break;
}
break; // End of WM_COMMAND
case WM_CLOSE:
WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
break; // End of WM_CLOSE
default:
return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
break;
}
return FALSE;
} /* End of DSPLGRPSMsgProc */
/************************************************************************/
/* */
/* Dialog Window Procedure */
/* */
/* This procedure is associated with the dialog box that is included in */
/* the function name of the procedure. It provides the service routines */
/* for the events (messages) that occur because the end user operates */
/* one of the dialog box's buttons, entry fields, or controls. */
/* */
/* The SWITCH statement in the function distributes the dialog box */
/* messages to the respective service routines, which are set apart by */
/* the CASE clauses. Like any other PM window, the Dialog Window */
/* procedures must provide an appropriate service routine for their end */
/* user initiated messages as well as for the general PM messages (like */
/* the WM_CLOSE message). If a message is sent to this procedure for */
/* which there is no programmed CASE condition (no service routine), */
/* the message is defaulted to the WinDefDlgProc function, where it is */
/* disposed of by PM. */
/* */
/************************************************************************/
MRESULT EXPENTRY SAVEPGMSMsgProc(hWndDlg, message, mp1, mp2)
HWND hWndDlg;
USHORT message;
MPARAM mp1;
MPARAM mp2;
{
SHORT i;
HPROGRAM hprogUserGrp ;
ULONG cchBufferMax, ulCount, ulWork, ulGrpKeyLen,
ulKeyDataSize, ulDetailsLen ;
PVOID pvoidKeyData ;
PSZ pszKeyName ;
USHORT sSelect ;
switch(message)
{
case WM_INITDLG:
WinSendDlgItemMsg (hWndDlg, SavePgms_Titles,
LM_DELETEALL, NULL, NULL) ;
WinSendDlgItemMsg(hWndDlg, SavePgms_GrpName, EM_SETTEXTLIMIT,
MPFROM2SHORT (80, 0), NULL) ;
WinSendDlgItemMsg(hWndDlg, SavePgms_Txt1, EM_SETTEXTLIMIT,
MPFROM2SHORT (80, 0), NULL) ;
WinSetDlgItemText (hWndDlg, SavePgms_GrpName, PgmEntPtrSel->szTitle) ;
if( hiniSource == HINI_USERPROFILE )
WinSetDlgItemText (hWndDlg, SavePgms_Txt1,
"Select Installed Programs(s) to Save") ;
else
WinSetDlgItemText (hWndDlg, SavePgms_Txt1,
"Select Installed Programs(s) to Restore") ;
pTitles = (PPROGTITLE)pvoidWorkArea ;
ulTitlesSize = PrfQueryProgramTitles( hiniSource,
PgmEntPtrSel->hprog,
pTitles,
ulWorkAreaSize,
&ulCount ) ;
(PBYTE)pTitlesEnd = (PBYTE)pTitles + ulTitlesSize ;
for( ulWork = 0 ; ulWork < ulCount ; ulWork++, pTitles++ )
{
WinSendDlgItemMsg(hWndDlg, SavePgms_Titles, LM_INSERTITEM,
MPFROM2SHORT (LIT_END, 0),
MPFROMP (pTitles->pszTitle)) ;
}
pTitles = (PPROGTITLE)pvoidWorkArea ;
(PBYTE)pvoidWorkArea = (PBYTE)pTitlesEnd + 1 ;
ulWorkAreaSize -= ulTitlesSize + 1 ;
break; // End of WM_INITDLG
case WM_CONTROL:
switch(SHORT1FROMMP(mp1))
{
case SavePgms_Titles: // List box
{
}
break;
}
break; // End of WM_CONTROL
case WM_COMMAND:
switch(SHORT1FROMMP(mp1))
{
case DID_OK:
sSelect = (USHORT)WinSendDlgItemMsg(hWndDlg,
SavePgms_Titles,
LM_QUERYSELECTION,
MPFROMSHORT(LIT_FIRST),
0L ) ;
if( sSelect == LIT_NONE ) break ;
if( !hiniTarget )
{
if( !WinDlgBox(HWND_DESKTOP, hWndDlg,
(PFNWP)OPENINIMsgProc,
NULL, IDLG_OPENINI, NULL) ) break ;
hiniTarget = hiniUser ;
}
hprogUserGrp = PrfCreateGroup( hiniTarget,
PgmEntPtrSel->szTitle,
SHE_VISIBLE ) ;
ulGrpKeyLen = ulWorkAreaSize ;
if( PrfQueryProfileData( hiniSource,
PgmEntPtrSel->szTitle,
NULL,
pvoidWorkArea,
&ulGrpKeyLen ) )
{
(PBYTE)pvoidKeyData = (PBYTE)pvoidWorkArea +
ulGrpKeyLen + 1 ;
for( pszKeyName = (PSZ)pvoidWorkArea;
strlen(pszKeyName) ;
pszKeyName += strlen(pszKeyName)+1 )
{
ulKeyDataSize = ulWorkAreaSize -
(ulGrpKeyLen + 1) ;
PrfQueryProfileData( hiniSource,
PgmEntPtrSel->szTitle,
pszKeyName,
pvoidKeyData,
&ulKeyDataSize ) ;
PrfWriteProfileData( hiniTarget,
PgmEntPtrSel->szTitle,
pszKeyName,
pvoidKeyData,
ulKeyDataSize ) ;
}
}
for( sSelect = (USHORT)WinSendDlgItemMsg(hWndDlg,
SavePgms_Titles,
LM_QUERYSELECTION,
MPFROMSHORT(LIT_FIRST),
0L ) ;
sSelect != LIT_NONE;
sSelect = (USHORT)WinSendDlgItemMsg(hWndDlg,
SavePgms_Titles,
LM_QUERYSELECTION,
MPFROMSHORT(sSelect),
0L ) )
{
ulDetailsLen = PrfQueryDefinition( hiniSource,
(pTitles+sSelect)->hprog,
(PPROGDETAILS)pvoidWorkArea,
ulWorkAreaSize ) ;
PrfAddProgram( hiniTarget, (PPROGDETAILS)pvoidWorkArea,
hprogUserGrp ) ;
}
WinDismissDlg(hWndDlg, TRUE);
break;
case DID_CANCEL:
// Ignore data values entered into the dialog controls
// and dismiss the dialog window
WinDismissDlg(hWndDlg, FALSE);
break;
}
break; // End of WM_COMMAND
case WM_CLOSE:
WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
break; // End of WM_CLOSE
default:
return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
break;
}
return FALSE;
} /* End of SAVEPGMSMsgProc */
/************************************************************************/
/* */
/* Dialog Window Procedure */
/* */
/* This procedure is associated with the dialog box that is included in */
/* the function name of the procedure. It provides the service routines */
/* for the events (messages) that occur because the end user operates */
/* one of the dialog box's buttons, entry fields, or controls. */
/* */
/* The SWITCH statement in the function distributes the dialog box */
/* messages to the respective service routines, which are set apart by */
/* the CASE clauses. Like any other PM window, the Dialog Window */
/* procedures must provide an appropriate service routine for their end */
/* user initiated messages as well as for the general PM messages (like */
/* the WM_CLOSE message). If a message is sent to this procedure for */
/* which there is no programmed CASE condition (no service routine), */
/* the message is defaulted to the WinDefDlgProc function, where it is */
/* disposed of by PM. */
/* */
/************************************************************************/
MRESULT EXPENTRY OPENINIMsgProc(hWndDlg, message, mp1, mp2)
HWND hWndDlg;
USHORT message;
MPARAM mp1;
MPARAM mp2;
{
SHORT i;
USHORT sSelect, CurDisk ;
ULONG DriveMap ;
UCHAR buffer[80] ;
PSZ IniMask = "*.ini" ;
switch(message)
{
case WM_INITDLG:
WinSendDlgItemMsg(hWndDlg, OpenIni_CWD, EM_SETTEXTLIMIT,
MPFROM2SHORT (80, 0), NULL) ;
WinSendDlgItemMsg(hWndDlg, OpenIni_IniName, EM_SETTEXTLIMIT,
MPFROM2SHORT (8, 0), NULL) ;
WinSetDlgItemText (hWndDlg, OpenIni_IniName, "") ;
CurDir2DlgText( hWndDlg, OpenIni_CWD ) ;
DrvList2DlgBox( hWndDlg, OpenIni_DriveList) ;
DirList2DlgBox( hWndDlg, OpenIni_DirList) ;
FileList2DlgBox( hWndDlg, OpenIni_FileList, IniMask) ;
break; // End of WM_INITDLG
case WM_CONTROL:
switch(SHORT1FROMMP(mp1))
{
case OpenIni_IniName: // Entry field
break;
case OpenIni_DriveList: // List box
sSelect = (USHORT) WinSendDlgItemMsg (hWndDlg,
OpenIni_DriveList,
LM_QUERYSELECTION, 0L, 0L) ;
WinSendDlgItemMsg(hWndDlg, OpenIni_DriveList,
LM_QUERYITEMTEXT,
MPFROM2SHORT(sSelect, sizeof buffer),
MPFROMP(buffer)) ;
if( SHORT2FROMMP( mp1 ) != LN_ENTER ) break;
DosQCurDisk( &CurDisk, &DriveMap );
if(DosSelectDisk (buffer [1] - '@')!=0)
DosSelectDisk ( CurDisk );
WinPostMsg(hWndDlg, WM_INITDLG, 0L, 0L);
break;
case OpenIni_DirList: // List box
sSelect = (USHORT) WinSendDlgItemMsg (hWndDlg,
OpenIni_DirList,
LM_QUERYSELECTION, 0L, 0L) ;
WinSendDlgItemMsg(hWndDlg, OpenIni_DirList,
LM_QUERYITEMTEXT,
MPFROM2SHORT(sSelect, sizeof buffer),
MPFROMP(buffer)) ;
if( SHORT2FROMMP( mp1 ) != LN_ENTER ) break;
strcpy(buffer,buffer);
for(i=1; i<=strlen(buffer)&&buffer[i]!=']';i++)
buffer[i-1]=buffer[i];
buffer[i-1]=0x00;
DosChDir(buffer, 0L) ;
WinPostMsg(hWndDlg, WM_INITDLG, 0L, 0L);
break;
case OpenIni_FileList: // List box
sSelect = (USHORT) WinSendDlgItemMsg (hWndDlg,
OpenIni_FileList,
LM_QUERYSELECTION, 0L, 0L) ;
if( sSelect == LIT_NONE ) break ;
WinSendDlgItemMsg(hWndDlg, OpenIni_FileList,
LM_QUERYITEMTEXT,
MPFROM2SHORT(sSelect, sizeof buffer),
MPFROMP(buffer)) ;
for(sSelect = 0; buffer[sSelect] != '.'; sSelect++ ) ;
buffer[sSelect] = '\0' ;
WinSetDlgItemText (hWndDlg, OpenIni_IniName, buffer) ;
if( SHORT2FROMMP( mp1 ) != LN_ENTER ) break;
WinPostMsg(hWndDlg, WM_COMMAND, MPFROM2SHORT(DID_OK,0L), 0L);
break;
}
break; // End of WM_CONTROL
case WM_COMMAND:
switch(SHORT1FROMMP(mp1))
{
case DID_OK:
if( !WinQueryDlgItemText(hWndDlg,
OpenIni_IniName,
ulWorkAreaSize,
pvoidWorkArea ) ) break ;
if( hiniUser ) PrfCloseProfile( hiniUser ) ;
WinQueryDlgItemText(hWndDlg, OpenIni_CWD,
sizeof(szUserIni), szUserIni ) ;
strcat( szUserIni, (PSZ)pvoidWorkArea ) ;
strcat( szUserIni, ".INI" ) ;
hiniUser = PrfOpenProfile( hAB, szUserIni ) ;
WinDismissDlg(hWndDlg, TRUE);
break;
case DID_CANCEL:
// Ignore data values entered into the dialog controls
// and dismiss the dialog window
WinDismissDlg(hWndDlg, FALSE);
break;
}
break; // End of WM_COMMAND
case WM_CLOSE:
WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
break; // End of WM_CLOSE
default:
return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
break;
}
return FALSE;
} /* End of OPENINIMsgProc */
/************************************************************************/
/* */
/* Dialog Window Procedure */
/* */
/* This procedure is associated with the dialog box that is included in */
/* the function name of the procedure. It provides the service routines */
/* for the events (messages) that occur because the end user operates */
/* one of the dialog box's buttons, entry fields, or controls. */
/* */
/* The SWITCH statement in the function distributes the dialog box */
/* messages to the respective service routines, which are set apart by */
/* the CASE clauses. Like any other PM window, the Dialog Window */
/* procedures must provide an appropriate service routine for their end */
/* user initiated messages as well as for the general PM messages (like */
/* the WM_CLOSE message). If a message is sent to this procedure for */
/* which there is no programmed CASE condition (no service routine), */
/* the message is defaulted to the WinDefDlgProc function, where it is */
/* disposed of by PM. */
/* */
/************************************************************************/
MRESULT EXPENTRY BKSYSINIMsgProc(hWndDlg, message, mp1, mp2)
HWND hWndDlg;
USHORT message;
MPARAM mp1;
MPARAM mp2;
{
SHORT i;
VOID APIENTRY Backup_Ini() ;
USHORT sSelect, CurDisk ;
ULONG DriveMap ;
UCHAR buffer[MAXNAMEL+1] ;
#define SEGSIZE 4096
#define ALLOCFLAGS 0
TID ThreadId ;
SEL ThreadStackSel ;
PBYTE StackEnd ;
switch(message)
{
case WM_INITDLG:
CurDir2DlgText( hWndDlg, Bksysini_CWD ) ;
DrvList2DlgBox( hWndDlg, Bksysini_DriveList) ;
DirList2DlgBox( hWndDlg, Bksysini_DirList) ;
break; // End of WM_INITDLG
case WM_CONTROL:
switch(SHORT1FROMMP(mp1))
{
case Bksysini_DriveList: // List box
sSelect = (USHORT) WinSendDlgItemMsg (hWndDlg,
Bksysini_DriveList,
LM_QUERYSELECTION, 0L, 0L) ;
WinSendDlgItemMsg(hWndDlg, Bksysini_DriveList,
LM_QUERYITEMTEXT,
MPFROM2SHORT(sSelect, sizeof buffer),
MPFROMP(buffer)) ;
if( SHORT2FROMMP( mp1 ) != LN_ENTER ) break;
DosQCurDisk( &CurDisk, &DriveMap );
if(DosSelectDisk (buffer [1] - '@')!=0)
DosSelectDisk ( CurDisk );
WinPostMsg(hWndDlg, WM_INITDLG, 0L, 0L);
break;
case Bksysini_DirList: // List box
sSelect = (USHORT) WinSendDlgItemMsg (hWndDlg,
Bksysini_DirList,
LM_QUERYSELECTION, 0L, 0L) ;
WinSendDlgItemMsg(hWndDlg, Bksysini_DirList,
LM_QUERYITEMTEXT,
MPFROM2SHORT(sSelect, sizeof buffer),
MPFROMP(buffer)) ;
if( SHORT2FROMMP( mp1 ) != LN_ENTER ) break;
strcpy(buffer,buffer);
for(i=1; i<=strlen(buffer)&&buffer[i]!=']';i++)
buffer[i-1]=buffer[i];
buffer[i-1]=0x00;
DosChDir(buffer, 0L) ;
WinPostMsg(hWndDlg, WM_INITDLG, 0L, 0L);
break;
}
break; // End of WM_CONTROL
case WM_COMMAND:
switch(SHORT1FROMMP(mp1))
{
case DID_OK:
WinQueryDlgItemText(hWndDlg, Bksysini_CWD,
WORKAREASIZE, pvoidWorkArea ) ;
DosAllocSeg( SEGSIZE, &ThreadStackSel, ALLOCFLAGS ) ;
StackEnd = MAKEP(ThreadStackSel, SEGSIZE-1) ;
DosCreateThread((PFNTHREAD)Backup_Ini, &ThreadId, StackEnd);
WinDlgBox(HWND_DESKTOP, hWndDlg, (PFNWP)BKUPRUNMsgProc,
NULL, IDLG_BKUPRUN, NULL);
DosFreeSeg( ThreadStackSel );
WinDismissDlg(hWndDlg, TRUE);
break;
case DID_CANCEL:
// Ignore data values entered into the dialog controls
// and dismiss the dialog window
WinDismissDlg(hWndDlg, FALSE);
break;
}
break; // End of WM_COMMAND
case WM_CLOSE:
WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
break; // End of WM_CLOSE
default:
return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
break;
}
return FALSE;
} /* End of BKSYSINIMsgProc */
/************************************************************************/
/* */
/* Dialog Window Procedure */
/* */
/* This procedure is associated with the dialog box that is included in */
/* the function name of the procedure. It provides the service routines */
/* for the events (messages) that occur because the end user operates */
/* one of the dialog box's buttons, entry fields, or controls. */
/* */
/* The SWITCH statement in the function distributes the dialog box */
/* messages to the respective service routines, which are set apart by */
/* the CASE clauses. Like any other PM window, the Dialog Window */
/* procedures must provide an appropriate service routine for their end */
/* user initiated messages as well as for the general PM messages (like */
/* the WM_CLOSE message). If a message is sent to this procedure for */
/* which there is no programmed CASE condition (no service routine), */
/* the message is defaulted to the WinDefDlgProc function, where it is */
/* disposed of by PM. */
/* */
/************************************************************************/
MRESULT EXPENTRY BKUPRUNMsgProc(hWndDlg, message, mp1, mp2)
HWND hWndDlg;
USHORT message;
MPARAM mp1;
MPARAM mp2;
{
SHORT i;
#define SLEEPSHORT 5L
switch(message)
{
case WM_INITDLG:
hwndThreadWaiter = hWndDlg ;
break; // End of WM_INITDLG
case WM_CONTROL:
switch(SHORT1FROMMP(mp1))
{
}
break; // End of WM_CONTROL
case WM_COMMAND:
switch(SHORT1FROMMP(mp1))
{
case DID_OK:
WinDismissDlg(hWndDlg, TRUE);
break;
case DID_CANCEL:
// Ignore data values entered into the dialog controls
// and dismiss the dialog window
WinDismissDlg(hWndDlg, FALSE);
break;
case THREAD_GONE:
DosSleep( SLEEPSHORT ) ;
WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
break ;
}
break; // End of WM_COMMAND
case WM_CLOSE:
WinPostMsg(hWndDlg, WM_COMMAND, MPFROMSHORT(DID_CANCEL), 0L);
break; // End of WM_CLOSE
default:
return(WinDefDlgProc(hWndDlg, message, mp1, mp2));
break;
}
return FALSE;
} /* End of BKUPRUNMsgProc */
/************************************************************************/
/* */
/* RegisterClass Function */
/* */
/* The following function registers all the classes of all the windows */
/* associated with this application. The function returns TRUE if it is */
/* successful, otherwise it returns FALSE. */
/* */
/************************************************************************/
INT RegisterClass()
{
INT rc;
strcpy(szAppName, "INIPGMS");
rc = WinRegisterClass(hAB, // Anchor block handle
(PCH)szAppName, // Name of class being registered
(PFNWP)WndProc, // Window procedure for class
CS_SIZEREDRAW ,
NULL); // Extra bytes to reserve
if (rc == FALSE)
return(FALSE);
return(TRUE);
} // End of RegisterClass
/************************************************************************/
/* */
/* CreateWindow Function */
/* */
/* The following function is used to create a window (the main window, */
/* a child window, an icon window, etc.) and set it's initial size and */
/* position. It returns the handle to the frame window. */
/* */
/************************************************************************/
HWND CreateWindow(
HWND hWndParent, // Handle to the parent of the window to be created
ULONG ctldata, // Frame control flags for the window
PCH appname, // Class name of the window
PCH title, // Title of the window
USHORT ResID, // Resource id value
INT x, // Initial horizontal and vertical location of origin
INT y,
INT cx, // Initial width and height of the window
INT cy,
PHWND hWndClient, // Handle to the client area of the window
ULONG lfStyle, // Frame window style
USHORT uSizeStyle) // User defined size and location flags
{
USHORT rc; // accepts return codes from function calls
HWND hWndFrame; // local handle to created window frame
USHORT SizeStyle; // local window positioning options
CHAR MsgBuffer[80]; // buffer for error messages
// Create the frame window
hWndFrame = WinCreateStdWindow(hWndParent, // parent of window
lfStyle, // frame window style
&ctldata, // frame flags
appname, // class name
title, // window title
0L, // client window style
NULL, // module for resources
ResID, // resource id
(HWND FAR *)hWndClient); // client handle
// if hWndFrame is NULL, an error occured when opening the window, notify
// the user and exit this function
if(hWndFrame == NULL)
{
WinLoadString(hAB, NULL, IDS_ERR_WINDOW_CREATE, 80, MsgBuffer);
WinMessageBox(HWND_DESKTOP, hWndParent, MsgBuffer,
NULL, NULL, MB_OK|MB_ICONEXCLAMATION);
return((HWND)NULL);
}
// set up size options
SizeStyle = SWP_ACTIVATE | SWP_ZORDER | uSizeStyle;
// if the either the intial x or y position of the window is non-zero,
// set the window to its new position
if((x > 0) || (y > 0))
SizeStyle |= SWP_MOVE;
// if either the width or the height are non-zero, then the size of the
// created window will be changed, set SizeStyle accordingly
if((cx > 0) || (cy > 0))
SizeStyle |= SWP_SIZE;
// set the size and position of the window and activate it
rc = WinSetWindowPos(hWndFrame, HWND_TOP, x, y, cx, cy, SizeStyle);
// if rc is not set to TRUE then WinSetWindowPos failed, notify the user
// and exit this function
if(!rc)
{
WinLoadString(hAB, NULL, IDS_ERR_WINDOW_POS, 80, MsgBuffer);
WinMessageBox(HWND_DESKTOP, hWndParent, MsgBuffer,
NULL, NULL, MB_OK|MB_ICONEXCLAMATION);
return((HWND)NULL);
}
// return the handle to the frame window
return(hWndFrame);
} // End of CreateWindow