Board index » delphi » What am I doing wrong (Win API stuff, 3rd part)

What am I doing wrong (Win API stuff, 3rd part)

Now I have another problem.

The message is not getting there.  If this were to work, NOTEPAD should
have the letter 't' typed, but it doesn't.  I used WinSight to make sure
that I have the correct handle, and I do.

Please note that NOTEPAD.EXE is already running.

So what's the deal now?

---------------------- Start code --------------------------

procedure TForm1.btnDailyBackupClick(Sender: TObject);

var
MyHandle: HWND;
ProgramPath: PChar;
Msg: Char;
S: string;
begin
Msg := 't';
MyHandle := FindWindow('Notepad',nil);
SendMessage(MyHandle,WM_CHAR,null,Word(Msg));
end;

---------------------- End code --------------------------

--
Joseph I. Ceasar (Yossi)
CLS Computer Solutions

 

Re:What am I doing wrong (Win API stuff, 3rd part)


Hey!

Remember that your MyHandle var is the handle of the Notepad Frame
window, which may not necessarily be the window handling the wm_Char
messages for the actual control which contains the text.

bly

Quote
j...@nyc.pipeline.com(Joseph I. Ceasar) wrote:

>Now I have another problem.

>The message is not getting there.  If this were to work, NOTEPAD should
>have the letter 't' typed, but it doesn't.  I used WinSight to make sure
>that I have the correct handle, and I do.

>Please note that NOTEPAD.EXE is already running.

>So what's the deal now?

>---------------------- Start code --------------------------

>procedure TForm1.btnDailyBackupClick(Sender: TObject);

>var
>MyHandle: HWND;
>ProgramPath: PChar;
>Msg: Char;
>S: string;
>begin
>Msg := 't';
>MyHandle := FindWindow('Notepad',nil);
>SendMessage(MyHandle,WM_CHAR,null,Word(Msg));
>end;

>---------------------- End code --------------------------

>--
>Joseph I. Ceasar (Yossi)
>CLS Computer Solutions

Re:What am I doing wrong (Win API stuff, 3rd part)


On Sep 08, 1996 03:14:43 in article <Re: What am I doing wrong (Win API
stuff, 3rd part)>, '...@castle.net' wrote:

Quote
>Hey!

>Remember that your MyHandle var is the handle of the Notepad Frame
>window, which may not necessarily be the window handling the wm_Char
>messages for the actual control which contains the text.

>bly

So how do I figure this one out?

Quote
>j...@nyc.pipeline.com(Joseph I. Ceasar) wrote:

>>Now I have another problem.  

>>The message is not getting there.  If this were to work, NOTEPAD should
>>have the letter 't' typed, but it doesn't.  I used WinSight to make sure
>>that I have the correct handle, and I do.  

>>Please note that NOTEPAD.EXE is already running.  

>>So what's the deal now?  

>>---------------------- Start code --------------------------  

>>procedure TForm1.btnDailyBackupClick(Sender: TObject);  

>>var  
>>MyHandle: HWND;  
>>ProgramPath: PChar;  
>>Msg: Char;  
>>S: string;  
>>begin  
>>Msg := 't';  
>>MyHandle := FindWindow('Notepad',nil);  
>>SendMessage(MyHandle,WM_CHAR,null,Word(Msg));  
>>end;  

>>---------------------- End code --------------------------  

>>--  
>>Joseph I. Ceasar (Yossi)  
>>CLS Computer Solutions

--
Joseph I. Ceasar (Yossi)
CLS Computer Solutions

Re:What am I doing wrong (Win API stuff, 3rd part)


Quote
Joseph I. Ceasar wrote:

> On Sep 08, 1996 03:14:43 in article <Re: What am I doing wrong (Win API
> stuff, 3rd part)>, '...@castle.net' wrote:

> >Hey!

> >Remember that your MyHandle var is the handle of the Notepad Frame
> >window, which may not necessarily be the window handling the wm_Char
> >messages for the actual control which contains the text.

> >bly

> So how do I figure this one out?

        You figure out the right hWnd using WinSight again. (Turns out that
the first child of the main Notepad window is the edit control you're after.)

        That's not the only problem with your example. The following works:

procedure TForm1.Button1Click(Sender: TObject);
var
MyHandle: HWND;
begin
MyHandle := GetWindow(FindWindow('Notepad',nil),GW_CHILD);
SendMessage(MyHandle,WM_CHAR,$41,0);
end;

        (That $41 is VK_A. The symbolic constant must be declared somewhere,
I don't see exactly where right now.)

        See the help on WM_CHAR for more details...

--
David Ullrich

?his ?s ?avid ?llrich's ?ig ?ile
(Someone undeleted it for me...)

Re:What am I doing wrong (Win API stuff, 3rd part)


Quote
j...@nyc.pipeline.com(Joseph I. Ceasar) wrote:

>Now I have another problem.

>The message is not getting there.  If this were to work, NOTEPAD should
>have the letter 't' typed, but it doesn't.  I used WinSight to make sure
>that I have the correct handle, and I do.

>Please note that NOTEPAD.EXE is already running.

>So what's the deal now?

>---------------------- Start code --------------------------

>procedure TForm1.btnDailyBackupClick(Sender: TObject);

>var
>MyHandle: HWND;
>ProgramPath: PChar;
>Msg: Char;
>S: string;
>begin
>Msg := 't';
>MyHandle := FindWindow('Notepad',nil);
>SendMessage(MyHandle,WM_CHAR,null,Word(Msg));
>end;

>---------------------- End code --------------------------

>--
>Joseph I. Ceasar (Yossi)
>CLS Computer Solutions

Wouldn't it just be easier to open the file that you are trying to
edit remotely and append text to it?

David Block
CoStar Corporation

Other Threads