🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: CALLBACK Hell

#1760
From: JD
Date: Thu, 14 Jun 2007 19:26
49 lines
2400 bytes
"Mike Collins" <its@TheBottomOfThePost> wrote:
>
> [...] I did this because it's the only way that i found that
> works in the past, with other callbacks i.e. EnumWindows 
> etc...

This has worked for me:

    protected:
        static  bool __stdcall EnumWindowsCallBack( HWND hWnd, LPARAM lParam );

//-------------------------------------------------------------
TSingleInstance *ThisSingleInstance = NULL;
//-------------------------------------------------------------
__fastcall TSingleInstance::TSingleInstance(TComponent* Owner) : TComponent(Owner)
{
    .....
    ThisSingleInstance = this;
    .....
}
//-------------------------------------------------------------
__fastcall TSingleInstance::~TSingleInstance()
{
    .....
    ThisSingleInstance = NULL;
}
//-------------------------------------------------------------
bool __stdcall TSingleInstance::EnumWindowsCallBack( HWND hWnd, LPARAM lParam )
{
    char WindowClassName[256] = { 0 };
    if( ::GetClassName(hWnd, WindowClassName, 255) )
      {
          if( stricmp(WindowClassName, reinterpret_cast<char*>(lParam)) == 0 )
            {
                if( hWnd != ThisSingleInstance->FParentForm->Handle )
                  {
                      ThisSingleInstance->hFirstInstance = hWnd;
                      return FALSE;
                  }
            }
      }
    return TRUE;
}
//-------------------------------------------------------------

Note the use of ThisSingleInstance in the CallBack.

~ JD
Technical Details
Message-ID: <46719667@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsgate.cistron.nl!xs4all!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <46716c33@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,f434271506d1483b
X-Google-Attributes: gid10cc67,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "JD" <nospam@nospam.com>
Sender: "JD" <nospam@nospam.com>
Reply-To: "JD" <nospam@nospam.com>
Subject: Re: CALLBACK Hell
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 64.12.116.144     
X-Forwarded-For: 172.146.203.28
References:  <46716c33@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <46719667@newsgroups.borland.com>
Date: 14 Jun 2007 12:26:31 -0700
X-Trace: newsgroups.borland.com 1181849191 207.105.83.66 (14 Jun 2007 12:26:31 -0700)
Lines: 50
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.glorb.com!newsgate.cistron.nl!xs4all!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail