To achieve a satisfactory style of the unified software interface is really difficult, like the user mentioned MessageBox, FileDialog, FontDialog, Directory selection dialog box, such as MFC internal and even the System DLL dialog box, to make it difficult to face. Some people say that hook technology can be, hook technology can be, hook can be said to be all-pervasive, but the use of hooks is not satisfactory, from the current use of most of the technology of the skin-changing software, it can prove this point. Today we are going to discuss another technique to achieve FileDialog's face, which is called the replacement window process method (Note: I fabricate).
Window procedure functions are available in most windows, and it handles every event in the window (including child windows). The replacement window process method is better than the hook technology who is weak is very obvious, because the same hook can only intercept an event, processing is quite time-consuming, hook also has its advantages, but it is not to be discussed in this article. Here first let everyone see the real, please look at the following figure:
One, principle explanation:
The window procedure to replace the dialog box uses this function SetWindowLong () its prototype is as follows:
LONG SetWindowLong(HWND hWnd, int nIndex , long dwLongNewProc)
hWnd为指定窗口的句柄,
nIndex 为 GWL_WNDPROC时才可设定新的窗口过程
dwLongNewProc 为指定新的窗口过程函数地址
The back value is a long value, which is the old window procedure function address.
If you want to replace a window's window procedure function, you first have to think about the handle to its window, and of course the window process.
Second, CFileDialog file dialog box interface design
A. Cmyfiledialog from CFileDialog derived classes;
B. Add protected-type virtual member functions: Oninitdone ();
This letter is actually CFileDialog a virtual function, it is called after the file dialog box is created, it leaves us an entrance, because some overloaded reality replaces its window process function;
C. Add member functions Mywindowprocnew ()
static LRESULT CALLBACK WindowProcNew(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam);