home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 19
/
CD_ASCQ_19_010295.iso
/
win
/
prg
/
cenviw
/
progman.lib
< prev
next >
Wrap
Text File
|
1994-09-19
|
13KB
|
314 lines
// ProgMan.lib - Library for interacting with Program Manager
// ver.2 through DDE.
//
//
//**** IsProgmanRunning()
// SYNTAX: bool IsProgmanRunning()
// RETURN: Returns true if Progman DDE is working
// NOTE: This routines simply calls ConnectToProgman() and CloseProgmanConnection()
//
//
//**** ConnectToProgman(): Initialize DDE Client connection to Progman
// SYNTAX: bool ConnectToProgman()
// RETURN: Return TRUE if able to connect, else False
// NOTE: The other funcitons in this library will connect by themselves if
// this routine has not already been called, but if you are doing
// a lot of Program Manager calls then it will go faster to call this
// once in the beginning and call CloseProgmanConnection() once at the end.
//
//
//**** CloseProgmanConnection(): terminate DDE Client connection
// SYNTAX: void CloseProgmanConnection()
// NOTE: This should be called once for each ConnectToProgman() call. See
// ConnectToProgman() for more notes.
//
//
//**** CreateGroup(): Create group in Program Mnager
// SYNTAX: bool CreateGroup(string GroupName[,bool CommonGroupFlag])
// WHERE: GroupName: Text name for the new group
// CommonGroupFlag: False for personal group, else CommonGroup; default=False
// RETURN: False on error, else success
//
//
//**** DeleteGroup(): Delete group from Program Mnager
// SYNTAX: bool DeleteGroup(string GroupName[,bool CommonGroupFlag])
// WHERE: GroupName: Text name for the existing group
// CommonGroupFlag: False for personal group, else CommonGroup; default=False
// RETURN: False on error, else success
//
//
//**** ShowGroup(): Set display state for group
// SYNTAX: bool ShowGroup(string GroupName,int ShowCommand[,bool CommonGroupFlag])
// WHERE: GroupName: Text name for the existing group
// ShowCommand: One of the following values for display state
#define PMG_RESTORE 1 // Activates and displays the group window. If the window is minimized or maximized, Windows
// restores it to its original size and position.
#define PMG_SHOWMIN 2 // Activates the group window and displays it as an icon.
#define PMG_SHOWMAX 3 // Activates the group window and displays it as a maximized window.
#define PMG_SHOWNOACTIVATE 4 // Displays the group window in its most recent size and position. The window that is currently
// active remains active.
#define PMG_SHOWACTIVE 5 // Activates the group window and displays it in its current size and position.
#define PMG_SHOWMIN 6 // Minimizes the group window.
#define PMG_SHOWMINNOACTIVE 7 // Displays the group window as an icon. The currently active window remains active.
#define PMG_SHOWNA 8 // Displays the group window in its current state. The currently active window remains active.
// CommonGroupFlag: False for personal group, else CommonGroup; default=False
// RETURN: False on error, else success
//
//
//**** Reload(): Remove and reload group
// SYNTAX: bool Reload([string GroupName[,bool CommonGroupFlag]])
// WHERE: GroupName: Text name for the existing group
// CommonGroupFlag: False for personal group, else CommonGroup; default=False
// RETURN: False on error, else success
// NOTE: You can use this command after making modification to update new group information
//
//
//**** AddItem(): Add Program Item to existing group
// SYNTAX: bool AddItem(string CmdLine[,string Name[,string IconPath[,int IconIndex[,int xPos,int yPos
// [,string DefDir[,int HotKey[,bool fMinimize]]]]]]])
// WHERE: CmdLine: Full Command Line to run application and optional parameters
// Name: The title below the icon
// IconPath: Filespec for the icon to display
// IconIndex: Index of icon in IconPathl; -1 for default
// xPos, yPos: Where to display icon in the group window; both -1 for default
// DefDir: Default directory
// HotKey: shortcut key to launch this item; 0 for no hotkey
// can OR key value with the following for combinations
#define HOT_SHIFT 0x100
#define HOT_CTRL 0x200
#define HOT_ALT 0x400
// fMinimize: boolean to minimize application window when launched
// RETURN: False on error, else success
// NOTE: Parameters that are not supplied or are NULL (strings) get default
//
//
//**** DeleteItem(): Delete Program Item from existing group
// SYNTAX: bool DeleteItem(string ItemName)
// WHERE: ItemName: Text name for item to remove
// RETURN: False on error, else success
//
//
//**** ReplaceItem(): Delete Program Item and save position for AddItem()
// SYNTAX: bool ReplaceItem(string ItemName)
// WHERE: ItemName: Text name for item to remove
// RETURN: False on error, else success
//
//
//**** ExitProgman(): Terminate Program Manager
// SYNTAX: bool ExitProgman(bool SaveGroups)
// WHERE: SaveGroups: If True then save groups before closing
// RETURN: False on error, else success
//
//
//**** ProgmanGroups(): Query Program Manager for a list of all groups
// SYNTAX: bool ProgmanGroups(string[] GroupList[,int GroupCount])
// WHERE: GroupList: Returned array of GroupNames
// GroupCount: How many groups available (also 1 + GetArraySpan(GroupList))
// MODIFIES: Modify GroupList and GroupCount
// RETURN: False on error, else success
//
//
//**** ProgmanGroupItems(): Enumerate items in group
// SYNTAX: bool ProgmanGroupItems(string GroupName,struct GroupInfo[,struct[] ItemList])
// WHERE: GroupName: Text name for the existing group
// GroupInfo: structure to receive data about this grouo, with members:
// .Name: string for name of this group
// .Path: string for group Path
// .Count: integer number of elements in this group
// .State: integer state as defined in ShowGroup()
// ItemList: If this parameter specified, then will receive an array of
// information about each item in this group
// (GroupInfo.Count elemenst), with these members
// .Description: string item text description
// .CommandLine: execution command string
// .WorkingDirectory: string path for item working directory
// .IconFile: string path for file conatining icon
// .IconID: integer Icon identifier in .IconFile
// .Col: integer column position of this item in group window
// .Row: integer row position of this item in group window
// .ShortcutKey: integer item shortcut execute key combination
// .RunMinized: bool False to run maximized, else minimized
// MODIFIES: creates GroupInfo and (if supplied) ItemList
// RETURN: False on error, else success
//
//
//
#include <DDEcli.lib>
gProgmanConnectCount = 0;
gProgmanDdeSession;
ConnectToProgman()
{
if ( 0 == gProgmanConnectCount++ ) {
gProgmanDdeSession.Application = gProgmanDdeSession.Topic = "PROGMAN";
gProgmanDdeSession.TerminateFunction = "ProgmanHasDisconnected";
if ( !ConnectToServer(gProgmanDdeSession) )
gProgmanConnectCount = 0;
}
return( 0 != gProgmanConnectCount );
}
ProgmanHasDisconnected(pddeSession)
{
if ( gProgmanConnectCount ) {
printf("\aError. Program manager has disconnected");
abort();
}
}
CloseProgmanConnection()
{
if ( gProgmanConnectCount && 0 == --gProgmanConnectCount )
DisconnectFromServer(gProgmanDdeSession);
}
IsProgmanRunning()
{
lRunning = ConnectToProgman();
CloseProgmanConnection();
return lRunning;
}
CreateGroup(pGroupName,pCommonGroupFlag)
{
if ( 1 == va_arg() )
sprintf(lCmd,"[CreateGroup(\"%s\")]",pGroupName);
else
sprintf(lCmd,"[CreateGroup(\"%s\",%d)]",pGroupName,pCommonGroupFlag?1:0);
return ProgmanDdeExecute(lCmd);
}
ShowGroup(pGroupName,pShowCommand,pCommonGroupFlag)
{
if ( 2 == va_arg() )
sprintf(lCmd,"[ShowGroup(\"%s\",%d)]",pGroupName,pShowCommand);
else
sprintf(lCmd,"[ShowGroup(\"%s\",%d,%d)]",pGroupName,pShowCommand,pCommonGroupFlag?1:0);
return ProgmanDdeExecute(lCmd);
}
DeleteGroup(pGroupName,pCommonGroupFlag)
{
if ( 1 == va_arg() )
sprintf(lCmd,"[DeleteGroup(\"%s\")]",pGroupName);
else
sprintf(lCmd,"[DeleteGroup(\"%s\",%d)]",pGroupName,pCommonGroupFlag?1:0);
return ProgmanDdeExecute(lCmd);
}
Reload(pGroupName,pCommonGroupFlag)
{
strcpy(lCmd,"[Reload(");
if ( va_arg() && pGroupName ) sprintf(lCmd+strlen(lCmd),"\"%s\"",pGroupName);
if ( 1 < va_arg() ) sprintf(lCmd+strlen(lCmd),",%d",pCommonGroupFlag?1:0);
strcat(lCmd,")]");
return ProgmanDdeExecute(lCmd);
}
AddItem(pCmdLine,pName,pIconPath,pIconIndex,pxPos,pyPos,pDefDir,pHotKey,pfMinimize)
{
lArgC = va_arg();
sprintf(lCmd,"[AddItem(%s",pCmdLine);
if ( 1 < lArgC ) sprintf(lCmd+strlen(lCmd),",%s",pName ? pName : "");
if ( 2 < lArgC ) sprintf(lCmd+strlen(lCmd),",%s",pIconPath ? pIconPath : "");
if ( 3 < lArgC ) sprintf(lCmd+strlen(lCmd),-1 == pIconIndex ? "," : ",%d", pIconIndex);
if ( 4 < lArgC ) sprintf(lCmd+strlen(lCmd),",%d,%d",pxPos,pyPos);
if ( 6 < lArgC ) sprintf(lCmd+strlen(lCmd),",%s",pDefDir ? pDefDir : "");
if ( 7 < lArgC ) sprintf(lCmd+strlen(lCmd),",%d",pHotKey);
if ( 8 < lArgC ) strcat(lCmd,pfMinimize ? ",1" : ",0");
strcat(lCmd,")]");
return ProgmanDdeExecute(lCmd);
}
DeleteItem(pItemName)
{
sprintf(lCmd,"[DeleteItem(%s)]",pItemName);
return ProgmanDdeExecute(lCmd);
}
ReplaceItem(pItemName)
{
sprintf(lCmd,"[ReplaceItem(%s)]",pItemName);
return ProgmanDdeExecute(lCmd);
}
ExitProgman(pbSaveGroups)
{
sprintf( lCmd, "[ExitProgman(%d)]", pbSaveGroups ? 1 : 0 );
return ProgmanDdeExecute(lCmd);
}
ProgmanDdeExecute(pExecuteCommandString)
{
lSuccess = False;
if ( ConnectToProgman() ) {
if ( DdeExecute(gProgmanDdeSession,pExecuteCommandString) )
lSuccess = True;
CloseProgmanConnection();
}
return lSuccess;
}
ProgmanGroups(pGroupList,pCount)
{
bool lSuccess = False;
undefine(pGroupList);
if ( ConnectToProgman() ) {
if ( lData = RequestDataFromServer(gProgmanDdeSession,"Groups") ) {
for ( lCount = 0, lGroupName = strtok(lData,"\r\n");
NULL != lGroupName; lCount++, lGroupName = strtok(NULL,"\r\n") )
lSuccess = True, strcpy(pGroupList[lCount],lGroupName);
}
CloseProgmanConnection();
}
if ( 1 < va_arg() ) pCount = lCount;
return lSuccess;
}
ProgmanGroupItems(pGroupName,pGroupInfo,pItemList)
{
bool lSuccess = False;
undefine(pGroupInfo);
if ( ConnectToProgman() ) {
if ( lData = RequestDataFromServer(gProgmanDdeSession,pGroupName) ) {
// first line of data looks something like: "Main",C:\WIN\MAIN.GRP,9,4
if ( (lGroupStr = strtok(lData,"\r\n"))
&& 4 == sscanf(lGroupStr,"%*c%[^\"]%*2c%[^,]%*c%d,%d",lG.Name,lG.Path,lG.Count,lG.State) ) {
pGroupInfo = lG;
lSuccess = True;
if ( 2 < va_arg() ) {
undefine(pItemList);
for ( lg.Count = 0; lItemStr = strtok(NULL,"\r\n"); ) {
// each line like: "CEnvi","C:\CENVIW\CENVI.EXE",C:\CENVIW,C:\CENVIW\CENVI.EXE,174,0,0,0,0
undefine(lI);
lDescription = lItemStr + 1;
if ( lItemStr = strstr(lItemStr+1,"\",\"") ) {
lItemStr[0] = 0;
lCommandLine = lItemStr + 3;
if ( lItemStr = strstr(lItemStr+4,"\",") ) {
lItemStr[0] = 0;
lWorkingDirectory = lItemStr + 2;
if ( lItemStr = strchr(lItemStr+2,',') ) {
lItemStr[0] = 0;
if ( 6 == sscanf(lItemStr+1,"%[^,]%*c%d,%d,%d,%d,%d",
lI.IconFile,lI.Col,lI.Row,lI.IconID,lI.ShortcutKey,lI.RunMinimized) ) {
strcpy(lI.Description,lDescription);
strcpy(lI.CommandLine,lCommandLine);
strcpy(lI.WorkingDirectory,lWorkingDirectory);
pItemList[lg.Count++] = lI;
}
}
}
}
}
}
}
}
CloseProgmanConnection();
}
return lSuccess;
}