解决方案 »
- 问一下png为底图的对话框//上面再加载一个对话框,怎么不行呢?
- 取得ping的时间问题,请网络高手看看
- 请教固定CSilderCtrl控件的位置和大小问题。
- 菜鸟提问一个关于时间定时执行的小程序××××××××××××××××××××××××××
- 自定义打印机纸张
- 通信应用出错了,高手来看看?
- 哪位大侠能帮助我啊,shapefile文件的结构是什么啊,怎么实现他的读取和显示?
- 用文件监视器看程序的文件读写,发现很多每次读操作都读4096字节,这样速度快吗?
- 救助win7下cpu占有率计算
- 有谁用过 核心编程 里面的 22章APIHOOK里的源代码? 2003下有问题。都来进来讨论讨论
- 如何获得日历控件上选择的日期?
- 【求助】读取INI文件,相对路径和绝对路径问题
UINT CtlType;
UINT itemID;
UINT itemAction;
ULONG_PTR itemData;这几个如何得到
主窗口 有个 m_pListBox
主窗口 OnPaintfor (int jj=0;jj< 20;jj)
{
DRAWITEMSTRUCT ds;
ds.CtlType=ODT_LISTBOX;
ds.CtlID=m_pListBox->GetDlgCtrlID();
ds.ItemID=jj;// current idx
ds.itemAction=ODA_DRAWENTIRE;
ds.hwndItem=m_pListBox->GetSafeHwnd();
ds.hDC= dc.GetSafeHdc();
ds.rcItem=CRect(0,0,60,20);// GetItemRect(jj);
ds.itemData=m_pListBox->GetItemData(jj);
ds.itemState=m_pListBox->GetSel(jj)>0?ODS_SELECTED:0);
//ds.itemState |= ODS_FOCUS;
m_pListBox->DrawItem(&ds)
}手打的 !
谢谢,我今天就是这么搞的,但是遇到个问题如下:
HWND childwnd = ::GetWindow(m_hWnd, GW_CHILD);
UINT ctlid;
int width,height;
ClientToScreen(&rcClient);
while(childwnd != NULL)
{
DRAWITEMSTRUCT ds;
ds.CtlType=ODT_LISTBOX;
ds.CtlID=m_pListBox->GetDlgCtrlID();//填充结构体
..................
CButton::DrawItem(&ds)//调用绘制
childwnd = ::GetWindow(childwnd, GW_HWNDNEXT);
}
while会出现已经出现过得childwnd ;
这两个消息或者说绘制途径是相互独立的
在OnPaint中完全可以获取到所有控件的信息完成相应绘制
然后 调用 m_pListBox->DrawItem(&ds) ; 让listbox把 当前 项 text 绘制到 tip 上. 上面9 楼是代码 片断.
{
ASSERT(m_nItemIndex != m_nNoIndex); CPaintDC DC(this); int nSavedDC = DC.SaveDC(); CRect ClientRect;
GetClientRect(ClientRect); if (IsListBoxOwnerDraw())
{
// Let the listbox do the real drawing.
DRAWITEMSTRUCT DrawItemStruct; DrawItemStruct.CtlType = ODT_LISTBOX;
DrawItemStruct.CtlID = m_pListBox->GetDlgCtrlID();
DrawItemStruct.itemID = m_nItemIndex;
DrawItemStruct.itemAction = ODA_DRAWENTIRE;
DrawItemStruct.hwndItem = m_pListBox->GetSafeHwnd();
DrawItemStruct.hDC = DC.GetSafeHdc();
DrawItemStruct.rcItem = ClientRect;
DrawItemStruct.itemData = m_pListBox->GetItemData(m_nItemIndex);
DrawItemStruct.itemState = (m_pListBox->GetSel(m_nItemIndex) > 0 ?
ODS_SELECTED : 0);
if (m_pListBox->GetStyle() & LBS_MULTIPLESEL)
{
if (m_pListBox->GetCaretIndex() == m_nItemIndex)
{
DrawItemStruct.itemState |= ODS_FOCUS;
}
}
else
{
DrawItemStruct.itemState |= ODS_FOCUS;
} m_pListBox->DrawItem(&DrawItemStruct);
}
else
{
// Do all of the drawing ourselves
........
让控件 把 它的 图 画在 YourMemDC, 上. (Onpaint 不能指定DC)
对 TreeCtrl, ListCtrl 这个方法行得通, 对你的控件只能试试.
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// get size
CRect rc;
GetClientRect(&rc);
// Create a compatible memory DC
CDC memDC;
memDC.CreateCompatibleDC(&dc);
// Select a compatible bitmap into the memory DC
CBitmap bitmap;
bitmap.CreateCompatibleBitmap( &dc, rc.Width(), rc.Height());
HBITMAP oldBmp=(HBITMAP)memDC.SelectObject(&bitmap);
// fill the region not occupied
memDC.FillRect(&rc,CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
// Let the control draws the list.
// CHeaderCtrl *pHead=GetHeaderCtrl();
// pHead->SendMessage(WM_PAINT, (WPARAM)memDC.m_hDC, 0 );// on screen ?
// ::DefWindowProc(pHead->m_hWnd, WM_PAINT, (WPARAM)memDC.m_hDC, 0 );// not ?
DefWindowProc(WM_PAINT, (WPARAM)memDC.m_hDC, 0 );
// copy to CB for checking
#ifndef TEST
memDC.SelectObject(oldBmp);
OpenClipboard();
EmptyClipboard();
SetClipboardData(CF_BITMAP,bitmap);
CloseClipboard();
oldBmp=(HBITMAP)memDC.SelectObject(&bitmap);
#endif
// 'and' to the background
dc.BitBlt(0, 0, rc.Width(), rc.Height(),&memDC,0 ,0 ,SRCAND);
// set back
memDC.SelectObject(oldBmp);
// free
DeleteObject(bitmap.m_hObject);
DeleteObject(memDC);
// Do not call CListCtrl::OnPaint() for painting messages
}