The realization of Activeskin 4.3 software for the skin-changing in VC

Source: Internet
Author: User

Activeskin is an ActiveX control that replaces the skin for the software. It's fine. The software interface design work is freed from the tedious programming code, so that the function designer can concentrate on the realization of the function code, and hand over the software interface to the art staff. It is a good idea of software design to improve the working efficiency of interface design.

The following three examples describe his general usage.

Example one: Standard skin skinform Dialog-Box project

In the VC environment to establish an MFC Basic dialog box project. In the dialog box's resource file, in the Dlg.rc Design dialog interface, delete the existing button buttons and label lables, and insert the Activeskin ActiveX control, named Idc_skin. Right-click the Activeskin Control and select Loadskin menu item in the ActiveX property to preload a skin file.

Add the following statement before//{{afx_insert_location} in StdAfx.h:

//目的是导入ActiveSkin的函数接口库。
  #include <atlbase.h>
  #import "actskn43.ocx" no_implementation raw_interfaces_only raw_native_types
  using namespace ACTIVESKINLib;

Next, add the statement in the Dlg.cpp file:

CComQIPtr<ISkin> m_pSkin=GetDlgItem(IDC_SKIN)->GetControlUnknown();//m_pSkin是应用程序全局量。
  m_pSkin->LoadSkin(L"皮肤文件X的路径");//如果ActiveSkin控件中已有皮肤,此句可省略。
  m_pSkin->ApplySkin((int)m_hWnd);

Compiled to run, you can see that the skin file x becomes the running interface of the program. If you want to change the skin while the program is running, that's OK. Create a button on the dialog box and add the Click event:void CMy1Dlg::OnBNewSkin()
  {
   static char BASED_CODE szFilter[] = "ActiveSkin Files (*.skn)|*.skn||";//文件过滤器设置。
   CFileDialog dlg(FALSE, ".skn", NULL, OFN_HIDEREADONLY, szFilter);//Skin文件选择窗口。
   if (dlg.DoModal() == IDOK)//Skin文件选择成功:
   {
    USES_CONVERSION;
    m_pSkin->LoadSkin(T2W(dlg.GetPathName()));//载入指定的Skin文件。
    m_pSkin->ApplySkin((int)m_hWnd);//使当前Skin生效。
   }
  }

You will find that the main window of the runtime has been successfully replaced, but the "about" dialog box and other non main windows have not changed. Need to add a sentence in the OnInitDialog () event of Aboutdlg: m_pSkin->ApplySkin((int)m_hWnd); run it all OK!

Example two: Multi-document engineering for standard skin Skinform

This is similar to example one, except that the subform is modified in the ChildFrm.cpp create event:

BOOL bRes = CMDIChildWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, pContext);
  m_pSkin->ApplySkin((long)m_hWnd);
  return bRes;
That's it.

Example three: Free Skin Skinfreeform Event operations

Unlike the above Skinform, Skinfreefrom is another type of skin file scheme. So it's a different way of doing things. You can refer to an example of Desktopcolorizer in Activeskin's own sample. The main difference between Skinform and Skinfreefrom is the way skinapply methods and events are driven.

if(FAILED(m_pSkin->LoadSkin(Temp))|| //均使用LoadSkin()装载某一Skin,参数是Skin文件的路径名。
   FAILED(m_pSkin->ApplySkinByName((long)m_hWnd, L"FreeForm")))
   //SkinForm类型的皮肤使用ApplySkin使其生效,
   //这种方式会自动将某Skin中的所有SkinObject元素替代指定Handle的窗口。
   //SkinFreeForm类型的皮肤使用ApplySkinByName()使其生效,
   //其中第一个参数是窗口句柄,第二个参数是SkinBuilder中一个Object的名字。
  {
   MessageBox("Could not load or apply the skin.");
   PostMessage(WM_CLOSE);
   return FALSE;
  }

Event-driven differences: skinform skin change does not affect the program code of the original event working mode, but the interface of the skin, so Skinform::applyskin (Handle) on the OK; but Skinfreeform is different, it must use a message pump, The message is used to get the program to the event on skin, and the Iskinobject::getname (BSTR *) is used in its event to obtain the relevant skin element, with Getskinnedwindow (HWND). Findobject ("screen") to get the corresponding element handle to set the element state. A simple message pump can be set up and written by the skin control on the right key event.

See the sample source code for a specific implementation. The example installs the ActiveSkin4.3 before use, and may also need to modify the skin control's initial Loadskin (skin file) in the case to work properly.

This article supporting source code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.