Address: http://blog.163.com/cgq_ I /blog/static/728779232009530112128471/
1. simple installation steps of window DDK mirror:
To download the DDK installation package path, see my previous article. After downloading and installing the Windows 2000 DDK package, you can start to compile the mirror demo program. Remember to select sample during installation so that the source code of SRC is available.
After the DDK driver is installed, it will be installed in the following path: C: \ Program Files \ ntddk, in C: \ Program Files \ ntddk \ SRC \ video \ displays \ mirror \ dll Directory to compile mirror. DLL. Compile mirror in the directory c: \ Program Files \ ntddk \ SRC \ video \ miniport \ mirror. SYS. during compilation, remember to use the build Command provided by ntddk (open through the start-> program menu ). After compiling these two tools, copy them by referring to c: \ Program Files \ ntddk \ SRC \ video \ displays \ mirror \ app \ readme.txt. OK. Compilation is complete. Then install the driver manually (on the control panel, select the compiled mirror. dll/mirror. sys ). Non-Window
2000 DDK compilation and installation steps may be different.
After the DDK of XP is installed, there is a directory mirror under the D: \ winddk00 \ SRC \ video \ displays directory, copy it to E: \ mirror \. Copy files such as mirror, mirror. dll, mirror. inf, mirror. Reg, and mirror. sys to the E: \ mirror \ bin directory.
Note that you cannot install the driver by double-clicking the INF file. You must run "add Hardware" on the Control Panel to install the driver. No new hardware is found after scanning the hardware. Select the hardware that has been linked:
Select "Add new hardware device ":
Select manually select from the list:
Select "display card ":
Select the path from "disk installation:
It is normal that the monitor will flash or turn it off and on during installation. At last, we can see that there are more mirror devices in the display device:
Finally, run the command line terminal cmd to execute ddmlapp.exe in E: \ mirror \ bindirectory, and output information about the mirror DRIVER:
The demo results are displayed, but these are only the device information, and there is no actual effect demonstration.
The above completes the compilation and installation of the mirror driver. After the installation is successful, a mirror driver and other devices will be displayed on the display card of the system hardware device management. This indicates that the installation is successful.
2. Mirror Demo:
After mirror is successfully installed, You can compile a demo program in this directory: C: \ Program Files \ ntddk \ SRC \ video \ displays \ mirror \ app, the compiled program is c: \ Program Files \ ntddk \ SRC \ video \ displays \ mirror \ app \ objchk \ i386 \ ddmlapp.exe, but it does not play the role of demo at all, only the information about the mirror driver and registry is displayed after running.
So let's look at the source code. Carefully analyzed the source code (main. cxx). The main process is to obtain the mirror device from the system enumeration, modify the registry, and attach the value. set todesktop to 1 to bind to the System screen. The next step is to call a common GDI function and use bitmap to capture the screen. Therefore, you need to understand the GDI function. The difference is that the mirror device is used here, so it can obtain good performance (fast speed, no flashing screen, etc ):
HDC = createdc ("display", devicename, null, null );
Createmywindow ("mirror sample") is commented in the main. cxx code. In fact, opening the comment does not work. Therefore, I think that if this sample is not modified, it is impossible to see the screenshot effect.
3. In order to achieve the mirror effect, I made some modifications to the source code and moved it to vc6 ++. I only needed to move the file main. cxx. I have created a dialog program. cxx and the new main. h to add this project, you must load the include path: C: \ Program Files \ ntddk \ Inc, and the dynamic library path: C: \ Program Files \ ntddk \ libchk \ i386. cxx has been modified and the source code is attached to it. Add a button to the dialog and call the consumer app (0, null) to see the effect. It should be particularly noted that this is only to test the mirror effect, without any reasonable optimization of the program, so if you want to use it on the project, you need to optimize it on your own.
4. I also mentioned the dfmirage driver in my previous article. In fact, it implements a driver similar to mirror. After downloading and installing the dfmirage driver, I set main. the content related to mirror in the cxx code is modified to dfmirage, and the effect is the same. Of course, it may have done some optimization, and I did not study it carefully.
5. The modified main. cxx code:
1) Main. h
# Ifndef _ mirror_app_h _
# DEFINE _ mirror_app_h _
Void upload app (INT argc, char * agrv []);
# Endif // _ mirror_app_h _
2) Main. cxx
//
// Generic Windows program Template
//
# Include <stdio. h>
# Include <stdlib. h>
# Include <stdarg. h>
# Include "C :\\ Program Files \ ntddk \ Inc \ Windows. H"
# Define mm_max_numaxes
16
Typedef struct tagdesignvector
{
DWORDDvreserved;
DWORDDvnumaxes;
Long Dvvalues [mm_max_numaxes];
} Designvector;
# Include <winddi. h>
# Include <tchar. h>
# Include <WINBASE. h>
# Include <winreg. h>
Char * programname; // Program name
Hinstance appinstance;// Handle to the application instance
Hbitmap HBM;
Lpstr drivername = "Microsoft mirror driver ";
Lpstr dispcode [7] = {
"Change successful ",
"Must restart ",
"Bad flags ",
"Bad Parameters ",
"Failed ",
"Bad mode ",
"Not updated "};
Int Giindex = 0;
Lpstr getdispcode (INT code)
{
Switch (CODE ){
Case disp_change_successful: Return dispcode [0];
Case disp_change_restart: Return dispcode [1];
Case disp_change_badflags: Return dispcode [2];
Case disp_change_badparam: Return dispcode [3];
Case disp_change_failed: Return dispcode [4];
Case disp_change_badmode: Return dispcode [5];
Case disp_change_notupdated: Return dispcode [6];
Default:
Static char TMP [max_path];
Sprintf (& TMP [0], "Unknown Code: % 08x \ n", Code );
Return (lptstr) & TMP [0];
}
Return NULL; // Can't happen
}
//
// Handle window repaint event
//
Void
Dopaint (
Hwnd
)
{
HDC;
Paintstruct pS;
HDC = beginpaint (hwnd, & PS );
Colorref Red = 0x00ff0000;
Hbrush HBr = createsolidbrush (red );
Rect R;
R. Left = ps. rcpaint. Left;
R. Top = ps. rcpaint. Top;
R. Right = ps. rcpaint. Right;
R. Bottom = ps. rcpaint. bottom;
// Fillrect (HDC, & R, HBr );
Hbrush dbrush;
Dbrush = createpatternbrush (HBM );
Fillrect (HDC, & R, dbrush );
Endpaint (hwnd, & PS );
}
//
// Window callback procedure
//
Lresult callback
Mywindowproc (
Hwnd Hwnd,
Uint Umsg,
WparamWparam,
LparamLparam
)
{
Switch (umsg)
{
Case wm_paint:
// MessageBox (null, "repaint !! "," OK ", mb_ OK );
Printf ("Get wm_paint MSG... \ n ");
Dopaint (hwnd );
Break;
Case wm_displaychange:
{
Word cxscreen = loword (lparam );
Word cyscreen = hiword (lparam );
Wparam format = wparam;