;;Program manager WBT script.  Adding/Deleting/Showing Program Manager Groups and Icons.  

                    ;;Written February 1994  by Wilson WindowWare, Inc.  
                    ;;Modifed July 1995

;;Call Progman.wil
;;Syntax of commands:
;;    Call("progman.wil", "AddGroup 'Group Title'")
;;        (             , "DelGroup 'Group Title'")
;;        (             , "AddIcon 'Group Title' 'File and Path' 'Icon Description''wrk dir'")
;;        (             , "DelIcon 'Group Title' 'Icon Description'")
;;        (             , "ShowGroup 'Group Title' ShowCommand")
;;        (             , "ReplaceItem 'Group Title' 'Icon Description'")
;;        (             , "Reload 'Group Title'")
;;        (             , "IconDump 'Group Title''Icon Description' 'variable name'")
;;        (             , "ProgBuild 'Group Title''variable name'")
;;        (             , "ListGroups")    ; Sets variable GROUP to tab delimited list of groups
;;    Call("progman.wil", "AddNewData '%grptitle%', '%data%'")

 
;;Show command is an integer which specifies the action Program Manager is to perform on the group window.
;;        VALUE          ACTION
;;          1               Restores group to its original size and position.
;;          2               Displays group as an icon.
;;          3               Displays group as a maximized window.
;;          6               Minimizes the group window.
;;                                 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Check to see if Program manager is running.  If not, run it.
AX=DDEInitiate("Progman", "Progman")
IF AX==0    ; Hmmm nobody's home
    run("progman.exe","")
    delay(2)
    AX=DDEInitiate("Progman", "Progman")
    If AX==0     ;   ooooo its really dead.  Give up
         Message("Program Manager DDE Initiate", "Didn't work.  Giving up.  Going home")
         return 
    endif
endif


ErrorMode(@OFF)
If AppExist("Progman.exe")  then WinActivate("Program Manager")
ErrorMode(@ON)
ErrorMSG=""
; Fake a case statement with a string for a variable
Goto %Param1%
           


:ADDGROUP
;Add a group to program manager.                                                              
     
Err=DDEExecute(AX,"[CreateGroup(%param2%)]")
If Err==0 then ErrorMSG="[CreateGroup(%param2%)] Failed"
goto byebye



:ListGroups
;List groups.                                                              
Groups=DDERequest(AX,"Groups")
If Groups==0 then ErrorMSG="Groups Failed"
Groups=strreplace(groups,@crlf,@tab)
goto byebye



:DELGROUP
;Delete a group from the program manager.
     
Err=DDEExecute(AX,"[DeleteGroup(%param2%)]")
If Err==0 then ErrorMSG="[DeleteGroup(%param2%)] Failed"
goto byebye



:ADDICON
;Add an icon to a program group.

;show or create the group first.
DDEExecute(AX,"[CreateGroup(%param2%)]")
;Add the item.     
Err=DDEExecute(AX,"[AddItem(%param3%,%param4%,,,-1,-1,%param5%,0)]")
If Err==0 then ErrorMSG="[AddItem(%param3%,%param4%,,,-1,-1,%param5%,0)] Failed"
goto byebye





:DELICON
;Delete an icon from the program manager.

;show or create the group
DDEExecute(AX,"[ShowGroup(%param2%,1)]")
;Delete the icon.     
Err=DDEExecute(AX,"[DeleteItem(%param3%)]")
If Err==0 then ErrorMSG="[DeleteItem(%param3%)] Failed"
goto byebye




:SHOWGROUP
;Show a program group. 
     
;show or create the group
Err=DDEExecute(AX,"[ShowGroup(%param2%,%param3%,)]")
If Err==0 then ErrorMSG="[ShowGroup(%param2%,%param3%,)] Failed"
goto byebye




:RELOAD
;This command instructs Program Manager to remove and reload an existing group.

;Show the group.
DDEExecute(AX,"[ShowGroup(%param2%,1)]")
delay(2)
Err=DDEExecute(AX,"[Reload(%param2%)")
If Err==0 then ErrorMSG="[Reload("")] Failed"
goto byebye




:REPLACEITEM
;This command deletes an item and records the position.  A new item can be added to this 
;position using AddIcon.

;Show the group.
DDEExecute(AX,"[ShowGroup(%param2%,1)]")
delay(2)

;record the position and delete existing group.
Err=DDEExecute(AX,"[ReplaceItem(%param3%)]")
If Err==0 then ErrorMSG="[ReplaceItem(%param3%)] Failed"
goto byebye

:ADDNEWDATA
;Add an icon by adding all information. Use with Progbuild or IconDump to create line.

;show or create the group first.
DDEExecute(AX,"[CreateGroup(%param2%)]")
;Add the item.     
Err=DDEExecute(AX,"[AddItem(%param3%)]")
If Err==0 then ErrorMSG="[AddItem(%param3%)] Failed"
goto byebye


:IconDump 
;;This command accesses a group and then searches the group for a specific icon title.
;;The DDE Syntax for the icon is returned to the calling program as a variable.
;;Open a channel to a specified Group

groups= DDERequest(AX, param2)
groups = StrReplace(groups, @crlf, @tab)
groups = ItemSort(groups, @tab)
count=ItemCount(groups,@tab)
For j = 1 to count by 1
        item = ItemExtract(j, groups, @tab)
        itemicon=ItemExtract(1, item, ",")
        if '"%param3%"'==itemicon then break   ;; Compare each line to the specified icon title.
Next            
if '"%param3%"'!=itemicon      ;;If the specified icon title is found, break loop.
        ErrorMSG="[IconDump] Failed"
        break
else
        %param4%=item   ;;icon title is set to equal and then returned as the supplied variable name.
        grptitle="%param2%"
endif
goto byebye


:PROGBUILD
;;This command accesses a group and then searches the group for a specific icon title.
;;The DDE Syntax for the icon is returned to the calling program as a variable.
while @true
        groups= DDERequest(AX, "Groups")                ;;Create a list of all Groups.
        groups = StrReplace(groups, @crlf, @tab)
        groups = ItemSort(groups, @tab)
        group=AskItemList("Groups", groups, @tab, @unsorted, @single)   ;;Display a list box
           grptitle="%group%"
           items = DDERequest(AX, group)                 ;;Create a list of icons within chosen group.
           items = StrReplace(items, @crlf, @tab)
           items = ItemRemove(1, items, @tab)
           items = ItemSort(items, @tab)
           item=AskItemList("Groups", items, @tab, @unsorted, @single)       ;;Display a list box
        %param2%=item     ;;icon title is set to equal and then returned as the supplied variable name.
        break
endwhile

If groups == "***NACK***" Then ErrorMSG="[ProgBuild(groups)] Failed "    
If items == "***NACK***" Then ErrorMSG="[ProgBuild(items)] Failed"
If item == "" Then ErrorMSG="[ProgBuild (item)] Failed"
goto byebye

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
:byebye
DDETerminate(AX)
If ErrorMSG!="" then message("Progman DDE Failed", ErrorMSG)
RETURN

