[Repost] SKIN Technology Implementation Framework (3)

xiaoxiao2021-03-06  23

Lastly said the principle of hook and window classes, with hook, we can intercept all messages, with window classes, we can identify window types, different types of windows give different processing. In this way, we have to identify different windows and different messages in the hook function. There are a lot of dispatch work, more destined, the optical zone window classes are not enough, and different windows of the same type often require different processing, such as two button The window, the size is different, the text is different, whether there is a mouse to press different ... Some of these states can be read from the Button window, such as size and text, and some can not read, such as whether there is a mouse button In the state that you can't read, we must record it yourself, for example, write down the button when you receive the WM_LBUTTONDOWN message. That is, for each window, we also need to record some data corresponding to it to do different processing when receiving the WM_PAINT message. Write all these logic in the hook function, even if it can be written, we need a good design.

Based on object-oriented ideas, we need to write a class for each window type and generate an instance of a corresponding class for each window, and process window messages by these instances, and record the necessary window status data. In this way, the task of processing the window message is handed over to these objects, then how to pass the message to these objects, and the hook function is forwarded is a solution, but we use another: SubclassWindow

Regarding the principle of SubclassWindow, don't talk more, you can see MSDN, in fact, it is replacing a window process function. ATL provides ready-made support that is still very convenient, alternative window process functions don't have to write it yourself, and you can use message mapping macro.

Now we can link our object to the window's message chain in the way, it seems to be duplicated with the function of the hook function, because the hook function is used to intercept messages. Now SubclassWindow, the news of the window can be intercepted, then what is the hook function?

The answer is: hook function is used to execute subclasswindow operations

. There are two reasons, first, what we have to do is a Skin Plugin, we hope that the user can call a function to change the entire interface style, not to call the SubclassWindow function for each window; second, some window creation is not Controlled in the code, such as a menu window, in addition to using the hook function, we can't even get the handle of the menu window. So, we must use the hook function, but in the hook function, we only handle a message: WM_CREATE, when you create any one-on-one identifiable window, generate a for object instance, and use SubclassWindow to mount this instance to the target window, rest This object instance is completed.

The rough design has already been, summed up:

1. Write classes for each identifiable window class, implement the necessary message processing and status;

2, use the hook function to intercept the WM_CREATE message and create a corresponding class instance;

3. Actions the generated class instance is attached to the target window by subclasswindow operation; complete the work of message processing and status.

Posted on 2004-05-18 11:49 Vibration Reading (484) Comments (6) Edit Collection

Comment # RE: SKIN Technology Implementation Framework (3) 2004-05-19 18:06 Yanxm See the E-text of this article on CodeProject. I feel very creative, thank you first here. I hope to see subsequent articles.

# RE: SKIN Technology Implementation Framework (3) 2004-05-19 20:37 Vibration

Will continue to write, Chinese can write detailed, E text can only be streamlined as possible, there may not be clear: P

# Re: Skin Technology Implementation Framework (3) 2004-05-20 09:51 Yanxm

I downloaded your code. After I compile, I have discovered the draw button, and some conflicts have been drawn in some cases. For example, when you press the left mouse button on the button, you don't release the mouse to the point other than the button. This time the button itself will be displayed (you want to fly up on the picture, but don't know how to post.). But I don't have this problem, I don't know if you compile this test program, I don't know if you compile this test program. There is also a question about GroupBox. Since my program needs to dynamically modify the topic of GroupBox based on the conditions, when I replace the title, after the call function setWindowText replaces the title, the refresh is a bit problem, which is the drawing of the GroupBox itself. For PushButton drawn issues, I take the liberty to make some changes to your code. The idea is to change the Style of Button into self-drawing after SubclassWindow operations for Button, which will not interfere with Button itself, and I estimate that as long as the WM_DRAWITEM and WM_MEASUREITEM messages can be handled, but I have not tried it. But Checkbox and Radiobutton do not have a BS_OWNERDRAW style, so it can't do this. Drawing interference issues have not been resolved. The following is a place to modify to CMACButton: 1. Add member variables long m_ictrltype; 2, void initialize () {m_nstate = state_normal; m_btracking = false; if (BaseTyPE_Button == getBaseType ()) {: : SetWindowLong (m_hWnd, GWL_STYLE, :: GetWindowLong (m_hWnd, GWL_STYLE) | BS_OWNERDRAW);}} 3, long getBaseType () {if (! m_iCtrlType = - 1) return m_iCtrlType; long lStyle = GetWindowLong (GWL_STYLE); if (( lStyle & BS_OWNERDRAW) == BS_OWNERDRAW) // ownerdraw return m_iCtrlType = BASETYPE_OWNERDRAW; if ((lStyle & BS_GROUPBOX) == BS_GROUPBOX) // groupbox return m_iCtrlType = BASETYPE_GROUPBOX; else if ((lStyle & BS_CHECKBOX) == BS_CHECKBOX || (lStyle & BS_AUTOCHECKBOX) == BS_AUTOCHECKBOX) // checkbox return m_iCtrlType = BASETYPE_CHECKBOX; else if ((lStyle & BS_AUTORADIOBUTTON) == BS_AUTORADIOBUTTON || (lStyle & BS_RADIOBUTTON) == BS_RADIOBUTTON) // radiobox return m_iCtrlType = BASETYPE_RADIOBUTTON; // return the push button m_ictrltype = basetype_button;} The above green color is part of my increase. # Re: Skin Technology Implementation Frame (3) 2004-05-20 13:29 Vibration

It is also an implementation method. The original code does not use this method to consider the host system may have OwnerDraw button # Re: Skin technology implementation framework (3) 2004-09-15 13:02 Happy wind

I downloaded the code of your code, how did you compile it? Tip error is: c: / documents and settings / chrys / desktop /skinx_demo/skinx/stdafx.h (22): Fatal Error C1083: Cannot Open include file: 'atlapp.h': no ​​such file or directory

转载请注明原文地址:https://www.9cbs.com/read-81036.html

New Post(0)