How to Control Other Application Windows in Delphi How to Control Other Application Windows Guangdong Agriculture Management Cadres School Chen Jianbing often involves the operation of other Windows applications. For example, in the management system of the database, the financial personnel need to use the calculator, which can call the calculator functionality contained in Windows. If each used, all use through the "Start / Program / Accessories / Calculator" to open the calculator, obviously It is very cumbersome, of course, can be considered to establish a "calculator" shortcut on the desktop, and define a hotkey. When using the calculator, press this hotkey to open the "calculator". However, since "calculator" is a "non-mode" window program, that is, every time the calculator is running, it will open a "calculator" window. This result is dozens of "calculators" on the desktop, not only large quantity. Increase the overhead of system memory, and it is not convenient for users' operation. It can be easily controlled in Delphi, and the effect is very perfect. The following is made in two main issues. 1. How to control design? Create a new form, put two buttons in the form, which CAPTION is "Open" (ie, "calculator") and "off", and add Click event processing to them. See the form FORM1 and unit file unit1 for details. Among them, the most important statements are: fWnd: = findwindow ('scicalc', 'calculator'); function original is (see Delphi help): HWND FINDWINDOW (LPCTSTR LPCLASSNAME, / / POINTER TO CLASS NAME LPCTSTSTR LPWINDOWNAME // Pointer to window name); here, 'scicalc' is the class name of the calculator, 'calculator' is the window title of the calculator} setWindowPos (FWnd, hwnd_notopmost, 0,0,0,0, swp_showwindow or swp_nosize or SWP_Nomove); Function original is: BOOL SETWINDOWPOS (HWND HWND, // Handle of Window Hwnd HWndinsertafter, // Placement-Order Handle Int x, // horizontal position int y, // value int CX, // width int CY, // Height uint uflags // window-positioning flags; showwindow (fwnd, sw_restore); // Displays the Open "Calculator" function original to: BOOL ShowWindow (hwnd hwnd, // handle of window int ncmdshow // show // show State of window); RET: = Winexec ('c: /windows/calc.exe' ,sw_shownormal); // Start Calculator Function Prototype: UINT WINEXEC (LPCSTR LPCMDLINE, / / Address of Command Line uint ucmdshow // WINDOW STYLE for new application); Run the Calculator program and detects the return value (to use the return value to determine the possible error) 2. How to clarify the "class name" of the application? To control the application, you must first clarify the "class name" of the application.