Click here to Skip to main content
16,005,552 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: OLBs & TLBs Pin
Christian Graus6-Nov-02 1:05
protectorChristian Graus6-Nov-02 1:05 
GeneralRe: OLBs & TLBs Pin
Stephane Rodriguez.6-Nov-02 1:40
Stephane Rodriguez.6-Nov-02 1:40 
GeneralPeculiar Resouce problem Pin
Anonymous6-Nov-02 0:37
Anonymous6-Nov-02 0:37 
GeneralClear List Box Pin
Ayush5-Nov-02 23:57
Ayush5-Nov-02 23:57 
GeneralRe: Clear List Box Pin
Anonymous6-Nov-02 0:28
Anonymous6-Nov-02 0:28 
GeneralRe: Clear List Box Pin
RuiSantiago6-Nov-02 5:21
RuiSantiago6-Nov-02 5:21 
GeneralProblem with ownerdrawn menus Pin
Chopper5-Nov-02 23:28
Chopper5-Nov-02 23:28 
GeneralRe: Problem with ownerdrawn menus Pin
includeh106-Nov-02 3:15
includeh106-Nov-02 3:15 
easy, only need to use 2 messages:
WM_MEASUREITEM and WM_DRAWITEM.

here is some code copied from my program, as a reference for u:
in WM_MEASUREITEM, call

void BMenuDraw::MeasureItem(int nIDCtl, MEASUREITEMSTRUCT *p)
{
NodeImage*pn=(NodeImage*)p->itemData;
ASSERT(pn!=0);
CString cs=pn->GetText();

HDC hdc=::GetDC(0);
CDC*pDC = CDC::FromHandle(hdc);

CSize size=pDC->GetTextExtent(cs);
p->itemWidth =size.cx+24;
p->itemHeight =22;
::ReleaseDC(0,hdc);
}

in WM_DRAWITEM, call:
void BMenuDraw::DrawItem(int nIDCtl, DRAWITEMSTRUCT *p)
{
CDC*pDC = CDC::FromHandle(p->hDC);
NodeImage*pn=(NodeImage*)p->itemData;

COLORREF clrBk =::GetSysColor(COLOR_MENU);
COLORREF clrTxt =::GetSysColor(COLOR_MENUTEXT);
COLORREF clrBkH =::GetSysColor(COLOR_HIGHLIGHT);
COLORREF clrTxtH =::GetSysColor(COLOR_HIGHLIGHTTEXT);

CString cs;

if(p->itemAction==ODA_DRAWENTIRE)
{
P_DrawItem(pDC,pn,p->rcItem,p->itemState,clrBk,clrTxt);
}

if(p->itemState&ODS_SELECTED)
{
if(p->itemAction&(ODA_SELECT|ODA_DRAWENTIRE))
{
P_DrawItem(pDC,pn,p->rcItem,p->itemState,clrBkH,clrTxtH);
}
}
else
{
if(p->itemAction&ODA_SELECT)
{
P_DrawItem(pDC,pn,p->rcItem,p->itemState,clrBk,clrTxt);
}
}
}

void BMenuDraw::P_DrawItem(CDC *pDC, NodeImage *pn, const CRect &rcItem, int iState, const COLORREF clrBk, const COLORREF clrTxt)
{
BOOL bDis=(iState&ODS_DISABLED)?1Blush | :O ;
BOOL bChk=(iState&ODS_CHECKED)?1Blush | :O ;
BOOL bSel=(iState&ODS_SELECTED)?1Blush | :O ;

BImageHold*pHold=image.GetMenuHolder();
const int iBmpWH=pHold->iBmpWH;

int iBkMode=pDC->SetBkMode(TRANSPARENT);

int iX=rcItem.left+3;
int iY=rcItem.top+2;

CRect rcTxt =rcItem;
rcTxt.left =iX+24;
rcTxt.top +=2;

pDC->FillRect(&rcTxt,&CBrush(clrBk));

CDC dc; dc.CreateCompatibleDC(pDC);
CBitmap*pBmpOld;

if(bDis) pBmpOld=dc.SelectObject(&pHold->bmpD);
else
if(bChk) pBmpOld=dc.SelectObject(&image.bmpS);
else pBmpOld=dc.SelectObject(&pHold->bmpN);

pDC->BitBlt(iX,iY,iBmpWH,iBmpWH,&dc,pn->iPos*iBmpWH,0,SRCCOPY);

CString cs=pn->GetText();

COLORREF clrTxtOld;

if(bDis)
{
BYTE iClr=223;
clrTxtOld=pDC->SetTextColor(RGB(iClr,iClr,iClr));
rcTxt.top++;
rcTxt.left++;
if(!bSel) pDC->DrawText(cs,&rcTxt,DT_EXPANDTABS);

rcTxt.top--;
rcTxt.left--;
COLORREF clrTxtDis=::GetSysColor(COLOR_GRAYTEXT);
pDC->SetTextColor(clrTxtDis);
pDC->DrawText(cs,&rcTxt,DT_EXPANDTABS);
}
else
if(bChk)
{
BYTE iClr=223;
clrTxtOld=pDC->SetTextColor(RGB(iClr,iClr,iClr));
rcTxt.top--;
rcTxt.left--;
if(!bSel) pDC->DrawText(cs,&rcTxt,DT_EXPANDTABS);

rcTxt.top++;
rcTxt.left++;
pDC->SetTextColor(clrTxt);
pDC->DrawText(cs,&rcTxt,DT_EXPANDTABS);
}
else
{
clrTxtOld=pDC->SetTextColor(clrTxt);
pDC->DrawText(cs,&rcTxt,DT_EXPANDTABS);
}

dc.SelectObject(pBmpOld);
pDC->SetBkMode(iBkMode);
pDC->SetTextColor(clrTxtOld);
}


in code above, i used menu image (NodeImage), u just modify it a little, must be well.



includeh10
GeneralPrinting made easy with MFC Pin
Ruca5-Nov-02 22:33
Ruca5-Nov-02 22:33 
GeneralRe: Printing made easy with MFC Pin
Roger Allen6-Nov-02 3:14
Roger Allen6-Nov-02 3:14 
GeneralRe: Printing made easy with MFC Pin
Ruca6-Nov-02 4:25
Ruca6-Nov-02 4:25 
GeneralONMESSAGE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Pin
stevenson5-Nov-02 21:20
stevenson5-Nov-02 21:20 
GeneralRe: ONMESSAGE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Pin
Alexandru Savescu5-Nov-02 22:36
Alexandru Savescu5-Nov-02 22:36 
GeneralRe: ONMESSAGE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Pin
Paul M Watt6-Nov-02 5:10
mentorPaul M Watt6-Nov-02 5:10 
GeneralVoice communication Pin
Saad Sarmad5-Nov-02 21:18
sussSaad Sarmad5-Nov-02 21:18 
GeneralRe: Voice communication Pin
Simon Brown5-Nov-02 22:31
Simon Brown5-Nov-02 22:31 
GeneralRe: Voice communication Pin
Anonymous5-Nov-02 23:24
Anonymous5-Nov-02 23:24 
GeneralRe: Voice communication Pin
benjymous5-Nov-02 23:28
benjymous5-Nov-02 23:28 
Generalerror: #include nesting level is 363 deep Pin
zecodela5-Nov-02 20:38
zecodela5-Nov-02 20:38 
GeneralRe: error: #include nesting level is 363 deep Pin
zecodela5-Nov-02 20:39
zecodela5-Nov-02 20:39 
GeneralRe: error: #include nesting level is 363 deep Pin
Christian Graus5-Nov-02 20:52
protectorChristian Graus5-Nov-02 20:52 
GeneralRe: error: #include nesting level is 363 deep Pin
zecodela5-Nov-02 21:53
zecodela5-Nov-02 21:53 
GeneralRe: error: #include nesting level is 363 deep Pin
benjymous5-Nov-02 23:31
benjymous5-Nov-02 23:31 
GeneralRe: error: #include nesting level is 363 deep Pin
JT Anderson6-Nov-02 10:59
JT Anderson6-Nov-02 10:59 
GeneralRe: error: #include nesting level is 363 deep Pin
Christian Graus6-Nov-02 11:05
protectorChristian Graus6-Nov-02 11:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.