?
Solved

Windows taskbar - getting captions

Posted on 2005-03-18
11
Medium Priority
?
928 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

771 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