🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8083

Re: Several ways to define 2 system-wide hotkeys, without to install keyboard-hook..

#8083
From: Oren Halvani
Date: Sun, 21 Nov 2004 09:57
95 lines
4311 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> schrieb im
Newsbeitrag news:41a03fb6@newsgroups.borland.com...

> Probably because your window enumeration is finding multiple top-level
> windows per application, so you find the same parent window multiple times.
>
>
> Gambit

Remy, i've found the following delphi code on the net..

i've tried to convert it to c++ code (see bottom) but the compiler
didn't recognized FreeMem( )...what does FreeMem do..?

how can i rewrite it to c++ ?

/*******************************************************/
//  List all Windows with a Button on the taskbar...

function GetText(Wnd: HWND): string;
var
  textlength: Integer;
  Text: PChar;
begin
  textlength := SendMessage(Wnd, WM_GETTEXTLENGTH, 0, 0);
  if textlength = 0 then Result := ''
  else
  begin
    GetMem(Text, textlength + 1);
    SendMessage(Wnd, WM_GETTEXT, textlength + 1, Integer(Text));
    Result := Text;
    FreeMem(Text);
  end;
end;

function EnumWindowsProc(Wnd: HWND; lParam: lParam): BOOL; stdcall;
begin
  Result := True;
  if (IsWindowVisible(Wnd) or IsIconic(wnd)) and
    ((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) or
    (GetWindowLong(Wnd, GWL_HWNDPARENT) = GetDesktopWindow)) and
    (GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then
    Form1.Listbox1.Items.Add('Handle: ' + IntToStr(Wnd) + ',Text:  ' +
GetText(Wnd));
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Param: Longint;
begin
  EnumWindows(@EnumWindowsProc, Param);
end;
/*******************************************************/


-----> converted to c++:


/*******************************************************/
String __fastcall GetText(HWND hwnd)
{
  int textlength;  char *Text;

  textlength = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0);
  if(textlength == 0) return; // i guess this might be wrong....
  else
  {
    sizeof(Text, textlength + 1);
    SendMessage(hwnd, WM_GETTEXT, textlength + 1, Integer(Text));
    return Text;
    FreeMem(Text); // ???
  }
}

BOOL CALLBACK EnumWindowsCallback(HWND hwnd, LPARAM lParam)
{
  if (IsWindowVisible(hwnd) || IsIconic(hwnd)) &&
    ((GetWindowLong(hwnd, GWL_HWNDPARENT) = 0) ||
    (GetWindowLong(hwnd, GWL_HWNDPARENT) = GetDesktopWindow)) &&
    (GetWindowLong(hwnd, GWL_EXSTYLE) && WS_EX_TOOLWINDOW = 0)
    frmMainUnit->ListBox1->Items->Add("Handle: " + IntToStr(hwnd) + ", Text: " +
GetText(hwnd));

    return true;
}

void __fastcall TfrmMainUnit::Button1Click(TObject *Sender)
{
    int Param;
    EnumWindows((WNDENUMPROC)EnumWindowsCallback, Param);
}
/*******************************************************/


Oren
Technical Details
Message-ID: <41a066cc@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <419ceea1@newsgroups.borland.com> <419cf173$1@newsgroups.borland.com> <419d2c69$1@newsgroups.borland.com> <419d3e01$1@newsgroups.borland.com> <419d8ce4@newsgroups.borland.com> <419dc340@newsgroups.borland.com> <419e5561$1@newsgroups.borland.com> <419e5ecc$1@newsgroups.borland.com> <419e6631@newsgroups.borland.com> <419e7adc$1@newsgroups.borland.com> <419e831e$1@newsgroups.borland.com> <419f0334$1@newsgroups.borland.com> <419f08b1@newsgroups.borland.com> <419fb061$1@newsgroups.borland.com> <419fc5aa@newsgroups.borland.com> <41a03fb6@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,9a94ec9a8ef193c6
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Oren Halvani" <Spam@Me-Please.com>
From: "Oren Halvani" <Spam@Me-Please.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <419ceea1@newsgroups.borland.com> <419cf173$1@newsgroups.borland.com> <419d2c69$1@newsgroups.borland.com> <419d3e01$1@newsgroups.borland.com> <419d8ce4@newsgroups.borland.com> <419dc340@newsgroups.borland.com> <419e5561$1@newsgroups.borland.com> <419e5ecc$1@newsgroups.borland.com> <419e6631@newsgroups.borland.com> <419e7adc$1@newsgroups.borland.com> <419e831e$1@newsgroups.borland.com> <419f0334$1@newsgroups.borland.com> <419f08b1@newsgroups.borland.com> <419fb061$1@newsgroups.borland.com> <419fc5aa@newsgroups.borland.com> <41a03fb6@newsgroups.borland.com>
Subject: Re: Several ways to define 2 system-wide hotkeys, without to install keyboard-hook..
Date: Sun, 21 Nov 2004 10:57:46 +0100
Lines: 97
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 217.234.120.75
Message-ID: <41a066cc@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1101031116 217.234.120.75 (21 Nov 2004 01:58:36 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail