Static OwnerDraw SS_OWNERDRAW DrawItem not being called
-
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
ENDDefined 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]; -
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
ENDDefined 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];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.
-
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
ENDDefined 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];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.
-
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.
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)
-
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)
-
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.
-
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.
-
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)
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[^]