home *** CD-ROM | disk | FTP | other *** search
/ PC Open 19 / pcopen19.iso / Zipped / CALMIR21.ZIP / SOURCE.ZIP / SRC / PROGCONV.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-02-20  |  5.4 KB  |  162 lines

  1. {**************************************************************************}
  2. {                                                                          }
  3. {    Calmira shell for Microsoft« Windows(TM) 3.1                          }
  4. {    Source Release 2.1                                                    }
  5. {    Copyright (C) 1997-1998 Li-Hsin Huang                                 }
  6. {                                                                          }
  7. {    This program is free software; you can redistribute it and/or modify  }
  8. {    it under the terms of the GNU General Public License as published by  }
  9. {    the Free Software Foundation; either version 2 of the License, or     }
  10. {    (at your option) any later version.                                   }
  11. {                                                                          }
  12. {    This program is distributed in the hope that it will be useful,       }
  13. {    but WITHOUT ANY WARRANTY; without even the implied warranty of        }
  14. {    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         }
  15. {    GNU General Public License for more details.                          }
  16. {                                                                          }
  17. {    You should have received a copy of the GNU General Public License     }
  18. {    along with this program; if not, write to the Free Software           }
  19. {    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             }
  20. {                                                                          }
  21. {**************************************************************************}
  22.  
  23. unit ProgConv;
  24.  
  25. { Program Group Converter.  This unit uses DDE to retrieve information
  26.   about groups from Program Manager, and puts them into a listbox.
  27.   When the user presses OK, each group is processed and the
  28.   OnConvertProg event is triggered for each item that is converted.
  29.  
  30.   Some Windows setups don't seem to respond to this properly.  An
  31.   alternative is reading in the group files, but the file format is
  32.   pretty hideous (and it's in the API help).
  33. }
  34.  
  35. interface
  36.  
  37. uses
  38.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  39.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, DdeMan;
  40.  
  41. type
  42.   TConvertProgEvent = procedure (Sender : TObject;
  43.     const group, caption: TFilename; const data: string) of object;
  44.  
  45.   TConvertDlg = class(TForm)
  46.     OKBtn: TBitBtn;
  47.     CancelBtn: TBitBtn;
  48.     GroupList: TListBox;
  49.     SortItems: TCheckBox;
  50.     Progman: TDdeClientConv;
  51.     procedure OKBtnClick(Sender: TObject);
  52.     procedure FormCreate(Sender: TObject);
  53.     procedure GroupListDblClick(Sender: TObject);
  54.     procedure FormDestroy(Sender: TObject);
  55.   private
  56.     { Private declarations }
  57.   public
  58.     { Public declarations }
  59.     OnConvertProg : TConvertProgEvent;
  60.   end;
  61.  
  62. var
  63.   ConvertDlg: TConvertDlg;
  64.  
  65. implementation
  66.  
  67. {$R *.DFM}
  68.  
  69. uses Strings, IniFiles, Start, MiscUtil, Settings, Desk, Locale;
  70.  
  71. { For each group in the list, RequestData is called to retrieve the
  72.   entire group contents as a long null terminated string.  Rather than
  73.   parsing this, it is quicker to assign it to a string list, which
  74.   separates it into lines, and even sorts them for you.  The first line
  75.   is always the group name, so it is discarded. }
  76.  
  77. procedure TConvertDlg.OKBtnClick(Sender: TObject);
  78. var
  79.   progs: TStringList;
  80.   p: PChar;
  81.   i, j, iconindex, mode: Integer;
  82.   cap, com, dir, iconfile: TFilename;
  83. begin
  84.   progs := TStringList.Create;
  85.   try
  86.     Desktop.SetCursor(crHourGlass);
  87.     for i := 0 to GroupList.Items.Count-1 do
  88.     if GroupList.Selected[i] then begin
  89.       progs.Clear;
  90.       try
  91.         p := Progman.RequestData(GroupList.Items[i]);
  92.         with progs do begin
  93.           Sorted := False;
  94.           SetText(p);
  95.           Delete(0); { Delete name of group }
  96.           Sorted := SortItems.Checked;
  97.         end;
  98.       finally
  99.         StrDispose(p);
  100.       end;
  101.  
  102.       for j := 0 to progs.Count-1 do begin
  103.         cap := '';
  104.         com := '';
  105.         dir := '';
  106.         iconfile := '';
  107.         iconindex := 0;
  108.         mode := 0;
  109.  
  110.         { Inspecting the data returned by Program Manager shows that
  111.           the fields are separated by commas and the first two are
  112.           enclosed in double quotes.  Some of the icon positions
  113.           are ignored }
  114.  
  115.         Unformat(progs[j], '"%s","%s",%s,%s,%D,%D,%d,%D,%d',
  116.           [@cap, 79, @com, 79, @dir, 79, @iconfile, 79, @iconindex, @mode]);
  117.         if Assigned(OnConvertProg) then
  118.           OnConvertProg(self, Trim(GroupList.Items[i]), Trim(cap),
  119.             PackStartInfo(com, dir, iconfile, mode, iconindex));
  120.       end;
  121.     end;
  122.   finally
  123.     progs.Free;
  124.     Desktop.ReleaseCursor;
  125.   end;
  126. end;
  127.  
  128.  
  129. procedure TConvertDlg.FormCreate(Sender: TObject);
  130. var
  131.   p: PChar;
  132. begin
  133.   if IsShell and (DdeMgr.AppName = 'PROGMAN') then
  134.     DdeMgr.AppName := 'CALMIRA';
  135.  
  136.   if Progman.OpenLink then
  137.     try
  138.       p := Progman.RequestData('Groups');
  139.       GroupList.Items.SetText(p);
  140.     finally
  141.       StrDispose(p);
  142.     end
  143.   else
  144.     ErrorMsgRes(SCannotFindProgman);
  145. end;
  146.  
  147.  
  148. procedure TConvertDlg.GroupListDblClick(Sender: TObject);
  149. begin
  150.   OKBtn.Click;
  151. end;
  152.  
  153. procedure TConvertDlg.FormDestroy(Sender: TObject);
  154. begin
  155.   if IsShell and ShellDDE then begin
  156.     Progman.ExecuteMacro('[ExitProgman(0)]', False);
  157.     DdeMgr.AppName := 'PROGMAN';
  158.   end;
  159. end;
  160.  
  161. end.
  162.