随时间改变文本框的背景色 有一个单文档的程序,可以弹出一个对话框,对话框里有一个文本框,我想实现文本框的背景色随着时间改变,不知道怎么做。请哪位大侠帮帮忙,最好能提供源代码。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 自绘吧 或者在OnctlColor消息中 获得你要改变控件的ID 自绘 响应对话框的WM_CTLCOLOR消息判断nCtlColor=CTLCOLOR_EDIT,然后调用pDC->SetBkColor设置颜色即可如果存在多个文本编辑框,则需要通过pWnd->GetDlgCtrlID获得控件ID,然后比较是不是你要变色的控件,然后再调用pDC->SetBkColor就是这样…… 全局变量 int m_icolor;初始化中m_icolor = rand()%256;void CTest::OnButton1() {// TODO: Add your control notification handler code hereSetTimer(2,1000,NULL);}void CTest::OnTimer(UINT nIDEvent) {// TODO: Add your message handler code here and/or call defaultif (nIDEvent==2){ m_icolor = rand()%256;//产生随机颜色}CDialog::OnTimer(nIDEvent);}HBRUSH CTest::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) {HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);// TODO: Change any attributes of the DC hereif(nCtlColor==CTLCOLOR_STATIC) //修改静态文本颜色{ pDC->SetTextColor(m_icolor ,rand()%256,rand()%256)); pDC->SetBkColor(m_icolor ,rand()%256,rand()%256)); HBRUSH b=CreateSolidBrush(RGB(m_icolor ,rand()%256,rand()%256)); return b;}return hbr;}} 我想用Settimer 做定时器,然后接受消息,改变文本框的背景色,不知道怎么自绘?这是我的代码void CTest::OnButton1() { // TODO: Add your control notification handler code here SetTimer(2,1000,NULL);}void CTest::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default if (nIDEvent==2) { i=i+9;} CDialog::OnTimer(nIDEvent);}HBRUSH CTest::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);if(nCtlColor==CTLCOLOR_STATIC) //修改静态文本颜色{ pDC->SetTextColor(RGB(rand()%256,rand()%256,rand()%256)); pDC->SetBkColor(RGB(rand()%256,rand()%256,rand()%256)); HBRUSH b=CreateSolidBrush(RGB(rand()%256,rand()%256,rand()%256)); return b;} // TODO: Return a different brush if the default is not desired return hbr; // TODO: Change any attributes of the DC here if ((pWnd->GetDlgCtrlID() == IDC_EDIT1) && (nCtlColor == CTLCOLOR_EDIT)) { COLORREF clr = RGB(0,i,0); pDC->SetBkColor(clr); //设置黑色的背景 m_brMine = ::CreateSolidBrush(clr); return m_brMine; //作为约定,返回背景色对应的刷子句柄 } else { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Return a different brush if the default is not desired return hbr;}} CStdioFile对象读文件后计算字符串长度时把空格也算进去 定义了一个继承CWnd的类,如何可以相应CWnd里的函数 请问我的理解对不对?udp通信过防火墙有两种主流方法1:socks5 2:http tunnel 求救!请问哪里有emule的源代码下载呀!急!!!!!! MFC应用方面关于Dialog的问题 网络通信冲突? 大家来看看,一个很简单的问题,一起来讨论讨论!!! 如何制作这种界面? 请大家给我一些学VC的建议 怎样处理注册表? 关于读文件显示数据到编辑框的问题? 自绘的CMENU,要分的来
判断nCtlColor=CTLCOLOR_EDIT,然后调用pDC->SetBkColor设置颜色即可
如果存在多个文本编辑框,则需要通过pWnd->GetDlgCtrlID获得控件ID,然后比较是不是你要变色的控件,然后再调用pDC->SetBkColor
就是这样……
int m_icolor;
初始化中
m_icolor = rand()%256;void CTest::OnButton1()
{
// TODO: Add your control notification handler code here
SetTimer(2,1000,NULL);}void CTest::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if (nIDEvent==2)
{
m_icolor = rand()%256;//产生随机颜色
}
CDialog::OnTimer(nIDEvent);
}
HBRUSH CTest::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC hereif(nCtlColor==CTLCOLOR_STATIC) //修改静态文本颜色
{
pDC->SetTextColor(m_icolor ,rand()%256,rand()%256));
pDC->SetBkColor(m_icolor ,rand()%256,rand()%256));
HBRUSH b=CreateSolidBrush(RGB(m_icolor ,rand()%256,rand()%256));
return b;
}
return hbr;
}
}
void CTest::OnButton1()
{
// TODO: Add your control notification handler code here
SetTimer(2,1000,NULL);}void CTest::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if (nIDEvent==2)
{ i=i+9;}
CDialog::OnTimer(nIDEvent);
}
HBRUSH CTest::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor==CTLCOLOR_STATIC) //修改静态文本颜色
{
pDC->SetTextColor(RGB(rand()%256,rand()%256,rand()%256));
pDC->SetBkColor(RGB(rand()%256,rand()%256,rand()%256));
HBRUSH b=CreateSolidBrush(RGB(rand()%256,rand()%256,rand()%256));
return b;
} // TODO: Return a different brush if the default is not desired
return hbr;
// TODO: Change any attributes of the DC here if ((pWnd->GetDlgCtrlID() == IDC_EDIT1) && (nCtlColor == CTLCOLOR_EDIT))
{
COLORREF clr = RGB(0,i,0);
pDC->SetBkColor(clr); //设置黑色的背景
m_brMine = ::CreateSolidBrush(clr);
return m_brMine; //作为约定,返回背景色对应的刷子句柄
}
else
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Return a different brush if the default is not desired
return hbr;
}
}