Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Creating Styles...

Creating Styles...

Scheduled Pinned Locked Moved C / C++ / MFC
wpfquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CDuddley
    wrote on last edited by
    #1

    How would you create and implement styles into your own custom class? Thanks for you replies in advance. -CDuddley

    M A 2 Replies Last reply
    0
    • C CDuddley

      How would you create and implement styles into your own custom class? Thanks for you replies in advance. -CDuddley

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      CDuddley wrote: styles Styles ??? Max.

      1 Reply Last reply
      0
      • C CDuddley

        How would you create and implement styles into your own custom class? Thanks for you replies in advance. -CDuddley

        A Offline
        A Offline
        alex barylski
        wrote on last edited by
        #3

        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

        C 1 Reply Last reply
        0
        • A alex barylski

          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

          C Offline
          C Offline
          CDuddley
          wrote on last edited by
          #4

          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

          S A 2 Replies Last reply
          0
          • C 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

            S Offline
            S Offline
            Serge Krynine
            wrote on last edited by
            #5

            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(); }

            1 Reply Last reply
            0
            • C 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

              A Offline
              A Offline
              alex barylski
              wrote on last edited by
              #6

              #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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups