Windows is a message-driven operating system, so you can use messages to operate any controls in windows. In Windows, a large number of APIs are open to users. Users can use these APIs to operate controls in Windows from the underlying layer and use messages, the following uses C # To operate IE browser through Win32 API --- to obtain ie url as an example: As for the prototype of API message function, you can find it in msdn, the following example shows how to use the C # element to represent the prototype of the API message function in C.
Using system;
Using system. Collections. Generic;
Using system. text;
Using system. runtime. interopservices; // namespace required to operate WIN32API
Namespace iemanipulation
{
Public class iemanipulation
{
[Dllimport ("user32.dll")] // user32.dll is one of the core dynamic libraries of the Windows operating system.
Static extern int findwindow (string lpclassname, string lpwindowname );
[Dllimport ("user32.dll")]
Static extern int find1_wex (INT hwndparent, int hwndchildafter, string lpszclass, string lpszwindow );
[Dllimport ("user32.dll")]
Static extern int getwindowtext (INT hwnd, stringbuilder Buf, int nmaxcount );
[Dllimport ("user32.dll")]
Static extern int sendmessage (INT hwnd, int MSG, int wparam, stringbuilder lparam );
Const int wm_gettext = 0x000d; // gets the hexadecimal representation of text messages.
/// <Summary>
/// Get the URL of the current opened IE
/// </Summary>
Public static string geturl ()
{
Int parent = findwindow ("ieframe", null );
Int child = find1_wex (parent, 0, "workerw", null );
Child = finddomainwex (child, 0, "rebarwindow32", null );
Child = find1_wex (child, 0, "comboboxex32", null );
Child = finddomainwex (child, 0, "ComboBox", null );
Child = finddomainwex (child, 0, "edit", null); // get the hierarchy of the address bar through spy ++, and then obtain
Stringbuilder buffer = new stringbuilder (1024 );
// Child indicates the handle Number of the form to be operated
// Wm_gettext indicates a message. How to drive the form?
// 1024 indicates the size of the text to be obtained
// Buffer indicates that the obtained text value is stored in the memory cache.
Int num = sendmessage (child, wm_gettext, 1024, buffer );
String url = buffer. tostring ();
Return URL;
}
}
}