|
Hi,
In my SDI application I override menus to be ownerdrawn, and then draw them using OnDrawItem(...) of the main frame. However, i have this little problem: I click on the main menu, then a pop-up appears, I select a pop-up menu item, it displays a pop-up of next level. This second level menu partly overlaps the first one, and when it disappears the first menu doesn't get updated (part of the menu item which is selected has an unupdated trace on it). This doesn't happen with not ownerdrawn menu items.
Does anybody know what else should I do to provide all menu items get updated when necessary
Regards,
Vitaly
|
|
|
|
|
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)?1 ;
BOOL bChk=(iState&ODS_CHECKED)?1 ;
BOOL bSel=(iState&ODS_SELECTED)?1 ;
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
|
|
|
|
|
hi everyone,
I read the article "Printing Made Easy with MFC" and am using the GPrintUnit and GPrintJob classes.
I would like to know how to redefine the Rect for printing, or more specifically how to introduce a margin so that my printing does not start on the edge of the page.
Thanks in advance
Regards
Rui
|
|
|
|
|
|
Thanks for the article, it does explain quite a bit on printing.
But I was wondering more about where to set the JRECT defined in the classes GPrintUnit and GPrintJob?
Although I am going to try to override the GPrintInfo function and set the JRECT there. I am not sure if this is correct.
Thanks
Rui
|
|
|
|
|
hi,
I defined a message in *.exe. And in *.dll, I trigered the message, nothing happened. tell me why.
Note, this message works well in *.exe
Thanks in advance
Extreme programming. Do the No.1
|
|
|
|
|
Did you add a command handler for that message?
Best regards,
Alexandru Savescu
|
|
|
|
|
Are you sending the message to the correct window?
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Is there any application written in VC++, regarding voice communication, you aware of; then please let me know.
There is one here at CP, but it gives lot of echoes and code not of good quality. If there any other present somewhere like MSDN or M$ research site, you aware of then please let me know.
BTW: i've already searched google but it is giving results that are either Unix related or difficult to compile in VC++
|
|
|
|
|
If you want to add Text-To-Speech then get the SDK from Microsoft, there are many examples in C++ which work well.
Old Simon HB9DRV
|
|
|
|
|
No, I don't want anything like text-to-speech. What i want is to transfer voice over lan/internet in peer-to-peer or client/server manner
|
|
|
|
|
There is example voice chat software in the DirectX SDK
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
hi all,
i found this error when i include 2 header files in each other's header file. i do this since i need to call each other's functions with pointer to link to these objects.
class A
{
public:
...
..
private:
B *b;
};
class B
{
public:
...
..
private:
B *b;
};
how can i solve this problem?
thanks!!!
chaze
|
|
|
|
|
the class declaration should like this!
class A
{
public:
...
..
private:
B *b;
};
class B
{
public:
...
..
private:
A *a;
};
|
|
|
|
|
Well, you include A, it includes B, it includes A, it includes B....
This sort of stuff messes with your build times as well. Do this:
a.h:
class b{};
class a
{
...
a.cpp:
#include "stdafx.h" // always at the top
@include "b.h"
and vice versa. You're telling the compiler that b is a class, it can worry about the rest later - this works because all you're storing is a pointer, it does not need to know any details about it until it gets to the implimentation ( the .cpp file)
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
hi,
your solution seems don't work... the compiler complain that redefine a class...
anything wrong with me?
|
|
|
|
|
don't include a.h from b.h (and vice versa)
--
Help me! I'm turning into a grapefruit!
|
|
|
|
|
Close. That should be:
class b;
Not:
class b{};
The curly braces are the cause of the "Redefinition" errors.
--------
There are 10 types of people in this world. Those who know binary and those who don't.
|
|
|
|
|
Thanks - that's what I get for answering off the top of my head when I am tired.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
|
I done this before with the forward-declaration as decriped in other answers.
But after a while I most found that this is a lack of the programming & class architecture.
In all my cases I have changed it somehow to no "back referencing".
possible solution:
a) inheritence
b) merge the classes
c) Make a member
You earn visibility and avoid bugs.
|
|
|
|
|
hi,
first, i don't understand "forward-declaration"...
yes, i think inheritance would be useful!
let me try!
thanks,
chaze
|
|
|
|
|
I have a Dialog App with and it has a list control in it. I want to handle wm_vscroll in the CMyDlg class though, not in a class derived from CTreeCtrl. Everything I've tried doesn't seem to work. How can I do this?
There's always one more bug.
|
|
|
|
|
hi,
can someone please help me with some c++ problems?
i've created a vc++ project using visual studio .net.. my application is a sdi and is using the windows explorer style(left side using treeview and right side using listview).. i've populated my trees in the treeview already, but i don't know how to add/associate control id with event handler functions.. the visual studio .net wizard wasn't very user friendly and i can't seem to find the command in the wizard which allows me to add/associate event handler with control id.. any help is welcome.. thanx in advance.
|
|
|
|
|
Here is the code that I am working with;
void balance(float pmt)
{
float bal_k;
int k=1;
float pay;
float i=9/12;
const int n=36;
pay=pmt;
bal_k=pay*(1-((1+i)^(k-n))/i)
}
When I compile, the compiler says that because the left hand operator of the "bal_k" expression is of type float that it is illegal. I tried forcing the expression "i" to type int but it becomes zero and then there is a divide by zero error. How can I get around this?
|
|
|
|
|