我做了一个图象的界面,对话框的,在OnPaint中 画上背景图案,然后用Invalidate 方法刷新每个控件,但是控件并没有完全显示出来,特别是CCtrlList 等控件,滚动条有时候显示不出来,CEdit控件边上的3d效果也出不来,这是怎么了?哪位大虾指点指点!
解决方案 »
- 关于图像卷积的问题,望高手指点!
- 请教DX SDK的问题!
- C++, 有人想做视频开发兼职或者专职吗
- TAB键处理问题,在线等。如果解决即时给分
- 调试的时候代码行定位不准是怎么回事?
- CMainFrame是从cwnd派生的为是么我用ClassWizard无法响应WM_SYSCOMMAND消息啊
- 求救!缩小jpg,bpm的尺寸??
- 如何用VC编写一个让字体变粗的程序?
- IPicture::Render如何翻转图片?
- 如何通过编程(Win32 API)共享目录?
- 我不知道我的问题放在这里是否合适,关于——开机提示::windows在造访系统注册表时遇到错误
- 将不同格式的文件导入SQL Server数据库!
{
.........CCtrlList->RedrawWindow();//用REDRAWWINDOW代替Invalidate
滚动条->RedrawWindow();
CEdit->RedrawWindow();
}
// Invalidate window so entire client area
// is redrawn when UpdateWindow is called.
Invalidate();
UpdateWindow();
你把控件的 Ower draw 设置上就可以了
对话框的 classwizrd 中没有 onEraseBackground啊,你的意思是直接填加 onEraseBackground ()吗?
顺便问问,我的三角形怎么成立 2个了,少了2个了
你的那个做法,好象不管用哦
WM_ERASEBKGND
The WM_ERASEBKGND message is sent when the window background must be erased (for example, when a window is resized). The message is sent to prepare an invalidated portion of a window for painting. A window receives this message through its WindowProc function. LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_ERASEBKGND
WPARAM wParam, // handle to device context (HDC)
LPARAM lParam // not used
);
Parameters
wParam
Handle to the device context.
lParam
This parameter is not used.
Return Values
An application should return nonzero if it erases the background; otherwise, it should return zero. Res
The DefWindowProc function erases the background by using the class background brush specified by the hbrBackground member of the WNDCLASS structure. If hbrBackground is NULL, the application should process the WM_ERASEBKGND message and erase the background. An application should return nonzero in response to WM_ERASEBKGND if it processes the message and erases the background; this indicates that no further erasing is required. If the application returns zero, the window will remain ed for erasing. (Typically, this indicates that the fErase member of the PAINTSTRUCT structure will be TRUE.)
WM_ERASEBKGND
The WM_ERASEBKGND message is sent when the window background must be erased (for example, when a window is resized). The message is sent to prepare an invalidated portion of a window for painting. A window receives this message through its WindowProc function. LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_ERASEBKGND
WPARAM wParam, // handle to device context (HDC)
LPARAM lParam // not used
);
Parameters
wParam
Handle to the device context.
lParam
This parameter is not used.
Return Values
An application should return nonzero if it erases the background; otherwise, it should return zero. Res
The DefWindowProc function erases the background by using the class background brush specified by the hbrBackground member of the WNDCLASS structure. If hbrBackground is NULL, the application should process the WM_ERASEBKGND message and erase the background. An application should return nonzero in response to WM_ERASEBKGND if it processes the message and erases the background; this indicates that no further erasing is required. If the application returns zero, the window will remain ed for erasing. (Typically, this indicates that the fErase member of the PAINTSTRUCT structure will be TRUE.)
怎么我在WindowProc 里判断 WM_ERASEBKGND后,
刷新图片还是不行啊?LRESULT CSdfadfDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
// TODO: Add your specialized code here and/or call the base class
if (message == WM_ERASEBKGND )
{
TRACE("WM_ERASEBKGND.\n"); ASSERT(m_pFace != NULL);
LPBITMAPINFOHEADER pInHeader = (LPBITMAPINFOHEADER)m_pFace;
char *pBuf = m_pFace + sizeof(BITMAPINFOHEADER);
HDC hDc;
hDc = GetDC ()->GetSafeHdc ();
DrawDibDraw(hdib,
hDc,
0,0,
pInHeader->biWidth ,
pInHeader->biHeight ,
pInHeader,
pBuf,
0,0,
pInHeader->biWidth ,
pInHeader->biHeight ,
DDF_BACKGROUNDPAL);
::ReleaseDC (this->m_hWnd,hDc);
m_l1.Invalidate ();
m_l2.Invalidate ();
m_l3.Invalidate ();
m_l4.Invalidate ();
return 1;
} return CDialog::WindowProc(message, wParam, lParam);
}能留下e-mail 吗 发给大家帮我看看
{
public:
CBackgroundManager();
virtual ~CBackgroundManager(); enum BackgroundLocation
{
BACKGR_TILE,
BACKGR_TOPLEFT,
BACKGR_TOPRIGHT,
BACKGR_BOTTOMLEFT,
BACKGR_BOTTOMRIGHT,
};
protected:
HBITMAP m_hBkgrBitmap;
CSize m_sizeBkgrBitmap;
CBrush m_brBkgr;
BackgroundLocation m_BkgrLocation;
BOOL m_bAutoDestroyBmp;
CWnd* m_pWnd;
public:
void Init(CWnd* pWnd){m_pWnd=pWnd;}
void SetBackgroundColor (COLORREF color, BOOL bRepaint = TRUE);
void SetBackgroundImage (HBITMAP hBitmap,
BackgroundLocation location = BACKGR_TILE,
BOOL bAutoDestroy = TRUE,
BOOL bRepaint = TRUE);
BOOL SetBackgroundImage (UINT uiBmpResId,
BackgroundLocation location = BACKGR_TILE,
BOOL bRepaint = TRUE);
BOOL HandleOnEraseBackground(CDC* pDC);
void HandleOnDestroy();
};
{
m_hBkgrBitmap = NULL;
m_sizeBkgrBitmap = CSize (0, 0);
m_BkgrLocation = (BackgroundLocation) -1;
m_bAutoDestroyBmp = FALSE;
m_pWnd=NULL;
}CBackgroundManager::~CBackgroundManager()
{}
//*************************************************************************************
void CBackgroundManager::SetBackgroundColor (COLORREF color, BOOL bRepaint)
{
if (m_brBkgr.GetSafeHandle () != NULL)
{
m_brBkgr.DeleteObject ();
} if (color != (COLORREF)-1)
{
m_brBkgr.CreateSolidBrush (color);
} if (bRepaint && m_pWnd->GetSafeHwnd () != NULL)
{
m_pWnd->Invalidate ();
m_pWnd->UpdateWindow ();
}
}
//*************************************************************************************
void CBackgroundManager::SetBackgroundImage (HBITMAP hBitmap,
BackgroundLocation location,
BOOL bAutoDestroy,
BOOL bRepaint)
{
if (m_bAutoDestroyBmp && m_hBkgrBitmap != NULL)
{
::DeleteObject (m_hBkgrBitmap);
} m_hBkgrBitmap = hBitmap;
m_BkgrLocation = location;
m_bAutoDestroyBmp = bAutoDestroy; if (hBitmap != NULL)
{
BITMAP bmp;
::GetObject (hBitmap, sizeof (BITMAP), (LPVOID) &bmp); m_sizeBkgrBitmap = CSize (bmp.bmWidth, bmp.bmHeight);
}
else
{
m_sizeBkgrBitmap = CSize (0, 0);
} if (bRepaint && m_pWnd->GetSafeHwnd () != NULL)
{
m_pWnd->Invalidate ();
m_pWnd->UpdateWindow ();
}
}
//*************************************************************************************
BOOL CBackgroundManager::SetBackgroundImage (UINT uiBmpResId,
BackgroundLocation location,
BOOL bRepaint)
{
HBITMAP hBitmap = NULL; if (uiBmpResId != 0)
{
hBitmap = ::LoadBitmap (AfxGetResourceHandle (),
MAKEINTRESOURCE (uiBmpResId));
if (hBitmap == NULL)
{
ASSERT (FALSE);
return FALSE;
}
} SetBackgroundImage (hBitmap, location, TRUE /* Autodestroy */, bRepaint);
return TRUE;
}
//virtual
BOOL CBackgroundManager::HandleOnEraseBackground(CDC* pDC)
{
if (m_brBkgr.GetSafeHandle () == NULL && m_hBkgrBitmap == NULL)
{
return FALSE;
} ASSERT_VALID (pDC); CRect rectClient;
m_pWnd->GetClientRect (rectClient); if (m_BkgrLocation != BACKGR_TILE || m_hBkgrBitmap == NULL)
{
if (m_brBkgr.GetSafeHandle () != NULL)
{
pDC->FillRect (rectClient, &m_brBkgr);
}
else
{
return FALSE;
}
} if (m_hBkgrBitmap == NULL)
{
return TRUE;
} ASSERT (m_sizeBkgrBitmap != CSize (0, 0)); if (m_BkgrLocation != BACKGR_TILE)
{
CPoint ptImage = rectClient.TopLeft (); switch (m_BkgrLocation)
{
case BACKGR_TOPLEFT:
break; case BACKGR_TOPRIGHT:
ptImage.x = rectClient.right - m_sizeBkgrBitmap.cx;
break; case BACKGR_BOTTOMLEFT:
ptImage.y = rectClient.bottom - m_sizeBkgrBitmap.cy;
break; case BACKGR_BOTTOMRIGHT:
ptImage.x = rectClient.right - m_sizeBkgrBitmap.cx;
ptImage.y = rectClient.bottom - m_sizeBkgrBitmap.cy;
break;
} pDC->DrawState (ptImage, m_sizeBkgrBitmap, m_hBkgrBitmap, DSS_NORMAL);
}
else
{
// Tile background image:
for (int x = rectClient.left; x < rectClient.Width (); x += m_sizeBkgrBitmap.cx)
{
for (int y = rectClient.top; y < rectClient.Height (); y += m_sizeBkgrBitmap.cy)
{
pDC->DrawState (CPoint (x, y), m_sizeBkgrBitmap, m_hBkgrBitmap, DSS_NORMAL);
}
}
} return TRUE;
}
void CBackgroundManager::HandleOnDestroy()
{
if (m_bAutoDestroyBmp && m_hBkgrBitmap != NULL)
{
::DeleteObject (m_hBkgrBitmap);
m_hBkgrBitmap = NULL;
}
}
cann HandleOnDestroywhen handling WM_DESTROY