send a message to IE

M

mo A

Hi all,
i am writing an App that reads from a barcode scanner. (no output
statments,i.e no active window)
i want to find a way to send the barcode to an open window (such as
Internet Explorer) so that when the user scans the barcode, the result
is displayed in any text box the user clicked. (the user has to click
on that text box --set focus-- before he triggers the barcode scanner)
i was looking into PostMessage(HWND_BROADCAST,WM_KEYDOWN,barocde,0).
but wasn't working.
i also tried PostMessage(GetForegroundWindow(),WM_KEYDOWN,barocde,0).
but wasn't working either.
my APP is a console app, no output statements (so a windows is not
created)

Any idea?
the window name is non constant so i cannot use
FindWindow( LPCTSTR lpClassName, LPCTSTR lpWindowName );
i looked into using EnumWindows() to get a handle to all active windows,
but how can i implement that ? (especially the call back function)?

Your help is greatly appreciated

Thanks
Mo
(e-mail address removed)
 
D

Derek Harmon

mo A said:
i looked into using EnumWindows() to get a handle to all active windows,
but how can i implement that ? (especially the call back function)?

EnumWindows can be accessed through P/Invoke using a signature
like this,

[DllImport( "USER32.DLL")]
public static extern int EnumChildWindows(
IntPtr hwndParent,
[MarshalAs( UnmanagedType.FunctionPtr)]
EnumFunc lpfnEnumFunc,
int lParam
);

The "callback" function is just a .NET delegate marshaled as a function
pointer in the above signature. Define it like this,

public delegate int EnumFunc( IntPtr hwnd, int lParam);

Elsewhere within your application, you define a method that gets called
back (in this trivial example, I'll just emit the HWND of the windows, al-
though in more sophisticated implementations you may have other Win32
P/Invoke methods like GetWindowText and can pass the HWND to them
to display more relevant information as required),

private int EnumChildren( IntPtr hwnd, int lParam)
{
Console.WriteLine( "HWND {0:X8}", (int)hwnd);
}

With these three pieces of code in place, the final line of code, the
actual calling to EnumWindows( ), becomes elementary,

MyClassName.EnumChildWindows(
IntPtr.Zero,
new EnumFunc( this.EnumChildren),
0
);


Derek Harmon
 
M

mo A

hi derek,
thanks for your reply, but my app is in c++ (not .net) so i need to know
how to use callback functions?

another question, how do i get a handle for an internet explorer window
so i can use postmessage/sendmessage to send data (in my case, scanned
barcode from my headless c++ app)to that window (a textbox in that
window)?

i tried FindWindow(LPCTSTR("IEfraame"),NULL): where IEframe is the name
of the Internet explorer class.t didnt work?

Thanks
Mo
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top