|
Please help. I try to integrate CHoverButton into my project. I follow all the steps and set the button to OWNER_DRAW. However, the button will not show up. Any idea? Thanks.
|
|
|
|
|
Thank you for this nice control!
Here is a minor improvement. To make bitmap transparent, set bitmap bits that should be transparent to RGB(255,0,255). Then change the DrawItem() function as follows:
void CHoverButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC *mydc = CDC::FromHandle(lpDrawItemStruct->hDC);
CDC * pMemDC = new CDC;
pMemDC->CreateCompatibleDC(mydc);
CBitmap * pOldBitmap = pMemDC->SelectObject(&mybitmap);
CPoint point(0, 0);
COLORREF rgbButtonFace = ::GetSysColor(COLOR_BTNFACE);
for (int x = 0; x < m_ButtonSize.cx*3; x++)
{
for (int y = 0; y < m_ButtonSize.cy; y++)
{
COLORREF rgb = pMemDC->GetPixel(x, y);
if (rgb == RGB(255,0,255))
pMemDC->SetPixel(x, y, rgbButtonFace);
}
}
if (lpDrawItemStruct->itemState & ODS_SELECTED)
.
.
.
|
|
|
|
|
I agree with Hans: thank you Niek for this nice control.
I have a minor update to Hans' minor update:
Use the topleft corner of the bitmap as the tranparent color:
void CHoverButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC *mydc=CDC::FromHandle(lpDrawItemStruct->hDC);
CDC * pMemDC = new CDC;
pMemDC -> CreateCompatibleDC(mydc);
CBitmap * pOldBitmap;
pOldBitmap = pMemDC -> SelectObject(&mybitmap);
COLORREF rgbButtonFace = ::GetSysColor(COLOR_BTNFACE);
COLORREF transparentcolor = pMemDC->GetPixel(0, 0);
for (int x = 0; x < m_ButtonSize.cx*3; x++)
{
for (int y = 0; y < m_ButtonSize.cy; y++)
{
COLORREF rgb = pMemDC->GetPixel(x, y);
if (rgb == transparentcolor)
{
pMemDC->SetPixel(x, y, rgbButtonFace);
}
}
}
if(lpDrawItemStruct->itemState & ODS_SELECTED)
Regards Anne Jan Beeks
|
|
|
|
|
I am not too familiar with the whole transparent thing, but wouldn’t a real transparent control replace the colour with the background colour?
Something like
...
//
// extern COLORREF m_rgbTrans, given by user.
//
COLORREF rgb = pMemDC->GetPixel(x, y);
// transparent color = magenta
if (rgb == m_rgbTrans )
pMemDC->SetPixel(x, y, mydc->GetPixel(x,y));
...
Sims
|
|
|
|
|
I agree with everyone that this is a nice control.
I also have a minor update to everyone's minor update.
The new code is a little slow and because it is performed everytime the image is updated, I noticed there's some flicker. Why not change the "transparent" colour only once when we first load the bitmap? I suggest changing LoadBitmap instead of DrawItem:
BOOL CHoverButton::LoadBitmap(UINT bitmapid)<br />
{<br />
mybitmap.Attach(::LoadImage(::AfxGetInstanceHandle(),MAKEINTRESOURCE(bitmapid), IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS));<br />
BITMAP bitmapbits;<br />
mybitmap.GetBitmap(&bitmapbits);<br />
m_ButtonSize.cy=bitmapbits.bmHeight;<br />
m_ButtonSize.cx=bitmapbits.bmWidth/3;<br />
<br />
CDC cdcBitmap;<br />
COLORREF rgbButtonFace = ::GetSysColor(COLOR_BTNFACE);<br />
COLORREF rgbTransparentColor;<br />
COLORREF rgbPixel;<br />
<br />
cdcBitmap.CreateCompatibleDC(NULL);<br />
cdcBitmap.SelectObject(mybitmap);<br />
rgbTransparentColor = cdcBitmap.GetPixel(0, 0);<br />
for (int x = 0; x < bitmapbits.bmWidth; x++)<br />
{<br />
for (int y = 0; y < bitmapbits.bmHeight; y++)<br />
{<br />
rgbPixel = cdcBitmap.GetPixel(x, y);<br />
if (rgbPixel == rgbTransparentColor)<br />
{<br />
cdcBitmap.SetPixel(x, y, rgbButtonFace);<br />
}<br />
}<br />
}<br />
cdcBitmap.DeleteDC();<br />
<br />
SetWindowPos( NULL, 0,0, m_ButtonSize.cx,m_ButtonSize.cy,SWP_NOMOVE |SWP_NOOWNERZORDER );<br />
return TRUE;<br />
}
Stephen.
|
|
|
|
|
Hi all
I am drawing bitmap image on a button and now want to make this buttan as hyperlink.
Is there any way in MFC to make buttons as hyperlink
Thanks
With Regards
Sunil Joshi
|
|
|
|
|
Thank you for the nice work!! But the button shape is rectangle, I added some new features to the class, now the button's shape is relatived to the bitmap.how can I upload my class?
|
|
|
|
|
When i try to compile your example i get following error message:
d:\[ Projects ]\MFC_incoming\hover_button\HoverButton.cpp(32): error C2440: 'static_cast': 'void (__thiscall CHoverButton::* )(WPARAM,LPARAM)' kann nicht in 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)' konvertiert werden
I´m a newbie in c++.
It would be nice if someone could help.
|
|
|
|
|
It has very simple solution about this problem.
Try as follows :
In HoverButton.h...
protected:
CToolTipCtrl m_ToolTip;
void InitToolTip();
//{{AFX_MSG(CHoverButton)
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg LRESULT OnMouseLeave(WPARAM wparam, LPARAM lparam);
afx_msg LRESULT OnMouseHover(WPARAM wparam, LPARAM lparam) ;
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
And in HoverButton.cpp
LRESULT CHoverButton::OnMouseHover(WPARAM wparam, LPARAM lparam)
{
// TODO: Add your message handler code here and/or call default
m_bHover=TRUE;
Invalidate();
return 0;
}
LRESULT CHoverButton::OnMouseLeave(WPARAM wparam, LPARAM lparam)
{
m_bTracking = FALSE;
m_bHover=FALSE;
Invalidate();
return 0;
}
H.J.Jo in Seoul, South Korea.
|
|
|
|
|
I tried this in .NET and get these errors:
warning C4996: 'CWinApp::Enable3dControls' was declared deprecated
error C2556: 'LRESULT CHoverButton::OnMouseHover(WPARAM,LPARAM)' : overloaded function differs only by return type from 'void CHoverButton::OnMouseHover(WPARAM,LPARAM)'
error C2371: 'CHoverButton::OnMouseHover' : redefinition; different basic types
|
|
|
|
|
All older App Wizard generated projects include the CWinApp::Enable3dControls() call to well, enable 3d controls. However with the latest version of .net and VC++'s associated libraries this appears to be unnecessary and so use of this function genrates a warning, although in truth I presume there is no harm in it's inclusion. As such, however, all projects containing the call that are migrated to .net (2003 at least) will produce this warning.
Other than that, it appears that .net 2003 is more rigorous with it's ON_MESSAGE() macro and consequently the return type for the CHoverButton::OnMouseHover() should be an LRESULT and not a void. Changing this fixes the problems and it compiles without any trouble. The above issues are issues to do with migration of the project/code to .net.
As already stated the slight flicker on the control can be avoided by handling WM_ERASEBKGND message, although you may still get a little "tearing", more noticeable on much larger buttons I imagine.
To eliminate all such artifcats, the only real way to handle it is ti blit the image to the screen during the vertical blank. This is problemtic at best and so handling the WM_ERASEBKGND is the cheaper and more acceptable solution.
Generally speaking, painting each pixel only once will provide the least flicker!
IMH
|
|
|
|
|
In side of this project I can call this function.
But When I try to use in side of my own project
I have an error saying this function is not
defined. Is there any library or .h file
I have to include in order to get it running?
Let me know and thanks for your help in advance.
Shinya
|
|
|
|
|
perhaps you try using TrackMouseEvent instead of _TrackMouseEvent (not the underscore).
|
|
|
|
|
perhaps you try using TrackMouseEvent instead of _TrackMouseEvent (note the underscore).
|
|
|
|
|
If you call LoadImage only once during their life,then it works Ok.
But if you attemp to change the bitmap, an assert warning accured during executing the debug version.Even
though not happened in release version,but probaly it will cause memory leaks.
So,it should release the bitmap's attached object.do like this:
insert the below line as the first line of the LoadImage method:
mybitmap.Detach()
insert the below line as the last line before return statement:
Invalidate();
so the complete code is:
BOOL CHoverButton::LoadBitmap(UINT bitmapid)
{
mybitmap.Detach();
mybitmap.Attach(::LoadImage(::AfxGetInstanceHandle(),MAKEINTRESOURCE(bitmapid), IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS));
BITMAP bitmapbits;
mybitmap.GetBitmap(&bitmapbits);
m_ButtonSize.cy=bitmapbits.bmHeight;
m_ButtonSize.cx=bitmapbits.bmWidth/3;
SetWindowPos( NULL, 0,0, m_ButtonSize.cx,m_ButtonSize.cy,SWP_NOMOVE |SWP_NOOWNERZORDER );
Invalidate();
return TRUE;
}
Thanks for you Hoverbutton,help me much!
|
|
|
|
|
I tried mybitmap.Detach() but there still seem to be a memory leak.
However after I tried mybitmap.DeleteObject(); instead the memory leak seem to dissapear.
|
|
|
|
|
I got a problem. the hoverbutton will not show up at the begining. only after i move my mouse over it, it will apear. help plz....
|
|
|
|
|
If you are trying to place the CHoverButton over a CEdit for example you might want to try making sure the CHoverButton is on top of the CEdit in the Z-order. Like so:
SetWindowPos(insertAfter, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
Where 'insertAfter' is the CWnd* to the edit control.
|
|
|
|
|
|
I just learn something new today !
Max.
|
|
|
|
|
I've a problem whit the tooltip.
I have a bitmap (on) the button.
If I've clicked on the button the tooltip for that button won't come back.
If I restart the app. the tooltip works again (UNTILL) i've clicked on that button.
What did i wrong?
|
|
|
|
|
Hello guys ! I've got a problem.
I've made a hover button in Frontpage 2002, I have a page with 2 frames in it.
Now, when I click on the hover button I want the 2 frames changed.
On one frame there is my hover button and on the other is my homepage, when I click on the hover button I want to link the 2 frames to another url.
How do I do this in Frontpage 2002 ? I've been searching a long time for this
can somebody help me ?
Thx in advance !!!
|
|
|
|
|
Why did you use Frontpage?
I think Photoshop is better
|
|
|
|
|
i'm sory to u.. i dont know about hover button bcz tis i need ur help to my assignment like tis the question...
You are experiencing problems with getting Front Page 98’s hover buttons to function. You are supposed to solve this problem in a very short time. Think about the possible ways that you can do to solve this problem very quickly.
Applet codes of your web page is as follow:
<applet code="fphover.class" codebase="./" width="120" height="24">
<param name="color" value="#000080" />
<param name="hovercolor" value="#0000FF" />
<param name="textcolor" value="#FFFFFF" />
<param name="text" value="C Programming" />
<param name="effect" value="glow" />
<param name="url" valuetype="ref" value="http://metalab.uniten.edu.my/~azhana/indexCProg.html" />
plz reply for me arianis_act86@yahoo.com
nothing
|
|
|
|
|
dear sir,
i want to change the background
and foreground color of the
button .please help me in this
regard.
kashif1012000@yahoo.com
|
|
|
|