How can I use a custom skinmagic control in VC?

Source: Internet
Author: User
In skinmagic, a control skin is customized and added to the skin file (. SMF). But how can I use it in VC programs? This document uses csplitterwnd as an example to describe how to use it.

I want to design a skin for the csplitterwnd split, skinmagic does not provide this standard control; so I customized this control.

The control skin type is "skinsplitter", which has three main attributes:

Splitterbar: imagerect type

Border: imagesetion type

Gripper: imagesetion type

The object named "skinsplitter" is added to the skin file ".

Now let's talk about the method used in the program. Suppose we have loaded the skin file into the program, and we reload the csplitterwnd class named cxsplitterwnd.

1. register the control skin object

Reload csplitterwnd: oncreate () and then call registerskinwindow (m_hwnd, 0 ):

Int cxsplitterwnd: oncreate (maid)
{
If (csplitterwnd: oncreate (lpcreatestruct) =-1)
Return-1;
 
Registerskinwindow (m_hwnd, 0 );
 
Return 0;
}

2. When the control is destroyed, the anti-registration control skin object

Reload csplitterwnd: ondestroy (), and then call unregisterskinwindow and closeskindata:

Void cxsplitterwnd: ondestroy ()
{
Csplitterwnd: ondestroy ();
 
Unregisterskinwindow (m_hwnd );
Closeskindata (m_hskin); // m_hskin is a member of the hskin type added in cxsplitterwnd.
}

3. Add the response function of the message wm_skindatachanged.

Wm_skindatachanged is a custom message of skinmagic SDK, indicating that skin data changes. You can easily compile the message response function. :)

We define the message response function as onskindatachanged; the object skinsplitter loaded into the skin file:

Lresult cxsplitterwnd: onskindatachanged (wparam, lparam)
{
If (m_hskin) closeskindata (m_hskin );

M_hskin = openskindata ("skinsplitter"); // custom skin object in the skin file
If (m_hskin)
{
Redrawwindow ();
}
Return 1;
}

4. Call methods such as drawskinimagerect and drawskinimagesetion to re-paint the shard.

The method I used is to reload the csplitterwnd: onpaint (), in which the redraw split entries:

Void cxsplitterwnd: onpaint ()

{

......

// Rectsplitter is the real square area of the split bar

// For how to obtain the real square area of a shard, see another article. "How to obtain the real rect of the shard? "

Drawskinimagerect (m_hskin, _ T ("splitterbar"), DC, & rectsplitter); // repaint splitterbar Based on the skinsplitter attribute of the skin object
Drawskinimagesection (m_hskin, _ T ("border"), DC, & rectsplitter); // redraw the border based on the skinsplitter attribute of the skin object
Drawskinimagesection (m_hskin, _ T ("gripper"), DC, & rectsplitter); // repaint gripper based on the skinsplitter attribute of the skin object

}

End now!

The usage of other custom controls is roughly the same, but may vary with overloaded functions.

Hope to help you ,:)

 

 

I want to re-draw the split string, but I found it wrong after obtaining it using the csplitterwnd: getrect (...) method? Here we will teach you how to obtain the real square area of the split bar.

If the split string type is cmysplitterwnd (inherited from csplitterwnd) and the object is m_splitter
The square area obtained by m_splitter.getrect (rect) is actually the square area of the entire split window. If you want to obtain the rect of the split, you have to calculate it by yourself. The method is as follows:
Below:

// (Suppose we have reloaded csplitterwnd: onpaint ())

Void cmysplitterwnd: onpaint ()
{
Cpaintdc DC (this); // device context for painting

Int icolumn = 0;
Int irow = 0;
Rect rect1, rect2, rectsplitter;

// Obtain the rect of each vertical split bar

For (icolumn = 1; icolumn <getcolumncount (); icolumn ++)
{
Getpane (0, iColumn-1)-> getwindowrect (& rect1 );
Getpane (getrowcount ()-1, icolumn)-> getwindowrect (& rect2 );

Rectsplitter. Top = rect1.top;
Rectsplitter. Bottom = rect2.bottom;
Rectsplitter. Right = rect2.left;
Rectsplitter. Left = rect1.right;

Screentoclient (& rectsplitter );
//... Do what u want to do!

}

// Obtain the rect of each horizontal split bar

For (irow = 1; irow <getrowcount (); irow ++)
{
Getpane (iRow-1, 0)-> getwindowrect (& rect1 );
Getpane (irow, getcolumncount ()-1)-> getwindowrect (& rect2 );

Rectsplitter. Top = rect1.bottom;
Rectsplitter. Bottom = rect2.top;
Rectsplitter. Right = rect2.right;
Rectsplitter. Left = rect1.left;

Screentoclient (& rectsplitter );
//... Do what u want to do!
}
}

 

Another method is to use the csplitter=wimpl class in wtl7.1. Its member function getsplitterbarrect (...) can be directly obtained, but wtl7.1 can only support windows and XP systems. It is not suitable for commercial product development.

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.