Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Windows taskbar - getting captions

Posted on 2005-03-18
11
Medium Priority
?
947 Views
Last Modified: 2008-01-09
Hello!

I'm trying to get captions for buttons in Windows Taskbar but I'm doing something wrong - Windows Explorer crashes every time I try this:

var
  wnd : cardinal;
  txt : pchar;
  btn : ^_tbbutton;
  n : integer;
begin
wnd := FindWindow('Shell_TrayWnd', nil);
wnd := FindWindowEx(wnd, 0, 'ReBarWindow32', nil);
wnd := FindWindowEx(wnd, 0, 'MSTaskSwWClass', nil);
wnd := FindWindowEx(wnd, 0, 'ToolbarWindow32', nil);
GetMem(txt, 256);
GetMem(btn, sizeof(btn^));
n := 0;
while SendMessage(wnd, tb_getbutton, n, integer(btn)) <> 0 do begin
  SendMessage(wnd, tb_getbuttontext, btn^.idCommand, integer(txt));
  memo1.Lines.Append(txt);
  n := n + 1;
end;
FreeMem(btn);
FreeMem(txt);
end;


Could anyone provide me with working example for getting these captions (with using SendMessage() function)?
0
Comment
Question by:ZhaawZ
  • 5
  • 4
  • 2
11 Comments
 
LVL 5

Expert Comment

by:paulb1989
ID: 13581613
A better solution for doing this may be by enumerating windows, a C++ example of this is at http://www.codeguru.com/Cpp/controls/toolbar/miscellaneous/article.php/c5495/
0
 
LVL 11

Author Comment

by:ZhaawZ
ID: 13581625
paulb1989, I can't use enumerating windows in this case because I have to do some work with these buttons, not with windows.
0
 
LVL 5

Expert Comment

by:paulb1989
ID: 13581634
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, CommCtrl;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  pForm1 = ^TForm1;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function EnumFunc(hwnd: HWND; lparam: pForm1): Boolean; stdcall;
var
  TitleLen: Integer;
  TitleText: pChar;
begin
  Result := True;

  if hwnd = lparam^.Handle then
  begin
    // Don't Show This Window
  end else
  if GetParent(hwnd) <> 0 then
  begin
    // Owned, won't be in taskbar
  end else
  if (GetWindowLong(hwnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = WS_EX_TOOLWINDOW) then
  begin
    // Tool Window
  end else
  if not IsWindowVisible(hwnd) then
  begin
    // Window Not Visible
  end else
  begin
    TitleLen := GetWindowTextLength(hwnd);

    if TitleLen = 0 then
    begin
      // No Title
    end else
    begin
      Inc(TitleLen);
      GetMem(TitleText, TitleLen);

      if GetWindowText(hwnd, TitleText, TitleLen) = 0 then
      begin
        // Error
        ShowMessage('Error Retreiving Window Title');
      end else
      begin
        if TitleText <> 'Program Manager' then
        begin
          lparam^.Memo1.Lines.Add(TitleText);
        end;
      end;
    end;
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Memo1.Lines.Clear;

  if not EnumWindows(@EnumFunc, Integer(@Self)) then
  begin
    ShowMessage('Error Enumerating Windows');
  end;
end;

end.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:paulb1989
ID: 13581636
Sorry, missed your last comment...
0
 
LVL 5

Expert Comment

by:paulb1989
ID: 13581637
What do you need to do with the buttons? Maybe knowing that will help in finding a solution.
0
 
LVL 11

Author Comment

by:ZhaawZ
ID: 13581639
I want to make an app that would allow users to change order of these buttons. That's why I need captions of all these buttons.
I want to make it without changing windows` styles, hiding/showing them etc.
0
 
LVL 5

Expert Comment

by:paulb1989
ID: 13583017
Well I'd advise you to reconsider hiding and showing windows as it seems to be the easiest way to do this, but its your choice so I'll let you see if somebody else knows how to do it without enumerating, hiding and showing windows.
0
 
LVL 11

Author Comment

by:ZhaawZ
ID: 13583044
I know that hiding/showing windows would be the easiest way :) But... It's not the best. Why?
1) it can be done by moving those buttons (without "touching" windows). Moving buttons can be done by sending tb_movebutton message to toolbar.
2) programs receive some messages when windows are about to hide/show. I believe that some windows can block these messages.
3) I want to learn something new :)
0
 
LVL 20

Expert Comment

by:Madshi
ID: 13589755
The problem is that some of those messages transport pointers - and pointers are usually only valid in their own process. So if you transport a pointer over to the explorer's process, this won't work properly. The easiest solution is to put your code into a little dll and inject it into the explorer's process.
0
 
LVL 11

Author Comment

by:ZhaawZ
ID: 13593137
Hmm.. Why is it so problematically to work with pointers between processes?
0
 
LVL 20

Accepted Solution

by:
Madshi earned 375 total points
ID: 13593774
Because in 32bit programming each process has its own address space, which don't have anything to do with each other.
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question