Creating Styles...
-
How would you create and implement styles into your own custom class? Thanks for you replies in advance. -CDuddley
CDuddley wrote: styles Styles ??? Max.
-
How would you create and implement styles into your own custom class? Thanks for you replies in advance. -CDuddley
I'll assume you mean styles like WS_VSCROLL and such...? Umm...well I dunno if windows reserves all 32 bits of the DWORD nStyle paramter, but you could find out pretty easy and use bit locations that weren't used or use a DOWRD StyleEx and set your own bits using bitwise OR's. Like this overloaded version of Create
Create(CWnd* pParent, DWORD nStyle)
{
//Extract the bits your interested in using bitwise AND's
//(i think) and basically do what you want to/with them before
//sending the rest to default Create.
CWnd::Create(nSytle...blah);
}For instance if bit 17 wasn't already used by CreateWindow() you could use it to specifiy SHOW/HIDE 3D borders around custom button control. Cheers! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
-
I'll assume you mean styles like WS_VSCROLL and such...? Umm...well I dunno if windows reserves all 32 bits of the DWORD nStyle paramter, but you could find out pretty easy and use bit locations that weren't used or use a DOWRD StyleEx and set your own bits using bitwise OR's. Like this overloaded version of Create
Create(CWnd* pParent, DWORD nStyle)
{
//Extract the bits your interested in using bitwise AND's
//(i think) and basically do what you want to/with them before
//sending the rest to default Create.
CWnd::Create(nSytle...blah);
}For instance if bit 17 wasn't already used by CreateWindow() you could use it to specifiy SHOW/HIDE 3D borders around custom button control. Cheers! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
How do you handle them I guess is what I was wondering. Say you have an enumeration. enum { ID_STYLE1 = 0, ID_STYLE2 = 1, ID_STYLE3 = 2 }; How do you handle the those styles in a function with the bitwize OR and AND ops? Thanks for the inputs in advance. -CDuddley
-
How do you handle them I guess is what I was wondering. Say you have an enumeration. enum { ID_STYLE1 = 0, ID_STYLE2 = 1, ID_STYLE3 = 2 }; How do you handle the those styles in a function with the bitwize OR and AND ops? Thanks for the inputs in advance. -CDuddley
Hope this is what you are after. Serge class MyClass { public: enum Style { Style1 = 1 << 0, // bit 0 Style2 = 1 << 1, // bit 1 Style3 = 1 << 2, // bit 2 // so on }; MyClass() : m_styles(0) {} void SetStyle(Style style) {m_styles |= style;} void ClearStyle(Style style) {m_styles &= ~style;} void Dump() {printf("Style = 0x%08X\n", m_styles);} private: unsigned int m_styles; }; void main() { MyClass mc; mc.SetStyle(MyClass::Style1); mc.Dump(); mc.SetStyle(MyClass::Style2); mc.Dump(); mc.SetStyle(MyClass::Style3); mc.Dump(); mc.ClearStyle(MyClass::Style3); mc.Dump(); mc.ClearStyle(MyClass::Style2); mc.Dump(); mc.ClearStyle(MyClass::Style1); mc.Dump(); }
-
How do you handle them I guess is what I was wondering. Say you have an enumeration. enum { ID_STYLE1 = 0, ID_STYLE2 = 1, ID_STYLE3 = 2 }; How do you handle the those styles in a function with the bitwize OR and AND ops? Thanks for the inputs in advance. -CDuddley
#define CWS_3DBORDER 0x01 //First bit of DWORD style is now used by child window style (CWS)
//Create custom control window with custom style
m_wndChild.Create(this, WS_CHILD | WS_VISIBLE | CWS_3DBORDER);//Custom control overloaded Create function
CCustom::Create(CWnd* pParent, DWORD nStyle)
{
m_b3DBorder = nStyle & MASK;
}//CCustom control OnPaint handler
CCustom::OnPaint()
{
CPaintDC dc(this);
if(m_b3DBorder)
//Draw 3d border cuz it was specified in style flag//Continue with normal drawing code
}
You may have to give the and operation the once over I dunno how accurate my attempt at masking bits is in the above...but you should figure it out easily. I did try and give a solid example of how I would use custom flags. Cheers! "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr