home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 April A / Pcwk4a98.iso / PROGRAM / DELPHI16 / Calmira / Src / SRC / PROGCONV.PAS < prev    next >
Pascal/Delphi Source File  |  1997-02-15  |  5KB  |  145 lines

  1. {**************************************************************************}
  2. {                                                                          }
  3. {    Calmira shell for Microsoft« Windows(TM) 3.1                          }
  4. {    Source Release 1.0                                                    }
  5. {    Copyright (C) 1997  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.   private
  54.     { Private declarations }
  55.   public
  56.     { Public declarations }
  57.     OnConvertProg : TConvertProgEvent;
  58.   end;
  59. {
  60. var
  61.   ConvertDlg: TConvertDlg;
  62. }
  63.  
  64. implementation
  65.  
  66. {$R *.DFM}
  67.  
  68. uses Strings, IniFiles, Start, MiscUtil, Settings, Desk;
  69.  
  70. { For each group in the list, RequestData is called to retrieve the
  71.   entire group contents as a long null terminated string.  Rather than
  72.   parsing this, it is quicker to assign it to a string list, which
  73.   separates it into lines, and even sorts them for you.  The first line
  74.   is always the group name, so it is discarded. }
  75.  
  76. procedure TConvertDlg.OKBtnClick(Sender: TObject);
  77. var
  78.   progs: TStringList;
  79.   p: PChar;
  80.   i, j, iconindex, mode: Integer;
  81.   cap, com, dir, iconfile: TFilename;
  82. begin
  83.   progs := TStringList.Create;
  84.   try
  85.     Desktop.SetCursor(crHourGlass);
  86.     for i := 0 to GroupList.Items.Count-1 do
  87.     if GroupList.Selected[i] then begin
  88.       progs.Clear;
  89.       try
  90.         p := Progman.RequestData(GroupList.Items[i]);
  91.         with progs do begin
  92.           Sorted := False;
  93.           SetText(p);
  94.           Delete(0); { Delete name of group }
  95.           Sorted := SortItems.Checked;
  96.         end;
  97.       finally
  98.         StrDispose(p);
  99.       end;
  100.  
  101.       for j := 0 to progs.Count-1 do begin
  102.         cap := '';
  103.         com := '';
  104.         dir := '';
  105.         iconfile := '';
  106.         iconindex := 0;
  107.         mode := 0;
  108.  
  109.         { Inspecting the data returned by Program Manager shows that
  110.           the fields are separated by commas and the first two are
  111.           enclosed in double quotes.  Some of the icon positions
  112.           are ignored }
  113.  
  114.         Unformat(progs[j], '"%s","%s",%s,%s,%D,%D,%d,%D,%d',
  115.           [@cap, 79, @com, 79, @dir, 79, @iconfile, 79, @iconindex, @mode]);
  116.         if Assigned(OnConvertProg) then
  117.           OnConvertProg(self, Trim(GroupList.Items[i]), Trim(cap),
  118.             PackStartInfo(com, dir, iconfile, mode, iconindex));
  119.       end;
  120.     end;
  121.   finally
  122.     progs.Free;
  123.     Desktop.ReleaseCursor;
  124.   end;
  125. end;
  126.  
  127.  
  128. procedure TConvertDlg.FormCreate(Sender: TObject);
  129. var
  130.   p: PChar;
  131. begin
  132.   if Progman.OpenLink then
  133.     try
  134.       p := Progman.RequestData('Groups');
  135.       GroupList.Items.SetText(p);
  136.     finally
  137.       StrDispose(p);
  138.     end
  139.   else
  140.     MsgDialog('Cannot find Program Manager.', mtError, [mbOK], 0);
  141. end;
  142.  
  143.  
  144. end.
  145.