Building Directui Development Platform

Source: Internet
Author: User

The effects of Directui can be implemented using GDI, GDI +, DirectX, OpenGL, commonly GDI and GDI +, the latter two have overkill feeling. We can find this material on the Internet.

Now the software more and more have a very dazzling interface, it seems that businessmen are more and more attention to user experience, this is a popular trend ah. Technically, there are two basic ways to beautify your interface:

1. Directui self-Drawing control mode without handle

2. Inheriting MFC control classes for self-painting

The two have advantages and disadvantages, the former: Complex, control complex (such as: Message control, the basic settings of each control), but the freedom is very large, you can implement any control you can imagine. The latter: the implementation of simple, but constrained by the existing MFC control functions, the most important is the window once more, the window background of the drawing and sub-window drawing if not properly handled can easily cause local mapping incomplete, drag window flashing. As a result, the latter is generally used in the case where the Subwindow control does not drag and drop with the main window, and other suggestions are done in the former way.

Because later will often use Directui to beautify the interface, so the time to play a Directui development platform, convenient for later development, DIRECTUI development platform requirements are as follows:

1. Built on VS2005 's MFC Dialog Project

2. Achieve the most basic of an empty dialog skin

3. After the skin is implemented, you must retain the most basic dialog functions, such as maximizing, minimizing, double-clicking the title bar, clicking Taskbar buttons, dragging and dragging, etc.

4. Build Direcrui engine, the easiest way to facilitate future program expansion

OK, we've started. First build MFC's dialog project, keep all properties default, remove the "OK" and "exit" buttons, as follows:

Then we have to solve one problem after another:

Question 1: Where do we redraw the window

There are 3 message processing to redraw the window: WM_ERASEBKGND, WM_PAINT, Wm_ncpaint, the first only redraws the entire background of the window, including the customer and non-client areas, does not redraw the Subwindow, and the second only redraws the customer area, unable to redraw the non-client area, and the third redraw the non-client area, You can also redraw the customer area. Obviously, we should handle the third message, but the first message we also need to deal with, the entire function, directly return TRUE.

Issue 2: Stubborn system default title bar

Drawing the first step of course is to redraw the title bar, after redrawing the title bar in the Wm_ncpaint, found that the system buttons in the window activation or drag is not flash in the interface, rather stubborn, the following methods can be resolved:

1. Intercept the wm_ncactivate message, this message function is modified as follows:

BOOL Cskintestdlg::onncactivate (bool bactive)
{
This->sendmessage (wm_ncpaint, 0, 0);
return TRUE;
}
2. In the WindowProc function, intercept the message that draws the title bar, with the following code:

LRESULT Cskintestdlg::windowproc (UINT message, WPARAM WPARAM, LPARAM LPARAM)
{
if (message = = 0x00ae | |//wm_ncuahdrawcaption
message = = 0X00AF)//Wm_ncuahdrawframe
{
return wm_ncpaint;
}

return __super::windowproc (Message, WParam, LParam);
}

The above two steps can be a perfect solution to the stubborn title bar button problem.

Issue 3: Distorted title bar message Handling

The system comes with the title bar will change with the theme of the desktop, the height of the title bar, the position of the system button will change, this is quite annoying, we customize the size of the button is generally not the same as the system button. In the process of dealing with this problem, found some causes some contradictions, it is almost difficult to reconcile (sorry, too long, a lot of contradictions forget), such as: customer area coordinates and non-client area coordinate conversion problem (two sets of coordinate system, maintenance is troublesome), the mouse in the title bar double-click Area, maximize the border problem ... ... In combination with these issues, the final processing is: intercept wm_nccalcsize messages, modify the non-client area size, so that the non-client area size is 0, all the self-painted Dongdong in the customer area, including the title bar and border. The code is as follows:

Intercept this message in order for the window to have no title bar and border
void Cskintestdlg::onnccalcsize (BOOL bcalcvalidrects, nccalcsize_params* LPNCSP)
{
__super::onnccalcsize (Bcalcvalidrects, LPNCSP);
}

Issue 4: Dragging Without Borders

Question 3 of the derivation of the problem, without a border, of course, can not be dragged, then we handle the drag and drop it, very simple, intercept wm_nchittest message, the code is as follows:


LRESULT cskintestdlg::onnchittest (CPoint point)
{
Note: This is not a full-screen scenario, it is possible to drag and drop, requiring the user to handle
int ncheckpos = 2;
int nrdpos = Ncheckpos * 2;
CRect wndrect (0, 0, 0, 0);
GetWindowRect (&wndrect);

M_nmousesizetype =-1;
if (point.x >= wndrect.right-nrdpos && point.y >= wndrect.bottom-nrdpos)
{
Lower right corner
return htbottomright;
}
else if (point.x >= wndrect.right-nrdpos && point.y <= wndrect.top + nrdpos)
{
upper right corner
return httopright;
}
else if (point.x <= wndrect.left + nrdpos && point.y <= wndrect.top + nrdpos)
{
Upper left corner
return httopleft;
}
else if (point.x <= wndrect.left + nrdpos && point.y >= wndrect.bottom-nrdpos)
{
Lower left corner
return htbottomleft;
}
else if (point.x >= wndrect.right-ncheckpos)
{
Right line
return htright;
}
else if (point.x <= wndrect.left + ncheckpos)
{
Left line
return htleft;
}
else if (point.y <= wndrect.top + ncheckpos)
{
Top Line
return httop;
}
else if (Point.y >= wndrect.bottom-ncheckpos)
{
Bottom Line
return htbottom;
}

Return __super::onnchittest (point);
}

Issue 5: Maximizing border issues

A normal window, maximized is always bigger than the current screen, just can cover the software's borders, I really do not want this effect, I can only deal with the maximum effect.

I set a maximum message, and when the self-drawn maximize button is pressed, the message is triggered, the message is received, the work area of the screen is taken, and the window is changed to the size of the work area, the code is as follows:


The position of the window before maximizing is recorded before it can be restored.
This->getwindowrect (&m_maxbeforerect);
CRect wndrect (0, 0, 0, 0);
:: SystemParametersInfo (Spi_getworkarea, 0, &wndrect, 0);

This->movewindow (&wndrect);

Here's the problem: maximize the animation, this simple, add a code, play the animation:


The position of the window before maximizing is recorded before it can be restored.
This->getwindowrect (&m_maxbeforerect);
CRect wndrect (0, 0, 0, 0);
:: SystemParametersInfo (Spi_getworkarea, 0, &wndrect, 0);

Play animations
DrawAnimatedRects (Idani_caption, &m_maxbeforerect, &wndrect);

This->movewindow (&wndrect);

The code for the same recovery window is as follows:


Recovery
CRect wndrect (0, 0, 0, 0);
:: SystemParametersInfo (Spi_getworkarea, 0, &wndrect, 0);

Play animations
DrawAnimatedRects (Idani_caption, &wndrect, &m_maxbeforerect);

This->movewindow (&m_maxbeforerect);

Issue 6: Customizing the System Menu

System default system menu (mouse right-click the taskbar button menu), can not be modified, then we do a, check a lot of news, finally found, the message 0x0313 is the right mouse click the taskbar button popup menu message, the code is as follows:

To define a message:

#define Wm_popupsystemmenu 0x0313

Intercept message:

On_message (Wm_popupsystemmenu, Onpopupsystemmenu)

Processing messages:

afx_msg LRESULT Onpopupsystemmenu (WPARAM WPARAM, LPARAM LPARAM);


LRESULT Cskintestdlg::onpopupsystemmenu (WPARAM WPARAM, LPARAM LPARAM)
{
CMenu Popmenu;
CPoint Point;
GetCursorPos (&point);

Popmenu.createpopupmenu ();

Popmenu.appendmenu (mf_string, 111111, _t ("about the Interface Test"));
Popmenu.appendmenu (Mf_separator);
Popmenu.appendmenu (mf_string, IDCANCEL, _t ("Exit \talt+f4"));

Popmenu.trackpopupmenu (Tpm_rightbutton, Point.x, Point.y, this);

Popmenu.destroymenu ();

return 0L;
}
In this way, you can deal with what you want to do.

Finally, we put on the skin, the basic Direcrui platform is built, the effect is as follows:

http://blog.csdn.net/qing666888/article/details/49734897

Building Directui Development Platform

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.