First look at a piece of code:
Using System; <br/> using System. collections. generic; <br/> using System. componentModel; <br/> using System. drawing; <br/> using System. text; <br/> using System. windows. forms; <br/> using System. runtime. interopServices; <br/> using System. diagnostics; <br/> namespace TTPlayerControl <br/>{< br/> public partial class Form1: Form <br/>{< br/> [DllImport ("USER32.DLL")] <br/> public static extern IntPtr FindWindow (string className, string WindowName); <br/> [DllImport ("User32.dll", EntryPoint = "SendMessage")] <br/> private static extern int SendMessage (<br/> IntPtr hWnd, // handle to destination window <br/> int Msg, // message <br/> IntPtr wParam, // first message <br/> IntPtr lParam // second message <br/>); <br/> [DllImport ("USER32.DLL")] <br/> public static extern IntPtr GetForegroundWindow (); <br/> [DllImport ("user32.dll", EntryPoint = "find1_wex")] <br/> private static extern IntPtr find1_wex (IntPtr hwndParent, <br/> IntPtr hwndChildAfter, string lpszClass, string lpszWindow); <br/> [DllImport ("USER32.DLL")] <br/> public static extern IntPtr GetDlgItem (<br/> IntPtr hDlg, // handle of dialog box <br/> int nIDDlgItem // identifier of control <br/> ); <br/> [DllImport ("USER32.DLL", CharSet = CharSet. auto)] <br/> private static extern int ShowWindow (<br/> System. intPtr hWnd, <br/> int nCmdShow <br/>); <br/> public Form1 () <br/>{< br/> InitializeComponent (); <br/>}< br/> // obtain the window handle <br/> private void button3_Click (object sender, EventArgs e) <br/>{< br/> getHander (); <br/>}< br/> // obtain the handle <br/> IntPtr nextSongHander; <br/> IntPtr lastSongHander; <br/> IntPtr startOrPauseSongHander; <br/> IntPtr stopSongHander; <br/> IntPtr exitHander; <br/> IntPtr parentHander; <br/> private void getHander () <br/>{< br/> nextSongHander = GetDlgItem (parentHander, 32006); <br/> lastSongHander = GetDlgItem (parentHander, 32005 ); <br/> response = GetDlgItem (parentHander, 32000); <br/> stopSongHander = GetDlgItem (parentHander, 32002); <br/> exitHander = GetDlgItem (parentHander, 57665 ); <br/>}< br/> // load start TTPLAYER to obtain the window handle <br/> Process p = new Process (); <br/> private void Form1_Load (object sender, eventArgs e) <br/>{< br/> parentHander = FindWindow ("TTPlayer_PlayerWnd", null); <br/> if (parentHander = IntPtr. zero) <br/>{< br/> p. startInfo. fileName = "ttplayer. EXE "; // D:/TTPlay <br/> p. start (); <br/>}< br/> else <br/>{< br/> getHander (); <br/>}< br/> while (parentHander = IntPtr. zero) <br/>{< br/> parentHander = FindWindow ("TTPlayer_PlayerWnd", null); <br/>}< br/> while (exitHander = IntPtr. zero | nextSongHander = IntPtr. zero | lastSongHander = IntPtr. zero | startOrPauseSongHander = IntPtr. zero | stopSongHander = IntPtr. zero) <br/>{< br/> getHander (); <br/>}< br/> private void btnExit_Click (object sender, EventArgs e) <br/>{< br/> messageSender (exitHander); <br/> this. close (); <br/>}< br/> // sendmessage <br/> private void messageSender (IntPtr hander) <br/>{< br/> SendMessage (hander, 0x201, IntPtr. zero, IntPtr. zero); <br/> SendMessage (hander, 0x202, IntPtr. zero, IntPtr. zero); <br/>}< br/> // The next <br/> private void button2_Click (object sender, EventArgs e) <br/>{< br/> messageSender (nextSongHander); <br/>}< br/> // previous <br/> private void btnLast_Click (object sender, EventArgs e) <br/>{< br/> messageSender (lastSongHander); <br/>}< br/> // stop <br/> private void btnStop_Click (object sender, EventArgs e) <br/>{< br/> messageSender (stopSongHander); <br/>}< br/> // suspend or start <br/> private void btnStartOrPause_Click (object sender, eventArgs e) <br/>{< br/> messageSender (startOrPauseSongHander ); <br/>}< br/> // display the main form <br/> private void btnShowMainWindow_Click (object sender, EventArgs e) <br/>{< br/> ShowWindow (parentHander, 1); <br/>}< br/> // minimized <br/> private void btnHiddenMainWindow_Click (object sender, EventArgs e) <br/>{< br/> ShowWindow (parentHander, 2); <br/>}< br/>
Question 1: parentHander = FindWindow ("TTPlayer_PlayerWnd
", Null );
Question 2: nextSongHander = GetDlgItem (parentHander, 32006
);
How do I get the red area?
In fact, we often compile programs, but forget some of the program running principles. In a windows operating system, it is nothing more than obtaining the ID or handle of a control. Therefore, nextSongHander = GetDlgItem (parentHander, 32006) is generated only when messages are sent to this control );
Convert the obtained ID to a handle.
// Sendmessage <br/> private void messageSender (IntPtr hander) <br/>{< br/> SendMessage (hander, 0x201, IntPtr. zero, IntPtr. zero); <br/> SendMessage (hander, 0x202, IntPtr. zero, IntPtr. zero); <br/>}
Send to a widget in the window. Control the action of the entire program.
SPY ++ is a tool used to obtain the ID of a control class and control. Specific use can refer to the http://blog.csdn.net/benny5609/archive/2007/10/19/1833477.aspx
Http://www.java2000.net/todoshow.jsp? Id = 63557
Http://www.vckbase.com/code/winsys/message/qqlogin.zip