Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
Hi all
i want to create a round button in my apps-MFC ActiveX Control
in the function ONCREATE of project
i have created a variable _button as CButton
and i use API Create():
_button.Create(_T("button view",WS_VISIABLE,CRect(15,15,20,10), this,1);
after, in the function OnDraw
 
_button.MoveWindow(rcBounds,TRUE);
pdc->FillRect(rcBounds,#color);
pdc->Ellipse(20,20,50,50);
 
however, button is show not a round button
can help me
thank so much
Posted 17-Apr-13 17:03pm
Comments
Sergey Alexandrovich Kryukov at 17-Apr-13 22:28pm
   
This is an interesting question! But you are trying to do something with graphics, which won't give you "really" non-rectangle window. There is an "absolute" method of doing it.
Please see my answer.
I voted 4 for the question.
—SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

All the magic is done via one important Windows API function SetWindowRgn:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd145102%28v=vs.85%29.aspx[^].
 
You create a non-rectangular region and call this function on some HWND when a handle of some window is already created. This make "real" non-rectangular window, not only visually, but observable via mouse hits. Don't mix it up with tricks performed on DC clip regions: they only give some visual effect, but the actual window, by a mouse hit test, is still rectangular.
 
I found a short manual, just to see what's involved: http://www.codeguru.com/cpp/w-d/dislog/non-rectangulardialogs/article.php/c5037/Creating-Shaped-Windows-Using-Regions-with-Win32.htm[^].
 
There is no a problem to do it with MFC, which is tightly coupled with raw Windows API and based on it. Anyway, HWND window handle for controls is always accessible.
 
—SA
  Permalink  
Comments
dev C plus at 17-Apr-13 22:43pm
   
thanks a lot
so, i have know it.
i have created a object CDC
and object CRect to create a rectangular
after, i use object CDC to create ellipse (in API Create of class CButton)
but, when compile to Vb.net application thi not used
-------
CDC* pdc;
pdc->Attach(::GETDC(0));
CRect rect(15,15,20,15);
pdc->Ellipse(&rect);
_button.Create(_T("button view",WS_VISIABLE,rect, this,1);
-------
Sergey Alexandrovich Kryukov at 18-Apr-13 0:21am
   
Why CDC, etc.? You create a region and call the SetWindowRgn, that's it. CDC is the wrapper around device context. This is unrelated thing.
 
For an ellipse use Window API CreateEllipticRgn. And so on...
 
Look, you have everything you need, don't get distracted with unrelated aspects.
Did you got it now? If yes, don't forget to accept the answer formally (green button).
—SA
nv3 at 18-Apr-13 3:07am
   
My 5.
Sergey Alexandrovich Kryukov at 18-Apr-13 9:42am
   
Thank you.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 17 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100