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. [MFC]no subclass, no derivation, just redirect one function of CButton, is it possible?

[MFC]no subclass, no derivation, just redirect one function of CButton, is it possible?

Scheduled Pinned Locked Moved C / C++ / MFC
c++jsonquestion
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.
  • F Offline
    F Offline
    Falconapollo
    wrote on last edited by
    #1

    As shown below, there are a few functions in CButton, but i want to change its behaviour by dealing with

    virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)

    . Yes, just this one and only one functon. It would generate more code than expected if I derive a class from CButton. I wonder if it possible to process this function without Subclass, and not use derivation. If so, how? Remarks: I must use MFC, it's so hard to use pure Win32 API.

    class CButton : public CWnd
    {
    DECLARE_DYNAMIC(CButton)

    // Constructors
    public:
    CButton();
    virtual BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle,
    const RECT& rect, CWnd* pParentWnd, UINT nID);

    // Attributes
    UINT GetState() const;
    void SetState(BOOL bHighlight);
    int GetCheck() const;
    void SetCheck(int nCheck);
    UINT GetButtonStyle() const;
    void SetButtonStyle(UINT nStyle, BOOL bRedraw = TRUE);

    HICON SetIcon(HICON hIcon);
    HICON GetIcon() const;
    HBITMAP SetBitmap(HBITMAP hBitmap);
    HBITMAP GetBitmap() const;
    HCURSOR SetCursor(HCURSOR hCursor);
    HCURSOR GetCursor();
    

    #if (_WIN32_WINNT >= 0x501)
    AFX_ANSI_DEPRECATED BOOL GetIdealSize(_Out_ LPSIZE psize) const;
    AFX_ANSI_DEPRECATED BOOL SetImageList(_In_ PBUTTON_IMAGELIST pbuttonImagelist);
    AFX_ANSI_DEPRECATED BOOL GetImageList(_In_ PBUTTON_IMAGELIST pbuttonImagelist) const;
    AFX_ANSI_DEPRECATED BOOL SetTextMargin(_In_ LPRECT pmargin);
    AFX_ANSI_DEPRECATED BOOL GetTextMargin(_Out_ LPRECT pmargin) const;
    #endif // (_WIN32_WINNT >= 0x501)

    #if ( _WIN32_WINNT >= 0x0600 ) && defined(UNICODE)
    CString GetNote() const;
    _Check_return_ BOOL GetNote(_Out_z_cap_(*pcchNote) LPTSTR lpszNote, _Inout_ UINT* pcchNote) const;
    BOOL SetNote(_In_z_ LPCTSTR lpszNote);
    UINT GetNoteLength() const;
    BOOL GetSplitInfo(_Out_ PBUTTON_SPLITINFO pInfo) const;
    BOOL SetSplitInfo(_In_ PBUTTON_SPLITINFO pInfo);
    UINT GetSplitStyle() const;
    BOOL SetSplitStyle(_In_ UINT nStyle);
    BOOL GetSplitSize(_Out_ LPSIZE pSize) const;
    BOOL SetSplitSize(_In_ LPSIZE pSize);
    CImageList* GetSplitImageList() const;
    BOOL SetSplitImageList(_In_ CImageList* pSplitImageList);
    TCHAR GetSplitGlyph() const;
    BOOL SetSplitGlyph(_In_ TCHAR chGlyph);
    BOOL SetDropDownState(_In_ BOOL fDropDown);

    // Sets whether the action associated with the button requires elevated permissions.
    // If elevated permissions are required then the button should display
    
    L CPalliniC _ 3 Replies Last reply
    0
    • F Falconapollo

      As shown below, there are a few functions in CButton, but i want to change its behaviour by dealing with

      virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)

      . Yes, just this one and only one functon. It would generate more code than expected if I derive a class from CButton. I wonder if it possible to process this function without Subclass, and not use derivation. If so, how? Remarks: I must use MFC, it's so hard to use pure Win32 API.

      class CButton : public CWnd
      {
      DECLARE_DYNAMIC(CButton)

      // Constructors
      public:
      CButton();
      virtual BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle,
      const RECT& rect, CWnd* pParentWnd, UINT nID);

      // Attributes
      UINT GetState() const;
      void SetState(BOOL bHighlight);
      int GetCheck() const;
      void SetCheck(int nCheck);
      UINT GetButtonStyle() const;
      void SetButtonStyle(UINT nStyle, BOOL bRedraw = TRUE);

      HICON SetIcon(HICON hIcon);
      HICON GetIcon() const;
      HBITMAP SetBitmap(HBITMAP hBitmap);
      HBITMAP GetBitmap() const;
      HCURSOR SetCursor(HCURSOR hCursor);
      HCURSOR GetCursor();
      

      #if (_WIN32_WINNT >= 0x501)
      AFX_ANSI_DEPRECATED BOOL GetIdealSize(_Out_ LPSIZE psize) const;
      AFX_ANSI_DEPRECATED BOOL SetImageList(_In_ PBUTTON_IMAGELIST pbuttonImagelist);
      AFX_ANSI_DEPRECATED BOOL GetImageList(_In_ PBUTTON_IMAGELIST pbuttonImagelist) const;
      AFX_ANSI_DEPRECATED BOOL SetTextMargin(_In_ LPRECT pmargin);
      AFX_ANSI_DEPRECATED BOOL GetTextMargin(_Out_ LPRECT pmargin) const;
      #endif // (_WIN32_WINNT >= 0x501)

      #if ( _WIN32_WINNT >= 0x0600 ) && defined(UNICODE)
      CString GetNote() const;
      _Check_return_ BOOL GetNote(_Out_z_cap_(*pcchNote) LPTSTR lpszNote, _Inout_ UINT* pcchNote) const;
      BOOL SetNote(_In_z_ LPCTSTR lpszNote);
      UINT GetNoteLength() const;
      BOOL GetSplitInfo(_Out_ PBUTTON_SPLITINFO pInfo) const;
      BOOL SetSplitInfo(_In_ PBUTTON_SPLITINFO pInfo);
      UINT GetSplitStyle() const;
      BOOL SetSplitStyle(_In_ UINT nStyle);
      BOOL GetSplitSize(_Out_ LPSIZE pSize) const;
      BOOL SetSplitSize(_In_ LPSIZE pSize);
      CImageList* GetSplitImageList() const;
      BOOL SetSplitImageList(_In_ CImageList* pSplitImageList);
      TCHAR GetSplitGlyph() const;
      BOOL SetSplitGlyph(_In_ TCHAR chGlyph);
      BOOL SetDropDownState(_In_ BOOL fDropDown);

      // Sets whether the action associated with the button requires elevated permissions.
      // If elevated permissions are required then the button should display
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I'm not sure I understand exactly what you want to do, but I do not think there is any way to override a single method unless you derive your own class from CButton. The documentation at http://msdn.microsoft.com/en-us/library/y0k9f0a4.aspx[^] shows an example.

      F 1 Reply Last reply
      0
      • L Lost User

        I'm not sure I understand exactly what you want to do, but I do not think there is any way to override a single method unless you derive your own class from CButton. The documentation at http://msdn.microsoft.com/en-us/library/y0k9f0a4.aspx[^] shows an example.

        F Offline
        F Offline
        Falconapollo
        wrote on last edited by
        #3

        then, how about Hook?

        L 1 Reply Last reply
        0
        • F Falconapollo

          As shown below, there are a few functions in CButton, but i want to change its behaviour by dealing with

          virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)

          . Yes, just this one and only one functon. It would generate more code than expected if I derive a class from CButton. I wonder if it possible to process this function without Subclass, and not use derivation. If so, how? Remarks: I must use MFC, it's so hard to use pure Win32 API.

          class CButton : public CWnd
          {
          DECLARE_DYNAMIC(CButton)

          // Constructors
          public:
          CButton();
          virtual BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle,
          const RECT& rect, CWnd* pParentWnd, UINT nID);

          // Attributes
          UINT GetState() const;
          void SetState(BOOL bHighlight);
          int GetCheck() const;
          void SetCheck(int nCheck);
          UINT GetButtonStyle() const;
          void SetButtonStyle(UINT nStyle, BOOL bRedraw = TRUE);

          HICON SetIcon(HICON hIcon);
          HICON GetIcon() const;
          HBITMAP SetBitmap(HBITMAP hBitmap);
          HBITMAP GetBitmap() const;
          HCURSOR SetCursor(HCURSOR hCursor);
          HCURSOR GetCursor();
          

          #if (_WIN32_WINNT >= 0x501)
          AFX_ANSI_DEPRECATED BOOL GetIdealSize(_Out_ LPSIZE psize) const;
          AFX_ANSI_DEPRECATED BOOL SetImageList(_In_ PBUTTON_IMAGELIST pbuttonImagelist);
          AFX_ANSI_DEPRECATED BOOL GetImageList(_In_ PBUTTON_IMAGELIST pbuttonImagelist) const;
          AFX_ANSI_DEPRECATED BOOL SetTextMargin(_In_ LPRECT pmargin);
          AFX_ANSI_DEPRECATED BOOL GetTextMargin(_Out_ LPRECT pmargin) const;
          #endif // (_WIN32_WINNT >= 0x501)

          #if ( _WIN32_WINNT >= 0x0600 ) && defined(UNICODE)
          CString GetNote() const;
          _Check_return_ BOOL GetNote(_Out_z_cap_(*pcchNote) LPTSTR lpszNote, _Inout_ UINT* pcchNote) const;
          BOOL SetNote(_In_z_ LPCTSTR lpszNote);
          UINT GetNoteLength() const;
          BOOL GetSplitInfo(_Out_ PBUTTON_SPLITINFO pInfo) const;
          BOOL SetSplitInfo(_In_ PBUTTON_SPLITINFO pInfo);
          UINT GetSplitStyle() const;
          BOOL SetSplitStyle(_In_ UINT nStyle);
          BOOL GetSplitSize(_Out_ LPSIZE pSize) const;
          BOOL SetSplitSize(_In_ LPSIZE pSize);
          CImageList* GetSplitImageList() const;
          BOOL SetSplitImageList(_In_ CImageList* pSplitImageList);
          TCHAR GetSplitGlyph() const;
          BOOL SetSplitGlyph(_In_ TCHAR chGlyph);
          BOOL SetDropDownState(_In_ BOOL fDropDown);

          // Sets whether the action associated with the button requires elevated permissions.
          // If elevated permissions are required then the button should display
          
          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          Inheritance is the natural way for doing that. Any other way (if feasible) would be contrived.

          Veni, vidi, vici.

          In testa che avete, signor di Ceprano?

          1 Reply Last reply
          0
          • F Falconapollo

            then, how about Hook?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Falconapollo wrote:

            how about Hook?

            What does that have to do with drawing a CButton? Hooks are system wide so you would need to capture every drawing message and then decide whether it was for your control or not. That's like using a big hammer to crack a small nut.

            1 Reply Last reply
            0
            • F Falconapollo

              As shown below, there are a few functions in CButton, but i want to change its behaviour by dealing with

              virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)

              . Yes, just this one and only one functon. It would generate more code than expected if I derive a class from CButton. I wonder if it possible to process this function without Subclass, and not use derivation. If so, how? Remarks: I must use MFC, it's so hard to use pure Win32 API.

              class CButton : public CWnd
              {
              DECLARE_DYNAMIC(CButton)

              // Constructors
              public:
              CButton();
              virtual BOOL Create(LPCTSTR lpszCaption, DWORD dwStyle,
              const RECT& rect, CWnd* pParentWnd, UINT nID);

              // Attributes
              UINT GetState() const;
              void SetState(BOOL bHighlight);
              int GetCheck() const;
              void SetCheck(int nCheck);
              UINT GetButtonStyle() const;
              void SetButtonStyle(UINT nStyle, BOOL bRedraw = TRUE);

              HICON SetIcon(HICON hIcon);
              HICON GetIcon() const;
              HBITMAP SetBitmap(HBITMAP hBitmap);
              HBITMAP GetBitmap() const;
              HCURSOR SetCursor(HCURSOR hCursor);
              HCURSOR GetCursor();
              

              #if (_WIN32_WINNT >= 0x501)
              AFX_ANSI_DEPRECATED BOOL GetIdealSize(_Out_ LPSIZE psize) const;
              AFX_ANSI_DEPRECATED BOOL SetImageList(_In_ PBUTTON_IMAGELIST pbuttonImagelist);
              AFX_ANSI_DEPRECATED BOOL GetImageList(_In_ PBUTTON_IMAGELIST pbuttonImagelist) const;
              AFX_ANSI_DEPRECATED BOOL SetTextMargin(_In_ LPRECT pmargin);
              AFX_ANSI_DEPRECATED BOOL GetTextMargin(_Out_ LPRECT pmargin) const;
              #endif // (_WIN32_WINNT >= 0x501)

              #if ( _WIN32_WINNT >= 0x0600 ) && defined(UNICODE)
              CString GetNote() const;
              _Check_return_ BOOL GetNote(_Out_z_cap_(*pcchNote) LPTSTR lpszNote, _Inout_ UINT* pcchNote) const;
              BOOL SetNote(_In_z_ LPCTSTR lpszNote);
              UINT GetNoteLength() const;
              BOOL GetSplitInfo(_Out_ PBUTTON_SPLITINFO pInfo) const;
              BOOL SetSplitInfo(_In_ PBUTTON_SPLITINFO pInfo);
              UINT GetSplitStyle() const;
              BOOL SetSplitStyle(_In_ UINT nStyle);
              BOOL GetSplitSize(_Out_ LPSIZE pSize) const;
              BOOL SetSplitSize(_In_ LPSIZE pSize);
              CImageList* GetSplitImageList() const;
              BOOL SetSplitImageList(_In_ CImageList* pSplitImageList);
              TCHAR GetSplitGlyph() const;
              BOOL SetSplitGlyph(_In_ TCHAR chGlyph);
              BOOL SetDropDownState(_In_ BOOL fDropDown);

              // Sets whether the action associated with the button requires elevated permissions.
              // If elevated permissions are required then the button should display
              
              _ Offline
              _ Offline
              _Superman_
              wrote on last edited by
              #6

              WTL is a light weight template library for creating UI controls. Michael Dunn[^] has written some great articles about WTL. These couple of articles would be useful for you - WTL for MFC Programmers, Part IV - Dialogs and Controls[^] WTL for MFC Programmers, Part V - Advanced Dialog UI Classes[^]

              «_Superman_»  _I love work. It gives me something to do between weekends.

              _Microsoft MVP (Visual C++) (October 2009 - September 2013)

              Polymorphism in C

              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