Send key presses to background application window

Announcements and discussion for PInvoke

Moderators: Luke Jefferson, Robert

Send key presses to background application window

Postby Hooch » Sun May 29, 2011 10:42 am

Hello.
Can you help me to transfer that code to C#?

Code: Select all
    HWND Notepad = FindWindowEx( GetDesktopWindow( ), 0, "Notepad", 0 );
   
    SendMessage( GetDlgItem( Notepad, MB_TYPEMASK ), WM_SETTEXT, 0, (LPARAM)"Hello Notepad, what's up?" );


Thank you in advance

I want to send key presses to background window.
I don't want to use SendKeys.Send because I want that window to be in background.
SendKeys requires that window is active.
Hooch
 
Posts: 1
Joined: Sun May 29, 2011 10:40 am

Postby Brian Donahue » Tue May 31, 2011 9:46 am

You can find the signatures for both functions on http://www.pinvoke.net. Once you insert the signature suggested by PInvoke, you can use both native functions from C#, for example:
Code: Select all
    [DllImport("User32.DLL")]
    public static extern int SendMessage(IntPtr hWnd, UInt32 Msg, Int32 wParam, Int32 lParam);
You'll also want to read the notes carefully on the PInvoke page for that function.
Brian Donahue
 
Posts: 6670
Joined: Mon Aug 23, 2004 10:48 am

Postby twain » Fri Nov 25, 2011 6:05 am

Well, I too had been recently working on this one. First of all, you need to search for the signatures for the two functions. The link for that has been given here by Brian. After you insert the signature, you can effectively use both of the native functions in C#. Has anyone used Port 25? Are they good in email delivery solutions?
twain
 
Posts: 2
Joined: Mon Nov 14, 2011 5:21 am


Return to PInvoke.Net

Who is online

Users browsing this forum: No registered users and 1 guest