Advertisement
Guest User

tutorial #4

a guest
Jul 19th, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.89 KB | None | 0 0
  1. type
  2.   TPalWinInfo = Record
  3.     sTitle: String;
  4.     hMainWin: Hwnd;
  5.     hOutgoing: Hwnd;
  6.     hIncoming: Hwnd;
  7.     hNickList: Hwnd;
  8.     bIsRoom: Boolean;
  9.   End;
  10.  
  11. type
  12.   TForm1 = class(TForm)
  13.     lvWinInfo: TListView;
  14.     btnRefresh: TButton;
  15.     procedure FormDestroy(Sender: TObject);
  16.     procedure btnRefreshClick(Sender: TObject);
  17.   private
  18.     { Private declarations }
  19.     Procedure AddToListView(pWinInfo: TPalWinInfo);
  20.     Procedure CleanUp;
  21.   public
  22.     { Public declarations }
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.   aPalWinInfo: Array of TPalWinInfo;
  28.  
  29. implementation
  30.  
  31. {$R *.dfm}
  32.  
  33. procedure TForm1.AddToListView(pWinInfo: TPalWinInfo);
  34. var
  35.  sIsRoom: String;
  36. begin
  37.  
  38.   if pWinInfo.bIsRoom then
  39.       sIsRoom:= 'Room'
  40.     else
  41.      sIsRoom:= 'Pm';
  42.  
  43.  
  44.   with lvWinInfo.Items.Add do
  45.   begin
  46.     Caption := pWinInfo.sTitle;
  47.     subItems.Add(IntToStr(pWinInfo.hMainWin));
  48.     subItems.Add(IntToStr(pWinInfo.hIncoming));
  49.     subItems.Add(IntToStr(pWinInfo.hOutgoing));
  50.     subItems.Add(IntToStr(pWinInfo.hNickList));
  51.     subItems.Add(sIsRoom);
  52.   end;
  53. end;
  54.  
  55. function GetTitle(aHwnd: Hwnd): String;
  56. begin
  57.   SetLength(Result, 255);
  58.   SetLength(Result, GetWindowText(aHwnd, Pchar(Result), 255));
  59. end;
  60.  
  61. function GetClass(aHwnd: Hwnd): String;
  62. begin
  63.   SetLength(Result, 255);
  64.   SetLength(Result, GetClassName(aHwnd, Pchar(Result), 255));
  65. end;
  66.  
  67. Function EnumChildProc(aHwnd: Hwnd; Param: LParam): BOOL; stdcall;
  68. begin
  69.   Result:= True;
  70.   if IsWindowVisible(aHwnd) then
  71.     case GetDlgCtrlId(aHwnd) of
  72.       202:
  73.         begin
  74.           aPalWinInfo[Pred(Length(aPalWinInfo))].hIncoming := aHwnd;
  75.           Result:= False;
  76.         end;
  77.       203:
  78.         begin
  79.           aPalWinInfo[Pred(Length(aPalWinInfo))].hOutgoing := aHwnd;
  80.         end;
  81.       1789:
  82.         begin
  83.           aPalWinInfo[Pred(Length(aPalWinInfo))].hNickList := aHwnd;
  84.           aPalWinInfo[Pred(Length(aPalWinInfo))].bIsRoom:= True;
  85.         end;
  86.     end;
  87. end;
  88.  
  89. function EnumWindowsProc(aHwnd: Hwnd; Param: LParam): BOOL; stdcall;
  90. begin
  91.   Result:= true;
  92.   if GetClass(aHwnd) = 'DlgGroupChat Window Class' then
  93.   begin
  94.     if aPalWinInfo <> nil then
  95.       SetLength(aPalWinInfo, Length(aPalWinInfo) + 1)
  96.     else
  97.       SetLength(aPalWinInfo, 1);
  98.  
  99.     aPalWinInfo[Pred(Length(aPalWinInfo))].sTitle := GetTitle(aHwnd);
  100.     aPalWinInfo[Pred(Length(aPalWinInfo))].hMainWin := aHwnd;
  101.  
  102.     EnumChildWindows(aHwnd, @EnumChildProc, 0);
  103.  
  104.   end;
  105. end;
  106.  
  107. procedure TForm1.btnRefreshClick(Sender: TObject);
  108. var
  109.   I: Integer;
  110. begin
  111.   CleanUp;
  112.   EnumWindows(@EnumWindowsProc, 0);
  113.  
  114.   for I := Low(aPalWinInfo) to High(aPalWinInfo) do
  115.    AddToListView(aPalWinInfo[i]);
  116.  
  117. end;
  118.  
  119. procedure TForm1.CleanUp;
  120. begin
  121.   if aPalWinInfo <> nil then
  122.    aPalWinInfo:= Nil;
  123.  
  124.   lvWinInfo.Clear;
  125. end;
  126.  
  127. procedure TForm1.FormDestroy(Sender: TObject);
  128. begin
  129.   if aPalWinInfo <> Nil then
  130.     aPalWinInfo := Nil;
  131. end;
  132.  
  133. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement