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. Static OwnerDraw SS_OWNERDRAW DrawItem not being called

Static OwnerDraw SS_OWNERDRAW DrawItem not being called

Scheduled Pinned Locked Moved C / C++ / MFC
linuxdebugginglearning
8 Posts 4 Posters 9 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
    ForNow
    wrote on last edited by
    #1

    I am going to paste all the relevant parts the resource control statements I am not quite sure what drives the Drawitem at one point I thought it was SetWindowText (I do that to ) have a breakpoint at the DRAWITMEM and doesnt get called thanks

    IDD_DIALOG10 DIALOGEX 0, 0, 769, 429
    STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
    CAPTION "Storage View / Change"
    FONT 8, "MS Shell Dlg", 400, 0, 0x1
    BEGIN
    CONTROL "",IDC_TCB,"Static",WS_CHILD| SS_OWNERDRAW, 45,30,47,8
    CONTROL "Owning TCB",IDC_TCB_LABEL,"Static",WS_CHILD | SS_OWNERDRAW, 41,13,58,8
    CONTROL "",IDC_SP,"Static",WS_CHILD | SS_OWNERDRAW ,164,28,43,8
    CONTROL "Storage SubPool",IDC_SUBPOOL_LABEL,"Static", WS_CHILD | SS_OWNERDRAW, 162,12,55,8
    CONTROL "",IDC_ASID,"Static", WS_CHILD | SS_OWNERDRAW, 265,26,32,8
    CONTROL "Asid",IDC_ASID_LABEL,"Static", WS_CHILD | SS_OWNERDRAW ,269,9,31,8,SS_OWNERDRAW
    CONTROL "",IDC_FP,"Static", WS_CHILD | SS_OWNERDRAW , 399,31,19,8
    CONTROL "Fetch Protect Key",IDC_FP_LABEL,"Static",WS_CHILD | SS_OWNERDRAW ,392,15,63,8
    CONTROL "",IDC_CUSTOM5,"PieCOntrol",WS_TABSTOP,617,99,109,109
    COMBOBOX IDC_COMBO1,491,236,48,30,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP
    CONTROL "",IDC_EDIT2,"RichEdit20A",ES_MULTILINE | WS_BORDER | WS_TABSTOP,45,106,494,314
    COMBOBOX IDC_COMBO2,637,244,67,16,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP
    LISTBOX IDC_LIST2,641,310,68,11,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
    CONTROL "Storage Area",IDC_AREA_LABEL,"Static", WS_CHILD | SS_OWNERDRAW , 534,14,58,8
    CONTROL "",IDC_AREA,"Static", WS_CHILD | SS_OWNERDRAW , 537,25,31,8
    CONTROL "Storage Key",IDC_KEY_LABEL,"Static", WS_CHILD | SS_OWNERDRAW, 651,17,48,8
    CONTROL "",IDC_KEY,"Static", WS_CHILD | SS_OWNERDRAW , 654,31,30,8
    END

    Defined in the Dialog class

    CMystatic ctcb, csubpool, casid, cfp, carea, ckey, ctcblabel, csubpoolabel, casidlabel,cfplabel, carealabel, ckeylabel;

    The CMystatic class

    #pragma once
    #include "afx.h"
    #include "afxwin.h"
    class CMystatic : public CStatic
    {

    DECLARE\_DYNAMIC(CMystatic)
    

    public:
    CMystatic();
    // void Dump();
    virtual void DrawItem(LPDRAWITEMSTRUCT pdi);
    BYTE red;
    BYTE green;
    BYTE blue;
    char fontface[16];

    L V 2 Replies Last reply
    0
    • F ForNow

      I am going to paste all the relevant parts the resource control statements I am not quite sure what drives the Drawitem at one point I thought it was SetWindowText (I do that to ) have a breakpoint at the DRAWITMEM and doesnt get called thanks

      IDD_DIALOG10 DIALOGEX 0, 0, 769, 429
      STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
      CAPTION "Storage View / Change"
      FONT 8, "MS Shell Dlg", 400, 0, 0x1
      BEGIN
      CONTROL "",IDC_TCB,"Static",WS_CHILD| SS_OWNERDRAW, 45,30,47,8
      CONTROL "Owning TCB",IDC_TCB_LABEL,"Static",WS_CHILD | SS_OWNERDRAW, 41,13,58,8
      CONTROL "",IDC_SP,"Static",WS_CHILD | SS_OWNERDRAW ,164,28,43,8
      CONTROL "Storage SubPool",IDC_SUBPOOL_LABEL,"Static", WS_CHILD | SS_OWNERDRAW, 162,12,55,8
      CONTROL "",IDC_ASID,"Static", WS_CHILD | SS_OWNERDRAW, 265,26,32,8
      CONTROL "Asid",IDC_ASID_LABEL,"Static", WS_CHILD | SS_OWNERDRAW ,269,9,31,8,SS_OWNERDRAW
      CONTROL "",IDC_FP,"Static", WS_CHILD | SS_OWNERDRAW , 399,31,19,8
      CONTROL "Fetch Protect Key",IDC_FP_LABEL,"Static",WS_CHILD | SS_OWNERDRAW ,392,15,63,8
      CONTROL "",IDC_CUSTOM5,"PieCOntrol",WS_TABSTOP,617,99,109,109
      COMBOBOX IDC_COMBO1,491,236,48,30,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP
      CONTROL "",IDC_EDIT2,"RichEdit20A",ES_MULTILINE | WS_BORDER | WS_TABSTOP,45,106,494,314
      COMBOBOX IDC_COMBO2,637,244,67,16,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP
      LISTBOX IDC_LIST2,641,310,68,11,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
      CONTROL "Storage Area",IDC_AREA_LABEL,"Static", WS_CHILD | SS_OWNERDRAW , 534,14,58,8
      CONTROL "",IDC_AREA,"Static", WS_CHILD | SS_OWNERDRAW , 537,25,31,8
      CONTROL "Storage Key",IDC_KEY_LABEL,"Static", WS_CHILD | SS_OWNERDRAW, 651,17,48,8
      CONTROL "",IDC_KEY,"Static", WS_CHILD | SS_OWNERDRAW , 654,31,30,8
      END

      Defined in the Dialog class

      CMystatic ctcb, csubpool, casid, cfp, carea, ckey, ctcblabel, csubpoolabel, casidlabel,cfplabel, carealabel, ckeylabel;

      The CMystatic class

      #pragma once
      #include "afx.h"
      #include "afxwin.h"
      class CMystatic : public CStatic
      {

      DECLARE\_DYNAMIC(CMystatic)
      

      public:
      CMystatic();
      // void Dump();
      virtual void DrawItem(LPDRAWITEMSTRUCT pdi);
      BYTE red;
      BYTE green;
      BYTE blue;
      char fontface[16];

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

      The WM_DRAWITEM message gets sent to the parent window when the control needs to be drawn. So you need to handle that message in your dialog's message handler. See WM_DRAWITEM message (Winuser.h) - Win32 apps | Microsoft Docs[^] for more details. The DRAWITEMSTRUCT (winuser.h) - Win32 apps | Microsoft Docs[^] contains details and flags which identify which phase of drawing needs to be performed. It is rather convoluted but I have used it in the past and it does work, as long as you follow the rules.

      V 1 Reply Last reply
      0
      • F ForNow

        I am going to paste all the relevant parts the resource control statements I am not quite sure what drives the Drawitem at one point I thought it was SetWindowText (I do that to ) have a breakpoint at the DRAWITMEM and doesnt get called thanks

        IDD_DIALOG10 DIALOGEX 0, 0, 769, 429
        STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
        CAPTION "Storage View / Change"
        FONT 8, "MS Shell Dlg", 400, 0, 0x1
        BEGIN
        CONTROL "",IDC_TCB,"Static",WS_CHILD| SS_OWNERDRAW, 45,30,47,8
        CONTROL "Owning TCB",IDC_TCB_LABEL,"Static",WS_CHILD | SS_OWNERDRAW, 41,13,58,8
        CONTROL "",IDC_SP,"Static",WS_CHILD | SS_OWNERDRAW ,164,28,43,8
        CONTROL "Storage SubPool",IDC_SUBPOOL_LABEL,"Static", WS_CHILD | SS_OWNERDRAW, 162,12,55,8
        CONTROL "",IDC_ASID,"Static", WS_CHILD | SS_OWNERDRAW, 265,26,32,8
        CONTROL "Asid",IDC_ASID_LABEL,"Static", WS_CHILD | SS_OWNERDRAW ,269,9,31,8,SS_OWNERDRAW
        CONTROL "",IDC_FP,"Static", WS_CHILD | SS_OWNERDRAW , 399,31,19,8
        CONTROL "Fetch Protect Key",IDC_FP_LABEL,"Static",WS_CHILD | SS_OWNERDRAW ,392,15,63,8
        CONTROL "",IDC_CUSTOM5,"PieCOntrol",WS_TABSTOP,617,99,109,109
        COMBOBOX IDC_COMBO1,491,236,48,30,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP
        CONTROL "",IDC_EDIT2,"RichEdit20A",ES_MULTILINE | WS_BORDER | WS_TABSTOP,45,106,494,314
        COMBOBOX IDC_COMBO2,637,244,67,16,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP
        LISTBOX IDC_LIST2,641,310,68,11,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
        CONTROL "Storage Area",IDC_AREA_LABEL,"Static", WS_CHILD | SS_OWNERDRAW , 534,14,58,8
        CONTROL "",IDC_AREA,"Static", WS_CHILD | SS_OWNERDRAW , 537,25,31,8
        CONTROL "Storage Key",IDC_KEY_LABEL,"Static", WS_CHILD | SS_OWNERDRAW, 651,17,48,8
        CONTROL "",IDC_KEY,"Static", WS_CHILD | SS_OWNERDRAW , 654,31,30,8
        END

        Defined in the Dialog class

        CMystatic ctcb, csubpool, casid, cfp, carea, ckey, ctcblabel, csubpoolabel, casidlabel,cfplabel, carealabel, ckeylabel;

        The CMystatic class

        #pragma once
        #include "afx.h"
        #include "afxwin.h"
        class CMystatic : public CStatic
        {

        DECLARE\_DYNAMIC(CMystatic)
        

        public:
        CMystatic();
        // void Dump();
        virtual void DrawItem(LPDRAWITEMSTRUCT pdi);
        BYTE red;
        BYTE green;
        BYTE blue;
        char fontface[16];

        V Offline
        V Offline
        Victor Nijegorodov
        wrote on last edited by
        #3

        I added an owner draw static to my MFC dialog application, added your code for DrawItem, fixed some bugs in your CMyStatic class, and I have to say: it works.

        F 2 Replies Last reply
        0
        • L Lost User

          The WM_DRAWITEM message gets sent to the parent window when the control needs to be drawn. So you need to handle that message in your dialog's message handler. See WM_DRAWITEM message (Winuser.h) - Win32 apps | Microsoft Docs[^] for more details. The DRAWITEMSTRUCT (winuser.h) - Win32 apps | Microsoft Docs[^] contains details and flags which identify which phase of drawing needs to be performed. It is rather convoluted but I have used it in the past and it does work, as long as you follow the rules.

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #4

          No Richard. The OP tries to use/override the virtual method of the MFC CStatic class: [CStatic Class | Microsoft Docs](https://docs.microsoft.com/en-us/cpp/mfc/reference/cstatic-class?view=msvc-170#drawitem) I have no idea why he has any problem here. I tried his DrawItem implementation and it works (however, I had to fix some bugs in his sample)

          L S 2 Replies Last reply
          0
          • V Victor Nijegorodov

            No Richard. The OP tries to use/override the virtual method of the MFC CStatic class: [CStatic Class | Microsoft Docs](https://docs.microsoft.com/en-us/cpp/mfc/reference/cstatic-class?view=msvc-170#drawitem) I have no idea why he has any problem here. I tried his DrawItem implementation and it works (however, I had to fix some bugs in his sample)

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

            Thanks, it's too many years since I used MFC.

            1 Reply Last reply
            0
            • V Victor Nijegorodov

              I added an owner draw static to my MFC dialog application, added your code for DrawItem, fixed some bugs in your CMyStatic class, and I have to say: it works.

              F Offline
              F Offline
              ForNow
              wrote on last edited by
              #6

              Thank you let me re-visit

              1 Reply Last reply
              0
              • V Victor Nijegorodov

                I added an owner draw static to my MFC dialog application, added your code for DrawItem, fixed some bugs in your CMyStatic class, and I have to say: it works.

                F Offline
                F Offline
                ForNow
                wrote on last edited by
                #7

                Hi When posted I was under the impression that Drawitem runs after window Creation which in my case is the DDX_Control however it runs after the return of the OnInitDialog Sorry and thanks

                1 Reply Last reply
                0
                • V Victor Nijegorodov

                  No Richard. The OP tries to use/override the virtual method of the MFC CStatic class: [CStatic Class | Microsoft Docs](https://docs.microsoft.com/en-us/cpp/mfc/reference/cstatic-class?view=msvc-170#drawitem) I have no idea why he has any problem here. I tried his DrawItem implementation and it works (however, I had to fix some bugs in his sample)

                  S Offline
                  S Offline
                  social media 2022
                  wrote on last edited by
                  #8

                  If any body want to want to draw lsomeething like thi sthen how it is posible? In website . How to draw Glasses | Easy Pencil Sketch in 5 Steps - Easy Drawing[^]

                  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