![]() |
The Picture Control |
|
|
The Picture is a static control that was created to be
able to display pictures or other resources. To use the picture control,
on the Controls toolbox, click the Picture button If you plan to refer to the picture control in your code, since it is in fact a static control, at design time, you must change its ID from IDC_STATIC The Picture control is meant to assume different roles in difference circumstances. These roles can be set using the Type combo box.
Besides the above characteristics, you can also enhance the Picture control with the styles inherited from CWnd.
The Picture control can be used to display changing
colors or even as a preview area. In this case, you can use it as a
painting box. To do this, you can first add a Picture control To make it a little easier, you should also add a CStatic Control Variable for it. You can name it m_ColorChanger for example. If you simply plan to change the background color of the color, you can use the OnDraw() of the OnPaint() event to do this. Here is an example: void CExerciseDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect RectColorChanger;
// Get the location and dimensions of the control
m_ColorChanger.GetWindowRect(&RectColorChanger);
CBrush BrushRed(RGB(255, 55, 5));
// Select the new brush
CBrush *pOldBrush = dc.SelectObject(&BrushRed);
// Convert the current coordinates from Screen to Client
ScreenToClient(&RectColorChanger);
// Change the background of the control
dc.Rectangle(RectColorChanger);
// Restore the old brush
dc.SelectObject(pOldBrush);
if (IsIconic())
{
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);
}
else
{
CDialog::OnPaint();
}
}
If you want to change the color of the picture control using other controls, refer to other tutorials on this site. Displaying a static picture on the Picture control is particularly easy. You can first create or import a picture. In MSVC 6, if you import an enhanced picture that uses more than 256 colors, which is common for most picture, you may receive a message that the picture was imported but cannot be displayed. You may get such a message when importing a picture such as this one:
|
Related Articles:
|
|
| Copyright © 2003-2005 FunctionX, Inc. |
|
|