很简单的问题,怎么用button改变skin! 定义一个CCourse1Dlg的成员变量,在button的事件中改变标志,并调用Invalidate();在OnPaint中判断该标志,从而显示不同的skin。我认为可以这样做,不知道你是不是这个意思 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你这样不行,按钮没和位图联系起来。我这儿,有一段在Picture上画图,的代码:你看看: for(int i=0;i<2;i++) { CWnd *pWnd=GetDlgItem(IDC_STATIC_PICTURE1+i); CRect rect; BITMAP bt; m_bitmap[i].GetBitmap(&bt); pWnd->Invalidate(); pWnd->UpdateWindow(); pWnd->GetWindowRect(&rect) ; CDC *pDC=pWnd->GetDC(); CDC dcMemory; dcMemory.CreateCompatibleDC(pDC); dcMemory.SelectObject(&m_bitmap[index1[i]]); pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcMemory,0,0,bt.bmWidth,bt.bmHeight,SRCCOPY); dcMemory.DeleteDC(); pWnd->ReleaseDC(pDC); //GetDlgItem(IDC_STATIC_PICTURE1+i)->ShowWindow(TRUE); } 我所些的代码中已实现了背景图,我想解决的是通过button来实现改变,背景图,(如何定义bitmap,具体怎么通过多个button来调用不同的bitmap,我上程序只导入一幅,若有两幅IDB_BITMAP1和IDB_BITMAP2,两个button,OnCat和OnBlue,程序具体如何修改) pBitmap1=new CBitmap;pBitmap2=new CBitmap;pBitmap1->LoadBitmap(IDB_BITMAP1);pBitmap2->LoadBitmap(IDB_BITMAP2);定义一个标志,在OnDraw()或OnPaint()函数中,根据标志选择pBitmap1,pBitmap2;在按钮的事件里修改标志,并调用Invalidate()函数刷新 我把程序做出如下修改:// course1Dlg.h : header file//.......// Constructionpublic:......HBITMAP m_bmp;void CCourse1Dlg::OnPaint() { if (IsIconic()) { ......... } else{ if (m_bmp!=NULL) { CPaintDC dc(this); //HBITMAP hbitmap= // ::LoadBitmap(::AfxGetInstanceHandle(), // MAKEINTRESOURCE(IDB_BITMAP1)); //creat a dc memory HDC hMemDC=::CreateCompatibleDC(NULL); //select the bitmap in the dc memory SelectObject(hMemDC,m_bmp); //copy the memory into the screen dc ::StretchBlt(dc.m_hDC,//destination 0, 0, 401, 300, hMemDC,//source 0, 0, 401, 300, SRCCOPY); //Delete the memory dc and the bitmap ::DeleteDC(hMemDC); ::DeleteObject(m_bmp);} } CDialog::OnPaint();}..............void CCourse1Dlg::OnGreen() { // TODO: Add your command handler code herem_bmp=::LoadBitmap(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP1));Invalidate();}void CCourse1Dlg::OnBlue() { // TODO: Add your command handler code herem_bmp=::LoadBitmap(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP2));Invalidate(); }虽然没有错误显示,但在运行时,出现内存不可写的错误......为什么.....能告诉我解决的方法吗? Visual Studio 2010里面是不是就已经包含了SQL Sever 2008啊? void CALLBACK TimerProc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime); 哪里有水印图片下载 要是8位的才行?? mfc对话框不显示,为什么 再请问界面换肤的问题`` mfc42u.lib error 超线程CPU上的多线程问题。 C语言的一个问题 监视目录下文件的变化并取得文件名? 怎样在启动时隐藏对话框? 有没有知道SQL-SERVER 2000的序列号? 我简直不敢相信,一个确省的对话框程序运行居然要2800K内存。
的代码:你看看:
for(int i=0;i<2;i++)
{
CWnd *pWnd=GetDlgItem(IDC_STATIC_PICTURE1+i);
CRect rect;
BITMAP bt;
m_bitmap[i].GetBitmap(&bt); pWnd->Invalidate();
pWnd->UpdateWindow();
pWnd->GetWindowRect(&rect) ;
CDC *pDC=pWnd->GetDC();
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);
dcMemory.SelectObject(&m_bitmap[index1[i]]);
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcMemory,0,0,bt.bmWidth,bt.bmHeight,SRCCOPY);
dcMemory.DeleteDC();
pWnd->ReleaseDC(pDC);
//GetDlgItem(IDC_STATIC_PICTURE1+i)->ShowWindow(TRUE);
}
pBitmap2=new CBitmap;
pBitmap1->LoadBitmap(IDB_BITMAP1);
pBitmap2->LoadBitmap(IDB_BITMAP2);
定义一个标志,在OnDraw()或OnPaint()函数中,根据标志选择pBitmap1,pBitmap2;
在按钮的事件里修改标志,并调用Invalidate()函数刷新
// course1Dlg.h : header file
//
.......
// Construction
public:
......
HBITMAP m_bmp;
void CCourse1Dlg::OnPaint()
{
if (IsIconic())
{
.........
}
else
{ if
(m_bmp!=NULL)
{
CPaintDC dc(this);
//HBITMAP hbitmap=
// ::LoadBitmap(::AfxGetInstanceHandle(),
// MAKEINTRESOURCE(IDB_BITMAP1));
//creat a dc memory
HDC hMemDC=::CreateCompatibleDC(NULL);
//select the bitmap in the dc memory
SelectObject(hMemDC,m_bmp);
//copy the memory into the screen dc
::StretchBlt(dc.m_hDC,//destination
0,
0,
401,
300,
hMemDC,//source
0,
0,
401,
300,
SRCCOPY);
//Delete the memory dc and the bitmap
::DeleteDC(hMemDC);
::DeleteObject(m_bmp);}
} CDialog::OnPaint();}
..............
void CCourse1Dlg::OnGreen()
{
// TODO: Add your command handler code here
m_bmp=::LoadBitmap(::AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_BITMAP1));
Invalidate();
}void CCourse1Dlg::OnBlue()
{
// TODO: Add your command handler code here
m_bmp=::LoadBitmap(::AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDB_BITMAP2));
Invalidate();
}
虽然没有错误显示,但在运行时,出现内存不可写的错误......为什么.....能告诉我解决的方法吗?