Click here to Skip to main content
15,887,175 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Azure DevOps Chocolatey question : install vs2022 Pin
Mircea Neacsu17-Feb-22 8:02
Mircea Neacsu17-Feb-22 8:02 
GeneralRe: Azure DevOps Chocolatey question : install vs2022 Pin
Maximilien18-Feb-22 3:23
Maximilien18-Feb-22 3:23 
GeneralRe: Azure DevOps Chocolatey question : install vs2022 Pin
Mircea Neacsu18-Feb-22 5:06
Mircea Neacsu18-Feb-22 5:06 
QuestionMessage Closed Pin
13-Feb-22 18:51
Member 1496877113-Feb-22 18:51 
AnswerRe: resource wanted - print control / color codes Pin
Gerry Schmitz13-Feb-22 19:32
mveGerry Schmitz13-Feb-22 19:32 
AnswerRe: resource wanted - print control / color codes Pin
Richard MacCutchan13-Feb-22 22:24
mveRichard MacCutchan13-Feb-22 22:24 
AnswerRe: resource wanted - print control / color codes Pin
Peter_in_278013-Feb-22 22:31
professionalPeter_in_278013-Feb-22 22:31 
QuestionStatic OwnerDraw SS_OWNERDRAW DrawItem not being called Pin
ForNow7-Feb-22 14:53
ForNow7-Feb-22 14:53 
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

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


The CMystatic class
C++
#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];
    int width;
    char text[9];
protected:
    DECLARE_MESSAGE_MAP()
    // private:
     //   CDumpContext dc;
};


The DDX statements
C++
void CStorge::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	
	DDX_Control(pDX, IDC_ASID_LABEL, casidlabel);
	DDX_Control(pDX, IDC_ASID, casid);
	DDX_Control(pDX, IDC_SUBPOOL_LABEL, csubpoolabel);
	DDX_Control(pDX, IDC_SP, csubpool);
	DDX_Control(pDX, IDC_TCB_LABEL, ctcblabel);
	DDX_Control(pDX, IDC_TCB, ctcb);
	DDX_Control(pDX, IDC_FP_LABEL, cfplabel);
	DDX_Control(pDX, IDC_FP, cfp);
	DDX_Control(pDX, IDC_AREA_LABEL, carealabel);
	DDX_Control(pDX, IDC_AREA, carea);
	DDX_Control(pDX, IDC_KEY_LABEL, ckeylabel);
	DDX_Control(pDX, IDC_KEY, ckey);
	DDX_Control(pDX, IDC_EDIT2, (CWnd&) *storagepointer);
			
}


The DRAWITEM
C++
IMPLEMENT_DYNAMIC(CMystatic, CStatic)

CMystatic::CMystatic()
{

}

void CMystatic::DrawItem(LPDRAWITEMSTRUCT pdi)
{
    ASSERT(pdi->CtlType == ODT_STATIC);
    CDC* pDC = CDC::FromHandle(pdi->hDC);
    ASSERT(pDC != NULL);
    CWnd* phwnd = CWnd::FromHandle(pdi->hwndItem);
    strcpy_s(&fontface[0],15, "Times New Roman");
    pDC->FillSolidRect(&pdi->rcItem, RGB(240, 255, 255));

    CString str;
    phwnd->GetWindowText(str);
   
        // Get text format options.
        UINT nFormat = DT_CENTER;
        // get actual settings in case they has been changed
        DWORD dwStyle = phwnd->GetStyle();
        // Don't process '&' prefix sequences
        if (dwStyle & SS_NOPREFIX)
            nFormat |= DT_NOPREFIX;
        // vertically centered text and no new line
        if ((dwStyle & SS_CENTERIMAGE) && str.Find(_T('\n')) < 0)
        {
            nFormat &= ~DT_WORDBREAK;
            nFormat |= DT_VCENTER | DT_SINGLELINE;	// must set both!
        }
        if (dwStyle & SS_ELLIPSISMASK)
        {
            nFormat &= ~DT_EXPANDTABS; // not supported with ellipsis
            switch (dwStyle & SS_ELLIPSISMASK)
            {
            case SS_ENDELLIPSIS:
                nFormat |= DT_END_ELLIPSIS | DT_MODIFYSTRING; break;
            case SS_PATHELLIPSIS:
                nFormat |= DT_PATH_ELLIPSIS | DT_MODIFYSTRING; break;
            case SS_WORDELLIPSIS:
                nFormat |= DT_WORD_ELLIPSIS; break;
            }
        }
        // The complete background has just been filled.
        // So use transparent mode for faster text drawing.
        // Saving and restoring of colors and mode is not necessary (drawing only performed here).
     if (!str.IsEmpty())
     {
        pDC->SetBkMode(TRANSPARENT);
        pDC->SetTextColor(RGB(0,0,255));

        int mapmode = pDC->GetMapMode();
        CFont l_font;
        LOGFONT lf;
        TEXTMETRIC tm;
        memset(&lf, 0x00, sizeof(lf));

        pDC->GetTextMetrics(&tm);

        lf.lfHeight = tm.tmHeight + 4;

        CSize sz;
        sz = pDC->GetTextExtent(str, str.GetLength());
        lf.lfWidth = (sz.cx / str.GetLength()) + width;
        lf.lfWeight = 700;
        strcpy_s(lf.lfFaceName,15, &fontface[0]); // Need a face name "Arial".
        l_font.CreateFontIndirect(&lf);
        pDC->SelectObject(&l_font);
        // The text string may be modified if DT_MODIFYSTRING is set!
        LPTSTR lpszText = str.GetBuffer();

        pDC->DrawText(lpszText, -1, &pdi->rcItem, nFormat);

        str.ReleaseBuffer();



    }
    else
    {
        pDC->SetTextColor(RGB(255, 0, 0));
        pDC->DrawText(&text[0], -1, &pdi->rcItem, nFormat);

    }
}

BEGIN_MESSAGE_MAP(CMystatic, CStatic)
END_MESSAGE_MAP()

AnswerRe: Static OwnerDraw SS_OWNERDRAW DrawItem not being called Pin
Richard MacCutchan7-Feb-22 21:08
mveRichard MacCutchan7-Feb-22 21:08 
GeneralRe: Static OwnerDraw SS_OWNERDRAW DrawItem not being called Pin
Victor Nijegorodov7-Feb-22 22:49
Victor Nijegorodov7-Feb-22 22:49 
GeneralRe: Static OwnerDraw SS_OWNERDRAW DrawItem not being called Pin
Richard MacCutchan7-Feb-22 23:39
mveRichard MacCutchan7-Feb-22 23:39 
AnswerRe: Static OwnerDraw SS_OWNERDRAW DrawItem not being called Pin
Victor Nijegorodov7-Feb-22 22:42
Victor Nijegorodov7-Feb-22 22:42 
GeneralRe: Static OwnerDraw SS_OWNERDRAW DrawItem not being called Pin
ForNow8-Feb-22 1:23
ForNow8-Feb-22 1:23 
GeneralRe: It gets called at the end of the OnInitDialog Pin
ForNow8-Feb-22 11:25
ForNow8-Feb-22 11:25 
Questionways to write code for a class Pin
Calin Negru6-Feb-22 7:43
Calin Negru6-Feb-22 7:43 
AnswerRe: ways to write code for a class Pin
Mircea Neacsu6-Feb-22 9:15
Mircea Neacsu6-Feb-22 9:15 
AnswerRe: ways to write code for a class Pin
Greg Utas6-Feb-22 10:16
professionalGreg Utas6-Feb-22 10:16 
GeneralRe: ways to write code for a class Pin
Calin Negru6-Feb-22 23:28
Calin Negru6-Feb-22 23:28 
QuestionC++ Pin
Naveenkumarreddy Ramireddy6-Feb-22 6:44
Naveenkumarreddy Ramireddy6-Feb-22 6:44 
AnswerRe: C++ Pin
trønderen6-Feb-22 8:00
trønderen6-Feb-22 8:00 
AnswerRe: C++ Pin
Victor Nijegorodov6-Feb-22 8:50
Victor Nijegorodov6-Feb-22 8:50 
AnswerRe: C++ Pin
Artem Moroz8-Feb-22 9:19
Artem Moroz8-Feb-22 9:19 
QuestionRichEdit Streamin SF_TEXT not appearing Pin
ForNow30-Jan-22 14:58
ForNow30-Jan-22 14:58 
AnswerRe: RichEdit Streamin SF_TEXT not appearing Pin
Victor Nijegorodov30-Jan-22 20:43
Victor Nijegorodov30-Jan-22 20:43 
GeneralRe: RichEdit Streamin SF_TEXT not appearing Pin
ForNow30-Jan-22 20:48
ForNow30-Jan-22 20:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.