Tutorials to .com

Tutorials to .com » Software » Vc » VC programming how to achieve 3D text in the interface

VC programming how to achieve 3D text in the interface

Print View , by: iSee ,Total views: 27 ,Word Count: 412 ,Date: Wed, 26 Aug 2009 Time: 4:09 PM

Author: Liu Tao

Under normal circumstances, the program developers hope that their beautiful and generous program, in order to achieve this a requirement, try every means to beautify their own procedures, if the right place at the interface to add and display 3D text, would seem to be a good choice, you can perform more efficiently, this article address this issue, through a simple small program on how to achieve this goal. Interested readers can slightly change, the method is applied to their own programs to go.

First, start the vc generates a new dialog-based project, named 3Dtext, in the dialog box override OnPaint () function, concrete realization of the idea that through the CDC:: SetTextColor (), respectively to set the text color for the highlight (3DHILIGHT ) and Shadow (3DSHADOW) state display text; paying attention to display text in two staggered when a pixel, so as to achieve the desired results. Concrete realization of the code is as follows:

void CMy3DTextDlg:: OnPaint ()
(If (IsIconic ())
CPaintDC dc (this); / / device context for painting
SendMessage (WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc (), 0);
/ / Center icon in client rectangle
int cxIcon = GetSystemMetrics (SM_CXICON);
int cyIcon = GetSystemMetrics (SM_CYICON);
CRect rect;
GetClientRect (& rect);
int x = (rect.Width () - cxIcon + 1) / 2;
int y = (rect.Height () - cyIcon + 1) / 2;
/ / Draw the icon
dc.DrawIcon (x, y, m_hIcon);
CPaintDC dc (this); / / device context for painting
CString string;
string = "computer newspaper, and our study materials";
CFont m_fontLogo;
m_fontLogo.CreateFont (44, 0, 0, 0, 55, FALSE, FALSE, 0,0,0,0,0,0, "Arial");
CRect rectText;
GetClientRect (& rectText);
CFont * OldFont = dc.SelectObject (& m_fontLogo);
/ / Draw text in DC
COLORREF OldColor = dc.SetTextColor (:: GetSysColor (COLOR_3DHILIGHT));
dc.DrawText (string, rectText + CPoint (1,1), DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_CENTER);
dc.SetTextColor (:: GetSysColor (COLOR_3DSHADOW));
dc.DrawText (string, rectText, DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_CENTER);
/ / Restore old text color
dc.SetTextColor (OldColor);
/ / Restore old font
dc.SelectObject (OldFont);
/ / CDialog:: OnPaint ();

Visual C++ Tutorial Articles

Can't Find What You're Looking For?

Rating: Not yet rated


No comments posted.