Board index » delphi » winapi - FindWindow

winapi - FindWindow

patri...@mincom.com (Patrick Bilsborough)  wrote

Quote
> Has anyone used the FindWindow function with the second parm null? In the
>     hWindow := FindWindow( 'CtlPanelClass', #0 );

Pass Nil, not 0!

Michael
--

Michael Suedkamp                                      m...@suedkm.franken.de

 

Re:winapi - FindWindow


In article <patrickb.14.000F4...@mincom.com>, patri...@mincom.com
says...
Quote

>Has anyone used the FindWindow function with the second parm null? In
the
>sample code, the first function call returns a nonzero value, but the
second
>returns zero, ie it fails. According to winapi.hlp, the second should
work,
>why doesn't it?

>unit Unit1;

>interface

>uses
>  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
>  Forms, Dialogs;

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

>var
>  Form1: TForm1;

>implementation

>{$R *.DFM}

>procedure TForm1.FormCreate(Sender: TObject);
>var
>    pcTemp: PChar;
>    hWindow: hWnd;
>begin
>    pcTemp := StrAlloc( 33 );
>    hWindow := FindWindow( 'CtlPanelClass', 'Control Panel' );
>    StrPCopy( pcTemp, IntToStr( hWindow ) );
>    MessageBox( Handle, pcTemp, 'Window handle',  mb_ok );
>    StrDispose( pcTemp );

>    { Now try passing 0 as the second parm as per winapi.hlp }
>    pcTemp := StrAlloc( 33 );
>    hWindow := FindWindow( 'CtlPanelClass', #0 );
>    StrPCopy( pcTemp, IntToStr( hWindow ) );
>    MessageBox( Handle, pcTemp, 'Window handle again',  mb_ok );
>    StrDispose( pcTemp );
>end;

>end.

A shot in the dark here, but try passing a Nil instead and see if that
works.  I know the documentation was incorrect if only title was
passed.  Docs say zero, Nil should be the actual value passed.

--
Regards,                        Computer consulting:
Eric Drews                      - Custom applications
Drews Enterprises               - Data conversion & manipulation
908 665 2513                    - Hardware assistance
drews...@superlink.net          - Using Pick-based systems & Delphi
No application is _too_ small

Re:winapi - FindWindow


I haven't an answer, but another question along the smae lines as

Quote
Patrick Bilsborough who wrote:

> Has anyone used the FindWindow function with the second parm null? In the
> sample code, the first function call returns a nonzero value, but the second
> returns zero, ie it fails. According to winapi.hlp, the second should work,
> why doesn't it?
> (code deleted, see original posting)

I have been using EnumWindows successfully in Delphi 1.0. In 2.0, the same code fails
miserably. The user-parameter passed to the EnumWindowsProc callback is bogus and the
first parameter, the window handle, is the same for each callback. I wonder if this
problem and Patrick's are related.

Gerald Dueck
Brandon University
du...@brandonu.ca

Re:winapi - FindWindow


Quote
Patrick Bilsborough wrote:

> Has anyone used the FindWindow function with the second parm null? In the
> sample code, the first function call returns a nonzero value, but the second
> returns zero, ie it fails. According to winapi.hlp, the second should work,
> why doesn't it?

> unit Unit1;

> interface

> uses
>   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
>   Forms, Dialogs;

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

> var
>   Form1: TForm1;

> implementation

> {$R *.DFM}

> procedure TForm1.FormCreate(Sender: TObject);
> var
>     pcTemp: PChar;
>     hWindow: hWnd;
> begin
>     pcTemp := StrAlloc( 33 );
>     hWindow := FindWindow( 'CtlPanelClass', 'Control Panel' );
>     StrPCopy( pcTemp, IntToStr( hWindow ) );
>     MessageBox( Handle, pcTemp, 'Window handle',  mb_ok );
>     StrDispose( pcTemp );

>     { Now try passing 0 as the second parm as per winapi.hlp }
>     pcTemp := StrAlloc( 33 );
>     hWindow := FindWindow( 'CtlPanelClass', #0 );
>     StrPCopy( pcTemp, IntToStr( hWindow ) );
>     MessageBox( Handle, pcTemp, 'Window handle again',  mb_ok );
>     StrDispose( pcTemp );
> end;

> end.

Just replace:

hWindow := FindWindow( 'CtlPanelClass', #0 );

with:

hWindow := FindWindow( 'CtlPanelClass', nil );

Re:winapi - FindWindow


Quote
Gerald Dueck wrote:

> I haven't an answer, but another question along the smae lines as
> Patrick Bilsborough who wrote:

> > Has anyone used the FindWindow function with the second parm null? In the
> > sample code, the first function call returns a nonzero value, but the second
> > returns zero, ie it fails. According to winapi.hlp, the second should work,
> > why doesn't it?
> > (code deleted, see original posting)

> I have been using EnumWindows successfully in Delphi 1.0. In 2.0, the same code fails
> miserably. The user-parameter passed to the EnumWindowsProc callback is bogus and the
> first parameter, the window handle, is the same for each callback. I wonder if this
> problem and Patrick's are related.

Sounds to me like you're not using the stdcall convention in 32-bit like you should be.
--

        -Steve Teixeira
         steix...@borland.com

Other Threads