Activeskin is an ActiveX control that replaces the skin of software. It fortunately frees the Software Interface Design from tedious program code writing, so that functional designers can concentrate on the implementation of functional code, and hand over the software interface to the artist. It improves the efficiency of interface design and is a good software design idea.
The following uses three examples to describe their general usage.
Example 1:Standard skin skinform dialog box project
Create an MFC basic dialog box project in the VC environment. In the resource file of the dialog box, Delete the existing buttons and label lables in the interface of the DLG. RC Design dialog box, insert the ActiveX Control of activeskin, and name it idc_skin. Right-click the activeskin control and select the loadskin menu item in ActiveX properties to load a skin file in advance.
Add the following statement before // {afx_insert_location} In stdafx. h:
// The purpose is to import the function interface library of activeskin.
# Include <atlbase. h>
# Import "actskn43.ocx" no_implementation raw_interfaces_only raw_native_types
Using namespace activeskinlib;
Then, add the statement in the DLG. cpp file:
Ccomqiptr <iskin> m_pskin = getdlgitem (idc_skin)-> getcontrolunknown (); // m_pskin is the global volume of applications.
M_pskin-> loadskin (L "path of skin file X"); // This sentence can be omitted if the activeskin control already contains skin.
M_pskin-> applyskin (INT) m_hwnd );
Compile and run the program. You can see that the skin file x becomes the program running interface. If you want to change the skin while the program is running, you can. Create a button in the dialog box and add a click event:
Void cmy1dlg: onbnewskin ()
{
Static char based_code szfilter [] = "activeskin files (*. skn) | *. skn |"; // file filter settings.
Cfiledialog DLG (false, ". skn", null, ofn_hidereadonly, szfilter); // The skin file selection window.
If (DLG. domodal () = idok) // The skin file is selected successfully:
{
Uses_conversion;
M_pskin-> loadskin (T2W (DLG. getpathname (); // load the specified skin file.
M_pskin-> applyskin (INT) m_hwnd); // make the current skin take effect.
}
}
You will find that the main window has been successfully changed during running, but the "about" dialog box and other non-main windows have not changed. You need to add a sentence to the oninitdialog () event of aboutdlg:
m_pSkin->ApplySkin((int)m_hWnd);
Run it again and everything is OK!
Example 2:Standard skin skinform multi-document Engineering
Similar to Example 1, the difference is that the child form must be modified in the create event of childfrm. cpp:
BOOL bRes = CMDIChildWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, pContext);
m_pSkin->ApplySkin((long)m_hWnd);
return bRes;
In this way, you can.
Example 3:Free skin skinfreeform event operations
Unlike the above skinform, skinfreefrom is another type of skin file solution. Therefore, its operation methods are different. You can refer to the example of topcolorizer In the example provided by activeskin. The main difference between skinform and skinfreefrom lies in the skinapply method and the event-driven method.
If (failed (m_pskin-> loadskin (temp) | // all use loadskin () to load a skin. The parameter is the path name of the skin file.
Failed (m_pskin-> applyskinbyname (long) m_hwnd, l "freeform ")))
// Apply applyskin to skinform skin,
// This method will automatically replace all the skinobject elements in a skin with the specified handle window.
// Apply applyskinbyname () to the skinfreeform skin,
// The first parameter is the window handle, and the second parameter is the name of an object in skinbuilder.
{
MessageBox ("cocould not load or apply the skin .");
Postmessage (wm_close );
Return false;
}
Event-driven differences: skinform does not affect the original event working method of the program code during skin replacement, but only the skin replacement on the interface, so skinform: applyskin (handle) is OK; but skinfreeform is different. It must use a message pump to send messages to the program to get events on the skin, and iskinobject: getname (BSTR *) is used in the event *) obtain the related skin elements, and use getskinnedwindow (hwnd ). findobject ("screen") to obtain the corresponding element handle and set the element state. A simple message pump can be set and written by right-clicking event on the skin control.
For specific implementation, see the sample source code. Before using the example, install activeskin4.3. You may need to modify the initial loadskin (skin file) of the skin control in the example to use it properly.