
Newbie: pls help with SendMessage
Hi Sean ,
You should send the messages to the TextBox window in the NotePad, not its
parent window. Also, if you use the WM_KEYDOWN message, call PostMessage
instead of the SendMessage, otherwise you cannot get the WM_CHAR message.
For example:
bool ret=WinAPI.BringWindowToTop((IntPtr)hWnd);
int hWndEditor=WinAPI.GetWindow((IntPtr)hWnd,WinAPI.GW_CHILD); //retrieve
the handle to the TextBox window, which is a child window of the NotePad
window
WinAPI.SendMessage ((IntPtr)hWnd, WinAPI.WM_SYSCOMMAND,
WinAPI.SC_MAXIMIZE,0);
//WinAPI.SendMessage ((IntPtr)hWndEditor, WinAPI.WM_CHAR, (int)(Keys.A), 0);
WinAPI.PostMessage ((IntPtr)hWndEditor, WinAPI.WM_KEYDOWN, (int)(Keys.A),
0);
Hope this helps.
Regards,
Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Quote:
>Subject: Newbie: pls help with SendMessage
>Date: Fri, 6 Sep 2002 02:19:33 +0800
>Lines: 48
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
>Newsgroups: microsoft.public.dotnet.languages.
CSharp >NNTP-Posting-Host: 203.125.30.37
>Path: cpmsftngxa10!tkmsftngp01!tkmsftngp08
>Xref: cpmsftngxa10 microsoft.public.dotnet.languages.csharp:91035
>X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
>I have the following codes which test SendMessage to Notepad program:
>------------------------------------------------------------------
>class Test
>{
> [STAThread]
> static void Main(string[] args)
> {
> WinAPI.SendMessage ((IntPtr)hWnd, WinAPI.WM_SYSCOMMAND,
>WinAPI.SC_MAXIMIZE,0);
> WinAPI.SendMessage ((IntPtr)hWnd, WinAPI.WM_CHAR, (int)(Keys.A), 0);
> WinAPI.SendMessage ((IntPtr)hWnd, WinAPI.WM_KEYDOWN, (int)(Keys.A), 0);
> }
>}
>class WinAPI
>{
> public const int WM_SYSCOMMAND = 0x0112;
> public const int SC_MAXIMIZE = 0xF030;
> public const int WM_KEYDOWN = 0x0100;
> public const int WM_CHAR = 0x0102;
> [DllImport ("user32.dll")]
> public static extern int SendMessage(IntPtr hWnd, int Msg, int
>wParam, int lParam);
> [DllImport("User32.dll")]
> public static extern int FindWindow(string lpClassName, string
>lpWindowName);
>}
>------------------------------------------------------------------
>The first SendMessage to maximize the Notepad window is working fine.
>However I could not get the second or third line of SendMessage() to work.
>What is wrong?
>Any idea how do I send to Notepad the "Alt+F" key (press Alt and hold and
>press F key)?
>Appreciate some hints, guidance or help. Thanks a lot.