背景的视图

4 篇文章 0 订阅
1、画面属性h文件
CSliderCtrl m_slider;
CString m_pic_name;
int m_pic_width;
CString m_pic_path;
COLORREF m_color;
CToolTipCtrl m_tooltip; 
2、编辑框限制字符:
DDV_MaxChars(pDX, m_sm_name, 16);
滑块设置范围:
DDV_MinMaxInt(pDX, m_pic_width, 1, 30);

OnInitDialog():
m_slider.SetRange(1,30);
m_slider.SetPos(8);
m_slider.SetLineSize(1);
m_slider.SetPageSize(5);

CString strFileName;
strFileName.Format(L"config.ini");
CFileFind fFind;
if(fFind.FindFile(strFileName)==FALSE)
{
	SetDlgItemText(IDC_EDIT1,L"画面1");
	SetDlgItemText(IDC_EDIT2,L"8");
	m_color=RGB(0,0,0);
	UpdateData(TRUE);
}
else
{
	CString temp;
	GetPrivateProfileString(L"PicInfo",L"name",L"画面1",m_pic_name.GetBuffer(20),20,L".\\config.ini");
	m_pic_width=::GetPrivateProfileInt(L"PicInfo",L"width",1,L".\\config.ini");
	m_slider.SetPos(m_pic_width);
	m_color=::GetPrivateProfileInt(L"PicInfo",L"color",0,L".\\config.ini");
	GetPrivateProfileString(L"PicInfo",L"path",L"",m_pic_path.GetBuffer(50),30,L".\\config.ini");
}

UpdateData(FALSE);

//tips
m_tooltip.Create(this);

m_tooltip.AddTool(GetDlgItem(IDC_EDIT1), _T("标题不超过16字"));
m_tooltip.AddTool(GetDlgItem(IDC_BUTTON_COLOR), _T("点击选择边框颜色"));
m_tooltip.AddTool(GetDlgItem(IDC_BUTTON_PATH), _T("点击选择背景图片"));

m_tooltip.SetMaxTipWidth(123);
m_tooltip.Activate(TRUE);

3、滑块函数WM_HSCROLL:
CSliderCtrl *pSlidCtrl=(CSliderCtrl*)GetDlgItem(IDC_SLIDER1);
//CString temp;
m_pic_width=pSlidCtrl->GetPos();
UpdateData(FALSE);
CDialog::OnHScroll(nSBCode, nPos, pScrollBar);

4、edit2函数:
CSliderCtrl *pSlidCtrl = (CSliderCtrl*)GetDlgItem(IDC_SLIDER1);
if (m_pic_width > 30)
{
	m_pic_width = 30;
}
UpdateData(TRUE);
pSlidCtrl->SetPos(m_pic_width);

5、颜色按钮
CColorDialog dlg_color;
dlg_color.DoModal();
m_color=dlg_color.GetColor();
Invalidate();

6、DrawItem():
if (nIDCtl == IDC_BUTTON4)         //checking for the button 
{
	CDC dc;
	RECT rect;
	dc.Attach(lpDrawItemStruct->hDC);   // Get the Button DC to CDC

	rect = lpDrawItemStruct->rcItem;     //Store the Button rect to our local rect.

	dc.Draw3dRect(&rect, RGB(255, 255, 255), RGB(0, 0, 0));

	dc.FillSolidRect(&rect, m_color);//Here you can define the required color to appear on the Button.

	UINT state = lpDrawItemStruct->itemState; //This defines the state of the Push button either pressed or not. 

	if ((state & ODS_SELECTED))
	{
		dc.DrawEdge(&rect, EDGE_SUNKEN, BF_RECT);

	}
	else
	{
		dc.DrawEdge(&rect, EDGE_RAISED, BF_RECT);
	}

	dc.SetBkColor(RGB(100, 100, 255));   //Setting the Text Background color
	dc.SetTextColor(RGB(255, 0, 0));     //Setting the Text Color


	TCHAR buffer[MAX_PATH];           //To store the Caption of the button.
	ZeroMemory(buffer, MAX_PATH);     //Intializing the buffer to zero
	::GetWindowText(lpDrawItemStruct->hwndItem, buffer, MAX_PATH); //Get the Caption of Button Window 

	dc.DrawText(buffer, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);//Redraw the Caption of Button Window 

	dc.Detach(); // Detach the Button DC
}
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);

7、路径按钮:
CFileDialog dlg(TRUE, L"", L"", OFN_HIDEREADONLY, L"DATA Files(*.bmp;*.png;*jpg)|*.bmp;*.png;*jpg||");
dlg.DoModal();
m_pic_path = dlg.GetPathName();
//SetDlgItemText(IDC_EDIT2, m_pic_path);
UpdateData(FALSE);

IDC_BUTTON3:
UpdateData(TRUE);
Cdialog::OnOK();

8、主对话框h文件
BOOL flagopen;
int num_joke=0;
CImage m_image;
CString m_pic_name;
int m_pic_width;
CPen pen;
CString m_pic_path;
COLORREF m_color;
CToolBar m_wndToolBar;

9、其菜单栏函数:
dlg.DoModal();
m_pic_name = dlg.m_pic_name;
m_pic_width = dlg.m_pic_width;
m_color = dlg.m_color;
m_pic_path = dlg.m_pic_path;
HRESULT hResult;

m_image.Destroy();
hResult = m_image.Load(m_pic_path);
if (FAILED(hResult))
{
	AfxMessageBox(_T("调用图像出错"));
	return;
}
CString str;
str.Format(L"%s", m_pic_name);
AfxGetMainWnd()->SetWindowTextW(str);
AfxGetMainWnd()->MoveWindow(0, 0, m_image.GetWidth() + 12, m_image.GetHeight() + 75);
AfxGetMainWnd()->CenterWindow();
flagopen = TRUE;
Invalidate();

10、OnDraw函数:
CRect r;
GetClientRect(&r);
if (!m_image.IsNull())
{
	m_image.Draw(pDC->m_hDC, 0, 0, r.Width(), r.Height());
}


pDC->SetBkMode(TRANSPARENT);
pDC->TextOutW(r.Width() / 2 - 20, 35, m_pic_name);
CClientDC dc(this);
CPen pen;
pen.CreatePen(PS_SOLID, m_pic_width, m_color);
dc.SelectObject(&pen);
dc.SelectStockObject(NULL_BRUSH);
dc.Rectangle(r);

11、给工具栏添加响应函数
ON_COMMAND(ID_PSX, &CMFCtest402View::OnTestFunc)

void CMFCtest402View::OnTestFunc()
{
	CDlgPicSX dlg;
	dlg.DoModal();
}

h文件:
afx_msg void OnTestFunc();

12、提示条
1、h文件:
CToolTipCtrl m_tooltip; 

2、OnInitDialog():
m_tooltip.Create(this);

m_tooltip.AddTool(GetDlgItem(IDC_EDIT1), _T("标题不超过16字"));
m_tooltip.AddTool(GetDlgItem(IDC_BUTTON1), _T("点击选择边框颜色"));
m_tooltip.AddTool(GetDlgItem(IDC_BUTTON2), _T("点击选择背景图片"));

m_tooltip.SetMaxTipWidth(123);
m_tooltip.Activate(TRUE);

3、PreTranslateMessage():
ASSERT(pMsg != NULL);
if (pMsg->message == WM_MOUSEMOVE || pMsg->message == WM_LBUTTONDOWN || pMsg->message == WM_LBUTTONUP)
{
	m_tooltip.RelayEvent(pMsg);
}
return CDialog::PreTranslateMessage(pMsg);




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值