subclassing CStatic

Hi,

I have subclassed a few CStatic ctrls so i can quickly change their font, BG
and FG colors etc... I have also handled the CFormView's CtlColor message
and painted the form white and text blue.

The problem that im having is the subclassed objects are painting themselves
the colors i specify, then the CFormView::OnCtlColor is painting them again.

This isnt too much of a problem as i can simply exclude the subclassed items
from the painting using:

HBRUSH CSmartMXEditLangView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT
nCtlColor)
{
    // create white brush:
    m_DlgBrush.DeleteObject();
    m_DlgBrush.CreateSolidBrush(RGB(255,255,255));

    // get default brush:
    HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);

    // *****exclude subclassed items:*****
    if(
           (pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM1)            // NOT
a subclassed ctrl
     &&(pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM2)            // NOT a
subclassed ctrl
     &&(pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM3)            // NOT a
subclassed ctrl
     &&(pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM4)            // NOT a
subclassed ctrl
     &&(pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM5)            // NOT a
subclassed ctrl
    )
    {
            hbr = m_DlgBrush; // use white brush
            pDC->SetBkMode(TRANSPARENT);
            pDC->SetTextColor(RGB(0, 0, 255));
    }
    return hbr;
}

Is there a way to tell if a object is subclassed at runtime so i dont have
to type out all the subclassed objects?


Joe
#


0
joey
7/10/2003 12:06:59 PM
vc.mfc 33608 articles. 0 followers. Follow

7 Replies
1510 Views

Similar Articles

[PageSpeed] 56

try checking out this... enable rtti info in your project on the project
settings c/c++ tab, c++ language list.  then you should be able to use one
of these:

if the objects are all the same subclass try something like:
IsKindOf(RUNTIME_CLASS( yoursubclassname)) to check it.

if they are different subclasses but all derived from CStatic you should be
able to use:
CRuntimeClass* ctrlclass=pWnd->GetRuntimeClass()
and then check ctrlclass->m_pBaseClass->IsKindOf(RUNTIME_CLASS(CStatic)) to
see that its derived from CStatic.

note, i have used the first one to check that a view is of a specific class,
i haven't tried the second one but it looks like the way to go.

"joey" <MSforum1@---I-DONT-LIKE-SPAM---Kybert.co.uk> wrote in message
news:#R$iDvtRDHA.3132@tk2msftngp13.phx.gbl...
> Hi,
>
> I have subclassed a few CStatic ctrls so i can quickly change their font,
BG
> and FG colors etc... I have also handled the CFormView's CtlColor message
> and painted the form white and text blue.
>
> The problem that im having is the subclassed objects are painting
themselves
> the colors i specify, then the CFormView::OnCtlColor is painting them
again.
>
> This isnt too much of a problem as i can simply exclude the subclassed
items
> from the painting using:
>
> HBRUSH CSmartMXEditLangView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT
> nCtlColor)
> {
>     // create white brush:
>     m_DlgBrush.DeleteObject();
>     m_DlgBrush.CreateSolidBrush(RGB(255,255,255));
>
>     // get default brush:
>     HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
>
>     // *****exclude subclassed items:*****
>     if(
>            (pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM1)            //
NOT
> a subclassed ctrl
>      &&(pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM2)            // NOT a
> subclassed ctrl
>      &&(pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM3)            // NOT a
> subclassed ctrl
>      &&(pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM4)            // NOT a
> subclassed ctrl
>      &&(pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM5)            // NOT a
> subclassed ctrl
>     )
>     {
>             hbr = m_DlgBrush; // use white brush
>             pDC->SetBkMode(TRANSPARENT);
>             pDC->SetTextColor(RGB(0, 0, 255));
>     }
>     return hbr;
> }
>
> Is there a way to tell if a object is subclassed at runtime so i dont have
> to type out all the subclassed objects?
>
>
> Joe
> #
>
>


0
drobbins (12)
7/10/2003 1:24:58 PM
Hi,

Try to add some information to the subclassed window when you subclass it
as:
SetWindowLong(hWnd, GWL_USER, YOURSIG)
Then later to check if this is your window do:
if (GetWindowLong(hwnd, GWL_USER) == YOURSIG) // skip it...

p.s: this is not the best way.

Regards,
Elias


0
lallous (134)
7/10/2003 2:15:04 PM
On Thu, 10 Jul 2003 13:06:59 +0100, "joey" <MSforum1@---I-DONT-LIKE-SPAM---Kybert.co.uk> wrote:

>Hi,
>
>I have subclassed a few CStatic ctrls so i can quickly change their font, BG
>and FG colors etc... I have also handled the CFormView's CtlColor message
>and painted the form white and text blue.
>
>The problem that im having is the subclassed objects are painting themselves
>the colors i specify, then the CFormView::OnCtlColor is painting them again.

I'm not sure you are doing this right, then again I'm not sure I
understand what you're asking.

OnCtlColor is *specifically* available to set background brush
for controls contained in the window.

If you want white background for your view, then do that in OnEraseBkgnd()
If you want blue text in your view, then pDC->SetTextColor() in OnDraw()

AFAICT, there is no problem except using the wrong method,
and it's doing exactly what you asked it to.

regards

bullshark
0
bullshark (19)
7/10/2003 3:50:06 PM
hi,

I didn't bother in the end, i needed the ability to use different fonts, and
colors in a formview with a custom form background color and i found that
the subclassing approch wasn't making life easy, so... i wrote a cupple of
structs that hold the colors of objects, and when the object is painted by
windows, i changed the color there.

My code is below, use freely... i expect it will be blasted by other
devolopers in the forum as its not exactly the best implimentation, but it
works for me.

<some global .h>
#define BOLD 0x0001
#define ITALIC 0x0002
#define UNDERLINE 0x0004
#define STRIKEOUT 0x0008

// view colors:
#define EDIT_LANG_VIEW_BGCOLOR ( RGB(255,255,215) )    // pale yellow
#define EDIT_LANG_VIEW_TEXTCOLOR ( RGB(0,0,255) )        // black
#define EDIT_LANG_VIEW_TEXTCHANGEDCOLOR ( RGB(255,0,0) )    // red

typedef struct tagColorChart // used to hold control colors in views
{
COLORREF crTextColor; // ctrl color
int iCtrlID; // ctrl ID
}COLOR_CHART;

// Inital control colors (controls can still change colors, see the
// control colors CMap notes in the views' header file).
// colors added here will be shown when view is constructed, colors can be
changed
// at runtime, also see CMap notes in views header):
const struct tagColorChart EditLangViewColors[] = {
{ RGB(255,0,0), IDC_CREATE_STATIC }
,{ RGB(255,0,0), IDC_CREATE_TIME_STATIC }
,{ RGB(255,0,0), IDC_CREATE_DATE_STATIC }
,{ RGB(255,0,0), IDC_MODS_DATE_STATIC }
};


<view .h>
private:
CBrush m_brDlgBrush;
CFont m_Font;

// Inital control colors CMap.
// To modify the colors at runtime (or add another contorl to the list):
//
// CtrlColors[IDC_CREATE_TIME].crTextColor = RGB(128,128,128);
// or
// CtrlColors[IDC_CREATE_TIME].crTextColor =
EDIT_LANG_VIEW_TEXTCHANGEDCOLOR;
// If you add an item (if the item is not found it is added) you
// MUST also add the FG and ID for the item!
CMap<int, int, tagColorChart, tagColorChart&> CtrlColors;

<view .cpp>

// constructor:
CSmartMXEditLangView::CSmartMXEditLangView()
: CFormView(CSmartMXEditLangView::IDD)
{
// setup colors:
m_brDlgBrush.DeleteObject();
m_brDlgBrush.CreateSolidBrush(EDIT_LANG_VIEW_BGCOLOR);

// load CtrlColors map:
    int iTotalColors =
sizeof(EditLangViewColors)/sizeof(EditLangViewColors[0]);
    for(int x=0; x < iTotalColors; x++)
        CtrlColors[EditLangViewColors[x].iCtrlID] = EditLangViewColors[x];
// load CMap(CtrlColors)
// end of loading
}

HBRUSH CSmartMXEditLangView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT
nCtlColor)
{
// list control doesn't paint, so do it now:
c_FontList.SetBkColor (EDIT_LANG_VIEW_BGCOLOR);
c_FontList.SetTextBkColor (EDIT_LANG_VIEW_BGCOLOR);
c_FontList.SetTextColor (EDIT_LANG_VIEW_TEXTCOLOR);

// everything uses the dialog background color:
pDC->SetTextColor(EDIT_LANG_VIEW_TEXTCOLOR); // global text color
pDC->SetBkMode(TRANSPARENT);

// get control colors, and set:
int iSearchID = pWnd->GetDlgCtrlID();
if(iSearchID)
{
    COLOR_CHART CC;
    if(CtrlColors.Lookup(iSearchID, CC) )
        {
            pDC->SetTextColor( CtrlColors[iSearchID].crTextColor );
            //pDC->SetBkMode(OPAQUE); // only if using a custom BG color for
CTRL
        }
}
return (HBRUSH)m_brDlgBrush;
}


void CSmartMXEditLangView::SetFontFace(CDC* pDC, int nPointSize, LPCTSTR
szFontFace, WORD nFlags)
{
// example call:
//             setup "no file loaded" static ctrl font:
//            SetFontFace(c_NoFileLoaded.GetDC(), 24, "Tahoma", BOLD |
UNDERLINE);
//
LOGFONT LogFont;
memset(&LogFont, 0, sizeof(LOGFONT)); // clear out structure.
strcpy(LogFont.lfFaceName, szFontFace);
LogFont.lfHeight = nPointSize*10;
LogFont.lfWeight = (nFlags & BOLD) ? FW_BOLD : NULL;
LogFont.lfItalic = (nFlags & ITALIC) ? TRUE : FALSE;
LogFont.lfUnderline = (nFlags & UNDERLINE) ? TRUE : FALSE;
LogFont.lfStrikeOut = (nFlags & STRIKEOUT) ? TRUE : FALSE;
m_Font.CreatePointFontIndirect(&LogFont);
    if(pDC)
    {
        pDC->GetWindow()->SetFont(&m_Font);
        ReleaseDC(pDC);
    }
}












"Steven C." <nospam@xxx.com> wrote in message
news:%231hBkV2RDHA.2008@TK2MSFTNGP11.phx.gbl...
> I'd be curious to see how you implemented your CStatic subclass because
I'm
> interested in controlling the fonts and colors too!
>
> Thanks,
>
>
> "joey" <MSforum1@---I-DONT-LIKE-SPAM---Kybert.co.uk> wrote in message
> news:%23R$iDvtRDHA.3132@tk2msftngp13.phx.gbl...
> Hi,
>
> I have subclassed a few CStatic ctrls so i can quickly change their font,
BG
> and FG colors etc... I have also handled the CFormView's CtlColor message
> and painted the form white and text blue.
>
> The problem that im having is the subclassed objects are painting
themselves
> the colors i specify, then the CFormView::OnCtlColor is painting them
again.
>
> This isnt too much of a problem as i can simply exclude the subclassed
items
> from the painting using:
>
> HBRUSH CSmartMXEditLangView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT
> nCtlColor)
> {
>     // create white brush:
>     m_DlgBrush.DeleteObject();
>     m_DlgBrush.CreateSolidBrush(RGB(255,255,255));
>
>     // get default brush:
>     HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
>
>     // *****exclude subclassed items:*****
>     if(
>            (pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM1)            //
NOT
> a subclassed ctrl
>      &&(pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM2)            // NOT a
> subclassed ctrl
>      &&(pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM3)            // NOT a
> subclassed ctrl
>      &&(pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM4)            // NOT a
> subclassed ctrl
>      &&(pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM5)            // NOT a
> subclassed ctrl
>     )
>     {
>             hbr = m_DlgBrush; // use white brush
>             pDC->SetBkMode(TRANSPARENT);
>             pDC->SetTextColor(RGB(0, 0, 255));
>     }
>     return hbr;
> }
>
> Is there a way to tell if a object is subclassed at runtime so i dont have
> to type out all the subclassed objects?
>
>
> Joe
> #
>
>
>


0
joey
7/11/2003 10:52:26 PM
add this to the message map too:
ON_WM_CTLCOLOR()





"joey" <MSforum1@---I-DONT-LIKE-SPAM---Kybert.co.uk> wrote in message
news:%23K%23Jb8$RDHA.2188@TK2MSFTNGP10.phx.gbl...
> hi,
>
> I didn't bother in the end, i needed the ability to use different fonts,
and
> colors in a formview with a custom form background color and i found that
> the subclassing approch wasn't making life easy, so... i wrote a cupple of
> structs that hold the colors of objects, and when the object is painted by
> windows, i changed the color there.
>
> My code is below, use freely... i expect it will be blasted by other
> devolopers in the forum as its not exactly the best implimentation, but it
> works for me.
>
> <some global .h>
> #define BOLD 0x0001
> #define ITALIC 0x0002
> #define UNDERLINE 0x0004
> #define STRIKEOUT 0x0008
>
> // view colors:
> #define EDIT_LANG_VIEW_BGCOLOR ( RGB(255,255,215) )    // pale yellow
> #define EDIT_LANG_VIEW_TEXTCOLOR ( RGB(0,0,255) )        // black
> #define EDIT_LANG_VIEW_TEXTCHANGEDCOLOR ( RGB(255,0,0) )    // red
>
> typedef struct tagColorChart // used to hold control colors in views
> {
> COLORREF crTextColor; // ctrl color
> int iCtrlID; // ctrl ID
> }COLOR_CHART;
>
> // Inital control colors (controls can still change colors, see the
> // control colors CMap notes in the views' header file).
> // colors added here will be shown when view is constructed, colors can be
> changed
> // at runtime, also see CMap notes in views header):
> const struct tagColorChart EditLangViewColors[] = {
> { RGB(255,0,0), IDC_CREATE_STATIC }
> ,{ RGB(255,0,0), IDC_CREATE_TIME_STATIC }
> ,{ RGB(255,0,0), IDC_CREATE_DATE_STATIC }
> ,{ RGB(255,0,0), IDC_MODS_DATE_STATIC }
> };
>
>
> <view .h>
> private:
> CBrush m_brDlgBrush;
> CFont m_Font;
>
> // Inital control colors CMap.
> // To modify the colors at runtime (or add another contorl to the list):
> //
> // CtrlColors[IDC_CREATE_TIME].crTextColor = RGB(128,128,128);
> // or
> // CtrlColors[IDC_CREATE_TIME].crTextColor =
> EDIT_LANG_VIEW_TEXTCHANGEDCOLOR;
> // If you add an item (if the item is not found it is added) you
> // MUST also add the FG and ID for the item!
> CMap<int, int, tagColorChart, tagColorChart&> CtrlColors;
>
> <view .cpp>
>
> // constructor:
> CSmartMXEditLangView::CSmartMXEditLangView()
> : CFormView(CSmartMXEditLangView::IDD)
> {
> // setup colors:
> m_brDlgBrush.DeleteObject();
> m_brDlgBrush.CreateSolidBrush(EDIT_LANG_VIEW_BGCOLOR);
>
> // load CtrlColors map:
>     int iTotalColors =
> sizeof(EditLangViewColors)/sizeof(EditLangViewColors[0]);
>     for(int x=0; x < iTotalColors; x++)
>         CtrlColors[EditLangViewColors[x].iCtrlID] = EditLangViewColors[x];
> // load CMap(CtrlColors)
> // end of loading
> }
>
> HBRUSH CSmartMXEditLangView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT
> nCtlColor)
> {
> // list control doesn't paint, so do it now:
> c_FontList.SetBkColor (EDIT_LANG_VIEW_BGCOLOR);
> c_FontList.SetTextBkColor (EDIT_LANG_VIEW_BGCOLOR);
> c_FontList.SetTextColor (EDIT_LANG_VIEW_TEXTCOLOR);
>
> // everything uses the dialog background color:
> pDC->SetTextColor(EDIT_LANG_VIEW_TEXTCOLOR); // global text color
> pDC->SetBkMode(TRANSPARENT);
>
> // get control colors, and set:
> int iSearchID = pWnd->GetDlgCtrlID();
> if(iSearchID)
> {
>     COLOR_CHART CC;
>     if(CtrlColors.Lookup(iSearchID, CC) )
>         {
>             pDC->SetTextColor( CtrlColors[iSearchID].crTextColor );
>             //pDC->SetBkMode(OPAQUE); // only if using a custom BG color
for
> CTRL
>         }
> }
> return (HBRUSH)m_brDlgBrush;
> }
>
>
> void CSmartMXEditLangView::SetFontFace(CDC* pDC, int nPointSize, LPCTSTR
> szFontFace, WORD nFlags)
> {
> // example call:
> //             setup "no file loaded" static ctrl font:
> //            SetFontFace(c_NoFileLoaded.GetDC(), 24, "Tahoma", BOLD |
> UNDERLINE);
> //
> LOGFONT LogFont;
> memset(&LogFont, 0, sizeof(LOGFONT)); // clear out structure.
> strcpy(LogFont.lfFaceName, szFontFace);
> LogFont.lfHeight = nPointSize*10;
> LogFont.lfWeight = (nFlags & BOLD) ? FW_BOLD : NULL;
> LogFont.lfItalic = (nFlags & ITALIC) ? TRUE : FALSE;
> LogFont.lfUnderline = (nFlags & UNDERLINE) ? TRUE : FALSE;
> LogFont.lfStrikeOut = (nFlags & STRIKEOUT) ? TRUE : FALSE;
> m_Font.CreatePointFontIndirect(&LogFont);
>     if(pDC)
>     {
>         pDC->GetWindow()->SetFont(&m_Font);
>         ReleaseDC(pDC);
>     }
> }
>
>
>
>
>
>
>
>
>
>
>
>
> "Steven C." <nospam@xxx.com> wrote in message
> news:%231hBkV2RDHA.2008@TK2MSFTNGP11.phx.gbl...
> > I'd be curious to see how you implemented your CStatic subclass because
> I'm
> > interested in controlling the fonts and colors too!
> >
> > Thanks,
> >
> >
> > "joey" <MSforum1@---I-DONT-LIKE-SPAM---Kybert.co.uk> wrote in message
> > news:%23R$iDvtRDHA.3132@tk2msftngp13.phx.gbl...
> > Hi,
> >
> > I have subclassed a few CStatic ctrls so i can quickly change their
font,
> BG
> > and FG colors etc... I have also handled the CFormView's CtlColor
message
> > and painted the form white and text blue.
> >
> > The problem that im having is the subclassed objects are painting
> themselves
> > the colors i specify, then the CFormView::OnCtlColor is painting them
> again.
> >
> > This isnt too much of a problem as i can simply exclude the subclassed
> items
> > from the painting using:
> >
> > HBRUSH CSmartMXEditLangView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT
> > nCtlColor)
> > {
> >     // create white brush:
> >     m_DlgBrush.DeleteObject();
> >     m_DlgBrush.CreateSolidBrush(RGB(255,255,255));
> >
> >     // get default brush:
> >     HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
> >
> >     // *****exclude subclassed items:*****
> >     if(
> >            (pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM1)            //
> NOT
> > a subclassed ctrl
> >      &&(pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM2)            // NOT
a
> > subclassed ctrl
> >      &&(pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM3)            // NOT
a
> > subclassed ctrl
> >      &&(pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM4)            // NOT
a
> > subclassed ctrl
> >      &&(pWnd->GetDlgCtrlID() != IDC_SUBCLASSED_ITEM5)            // NOT
a
> > subclassed ctrl
> >     )
> >     {
> >             hbr = m_DlgBrush; // use white brush
> >             pDC->SetBkMode(TRANSPARENT);
> >             pDC->SetTextColor(RGB(0, 0, 255));
> >     }
> >     return hbr;
> > }
> >
> > Is there a way to tell if a object is subclassed at runtime so i dont
have
> > to type out all the subclassed objects?
> >
> >
> > Joe
> > #
> >
> >
> >
>
>


0
joey
7/11/2003 11:04:56 PM
"joey" <MSforum1@---I-DONT-LIKE-SPAM---Kybert.co.uk> wrote in message
news:#K#Jb8$RDHA.2188@TK2MSFTNGP10.phx.gbl...
> hi,
>
> I didn't bother in the end, i needed the ability to use different fonts,
and
> colors in a formview with a custom form background color and i found that
> the subclassing approch wasn't making life easy, so... i wrote a cupple of
> structs that hold the colors of objects, and when the object is painted by
> windows, i changed the color there.
>
> My code is below, use freely... i expect it will be blasted by other
> devolopers in the forum as its not exactly the best implimentation, but it
> works for me.
>

*blast* :-)))

Johan Rosengren
Abstrakt Mekanik AB

<snip>


0
7/14/2003 4:23:39 AM
"joey" <MSforum1@---I-DONT-LIKE-SPAM---Kybert.co.uk> wrote:

>Hi,
>
>I have subclassed a few CStatic ctrls so i can quickly change their font, BG
>and FG colors etc... I have also handled the CFormView's CtlColor message
>and painted the form white and text blue.
>
>The problem that im having is the subclassed objects are painting themselves
>the colors i specify, then the CFormView::OnCtlColor is painting them again.
>

As an idea... why not capture the reflected WM_CTLCOLOR message in the
subclassed control? That's where I set background colours for my
controls (CEdits more than CStatics, but it should still work).

HTH

Paul.
-------------------------------------------
Expressed opinions are usually my own.
Especially if they're any good (of course).
-------------------------------------------
NB Spam trap in e-mail address
-------------------------------------------
0
7/17/2003 12:09:59 PM
Reply:

Similar Artilces:

Subclassing
Hello, Im very new to c++ programming so pardon me if this is a dumb question and my bad english. I made a subclass from CListBox. I want to handle all the list controls derived from this class on one function, for example, void CListBox_SC::OnRButtonUp(UINT nFlags, CPoint point) { ..... } on this function I want to manage the OnRButtonUp event, and with a switch or if statement, select the code to execute. The following does work: SetCurSel(ItemFromPoint(point, ifp)); but the following comparison is never true, (IDC_LST_TIPO is a resource for one of the ListBoxes) UINT currLst = It...

HBITMAP on a CStatic control
hi all, as i remember some questions like mine asked before(may be its not directly related to MFC). i have a DIB in memory, what i do now is; first specify a BITMAPINFOHEADER and fill its members (bfType, bfSize etc..) and then using BITMAPINFOHEADER and DIB write to disk. To show this bitmap on a CStatic control i use LoadImage(NULL, "img.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE) which returns a HBITMAP, and then m_ctrl.SetBitmap(HBITMAP). as u can see in some cases (dealing with images which have high resolution) writing/reading to/from disk is very time consuming.. how ...

Custom Drawing CEdit : Subclassing
Hello experts, My objective is simple, but I'm not entirely sure what needs tweaking. I am using MSVC 6, and I would like to subclass the CEdit box so that it appears as the color-picker editbox of a PropertyGrid. There is a color box followed by three values. Like this: [###] 255; 192; 192 Where ### is just a color box representation of the value. So thus far, I've made a masked CEdit box, where I can edit the numbers (or click a button that visually sets the numbers from a different window), and I'm happy with that - but what I would like to do next is to subclass the dra...

Help with subclassing a RichEditCtrl
Hi folks, I could use some help. As a side project I am trying to write a DLL that will extend the functionality of an existing application that I do not have source code for, i.e., some autocompletion functionality, word lookup, etc. In the actual DLL, I am going to have to inject it into the existing app and then use FindWindow or something like that to subclass the existing RichEditCtrl. I need to be able to process the WM_CHAR and WM_KEYDOWN messages only. I started out by creating my own sample project using a RichEditCtrl in my project to code my object. I've now moved everythin...

WM_CREATE for a subclass
Hi All, I am fairly new to C++, although I have developed OO windows applications in the past using CTD and Power Builder. I am developeing an edit class based on a CEdit. I am trying to trap the WM_CREATE message to modify the style of the window (i.e. to make is multiline). For some reason the control does not appear to be getting the WM_CREATE message ( or at least it is not implementing the handler I have for it). At present I create an edit control on a form and the Subclass the edit. This appears to work as my user defined menu is used and my color modifications appear as requir...

Subclassing CWinThread
I created a subclass of CWinThread - no big deal! Now, what I would like to do is use that subclass as a base class for a couple of other, more specialized classes. How can I do this? If I create a subclass as a generic C++ class, then I'm running into the assertion, "Invalid Address specified to RtlValidateHeap( 00940000, 0042DBA0 )" when I post the quit message to the thread. I assume this might have something to do with the virtual/non-virtual constructor combination of the MFC class and the generic C++ class. Any thoughts? Create more subclasses of CWinThread, then ...

Subclassing TreeView
I created a class derived from a TreeView (ShellTree) that displays the Shell directory structure . I changed the LeftView class so that it is derived from my ShellTree class, and everything works as expected, except I cannot add any TreeView specific message handlers to my LeftView class any more eg. NM_DBLCLICK. Basically in a nutshell what i want to do is display the directory name (which is stored in a variable in the ShellTree class) when the LeftView is Double clicked Check out http://www.codeproject.com/treectrl/enumdeskclones.asp Which isn't perfect.. but is a good star...

Detecting mouse over CStatic bitmap
Hello I'm trying to detect when a mouse is over one of three CStatic bitmaps, in a OnMouse function. Unfortunately the OnMouse routine only seems to be called when the pointer isn't over a static object. Currently I can get around it by using Set/Release Capture, but is there a better way? Nicholas Nicholas wrote: > Hello > > I'm trying to detect when a mouse is over one of three CStatic bitmaps, in a > OnMouse function. Unfortunately the OnMouse routine only seems to be called > when the pointer isn't over a static object. > > Currently I ...

Subclassing a subclass of CDialog, for cross-platform compilation
Hi people, I've been working on porting an app from PC to Mac. What I'm trying to do, is separate out the PC specific components into it's own subclass. So there are the PC specific functions like PCAppDlg::OnBtnClicked1, and mac specific functions like MacAppDlg::BlaBlaBla. Of course the Mac subclass doesn't compile on the PC, and the same the other way around. I've had to write my own CDialog wrapper for Mac but that's another story. Now anyhow, this leads me to a question. How to subclass a subclass? Specifically, how does the message maps work? Will there be any p...

Xml Serializing subclass problem
Hi guys. I've come across a problem when I tried to serialize a class into xml, only to discover that the parent class's XML Serialization properties weren't included in the output xml. Actually, the class I'm serializing is two steps down in the inheritance ladder. It's got a parent class which also has a parent class :( All those classes in the hierarchy are Xml Serializable, and I'd think that it should be obvious that all attributes/properties of the parents should be serialized for any given subclass, no ? Here's the two classes, subclass first, parent class...

Subclassing problem???
Hi there, I've got: LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){ switch(uMsg){ case WM_NCACTIVATE: if((BOOL)wParam==FALSE){ DefWindowProc(hwnd, uMsg, wParam, lParam); CreateText(hwnd); return TRUE; } case WM_NCPAINT: DefWindowProc(hwnd, uMsg, wParam, lParam); CreateText(hwnd); break; } DefWindowProc(hwnd, uMsg, wParam, lParam); } void CreateText(HWND hwnd){ HDC hDC = GetWindowDC(hwnd); int x,y; RECT rc1,rc2; GetWindowRect(hwnd, (LPRECT)&rc2 ); x = GetSystemMetrics(SM_CXSIZE) + GetSystemMetrics(SM_CXBORDE...

subclassing CStatic
Hi, I have subclassed a few CStatic ctrls so i can quickly change their font, BG and FG colors etc... I have also handled the CFormView's CtlColor message and painted the form white and text blue. The problem that im having is the subclassed objects are painting themselves the colors i specify, then the CFormView::OnCtlColor is painting them again. This isnt too much of a problem as i can simply exclude the subclassed items from the painting using: HBRUSH CSmartMXEditLangView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { // create white brush: m_DlgBrush.DeleteObject(); ...

VC
I need a way to come up with a simple (free) combobox activeX control I can use in a third party development tool. I tried just subclassing ComboBoxEx using the ActiveX control wizard in VC6. It clearly creates the control, but it doesn't seem to be created with the properties and methods (like AddItem/New) and when I plop on a VB6 form it doesn't look like a combobox. Granted I am newbie working way over my head, by why would the ActiveX control wizard ask me which control to inherit from if it isn't going to give me _roughly_ the same functionality? Can anyone point me in a di...

subclassing CComboBox
compiler: VC++ 6.0 SP 6, running XP Pro SP 2. I subclassed CComboBox into CMyComboBox, then setup up event handlers for several of the reflected events -- one being CBN_CLOSEUP reflected event. I have an object of type CMyComboBox in an MFC program, which also needs to catch the CBN_CLOSEUP event. I used ClassWizard to create all event handlers. Problem: The event handler in CMyComboBox works ok, but the handler in the application program never gets called. Is there a way around this problem? I tried posting a message to the parent window but that didn't seem to work either (pare...

UpdateData and CStatic
I have written a CStatic-derived control but UpdateData seems not to work with it while SetWindowText does. What exactly happens when you do UpdateData(False) in a CDialog that has CStatic controls ? Nothing happens! As far as I know UpdataData only works on CEdit. "Vince" wrote: > I have written a CStatic-derived control but UpdateData seems not to work > with it while SetWindowText does. > What exactly happens when you do UpdateData(False) in a CDialog that has > CStatic controls ? > > > UpdateData causes the DoDataExchange function to be called. ...

Moving subclasses to different classes
I'm having trouble figuring out how to move subclasses to different classes (to re-assign budget categories to differnt umbrella budget areas). I see a "MOVE" button at the bottom of the list of Classes but can't figure out how to make it active. Anyone know the secret to moving classes without deleting them, recreating them under a new high level class, and re-assigning the transactions? Thanks in Advance!! Never mind -- you just delete the class and ask it to reassign things to a new subclass bucket. PRODUCT WISHLIST: Have the "MOVE" button active...

Subclassing AfxControlBar80su
I have a CDialogBar derived class which has a bitmap background texture. The parent's wndclass is AfxControlBar80su which still displays in gray. I'd like to give it the same background as the dialog bar and I thought it could be done by subclassing and handling the appropriate messages. But how can that be done? TIA, Hans Subclass CDialogBar and override OnPaint would be my first guess as to how to do it. The AfxControlBar80su is probably not relevant here. joe On Mon, 30 Jul 2007 01:16:15 +0200, Hans-J. Ude <news@hajue-ude.de> wrote: >I have a CDialogBar derived c...

subclassing a CTreeCtrl
All, I'm trying to subclass a CTreeCtrl control with a CHeaderCtrl derived class to obtain the result as in (http://users.pandora.be/bart.de.lathouwer/Untitled-1.jpg) I would subclass the CTreeCtrl derived class to be able to draw 'over' both the header and CTreeCtrl surface. When I subclass my CTreeCtrl derived class it reports that it is already attached. My Ctrl's live in a CWnd derived class. Question: What is the correct way to subclass my CTreeCtrl with my HeaderClass to be able to draw "over" both classes? If not possible what is an alternative? (apart from ...

Subclass question
Hi, I am writing an app in which I have a dialog bar (IDD_DLGBAR) at the top of the MDI frame window besides the standard toolbar. The dialog bar contains several controls. One of them is a combo box with id IDC_SEARCHBOX. I also created a class CSearchBox (derived from CComboBox) to process keyboard messages. My question is how do I link the combo box in the dialog bar with CSearchBox class so I can capture keyboard events (i.e., PreTranslateMessage)? Thanks in advance. >Hi, I am writing an app in which I have a dialog bar (IDD_DLGBAR) at the top >of the MDI frame window beside...

Subclass Help
During the desing of my app, I realized that I would need to have a combobox with a set of pre-defined values (collected from a database). This combobox will be used in many dialogs and for that, I decided to derive my own class. I want the combobox to be populated when created, but I can't figure out how to make it work with DDX. If I "create" it manually, I can do this in "OnCreate," but I'm attaching to a dialog. I don't know what gets called when DDX does the attaching. Any ideas? Thanks in advanced. Eddie. "Eddie Pazz" <drpazz@hotmail...

SHBrowseForFolder Subclassing.
I would like to change the name of the "cancel" button. Is that possible with Subclassing, Superclassing, etc.? ....Bruce Maybe this article can help you: http://www.codeproject.com/dialog/browse_for_folder_dialog.asp -- Mav Rossi "Bruce Arnold" <b_a_r_n_o_l_d@b_l_a_s_t.n_e_t> ha scritto nel messaggio news:cka5tv4rf6mq086b1nf6t6gom5rgds0a33@4ax.com... > I would like to change the name of the "cancel" button. Is that > possible with Subclassing, Superclassing, etc.? > ...Bruce > > And this too: http://www.codeproject.com/dialog/browse...

Re: Subclassing
Hi All I wish to create my own control for subclassing. The control will essentially contain some simple text and some minor graphics. No real control functionality is required. The question is should I derive this new control from an existing control, say CButton, or directly from CWnd? Thanks in advance LarryM wrote: > Hi All > > I wish to create my own control for subclassing. The control will > essentially > contain some simple text and some minor graphics. No real control > functionality is required. > > The question is should I derive this new control...

flickering free and transparent CStatic
Hi, I am currently trying to write a very simple CStatic derived control. It has to be flicker free and transparent. I mean by transparent that if there is a bitmap under the Cstatic we will see it. I have achieved to do a transparent CStatic but that flickers and one flicker free but not transparent. The problem is I am using the CMemDC (by Keith Rule available on code project) but as someone said the class is assuming the background is Opaque by filling in the background of the DC.(FillSolidRect(m_rect, pDC->GetBkColor());) But it should check the BK mode instead and do somethin...

Subclassing controls
Hi! I'm trying to create a custom control with custom NC area, but there's an odd problem: When I create the control using .Create(...), its all fine, but when I subclass the control, the NC messages are never sent! Anyone knows why this happens?? Tnx... >I'm trying to create a custom control with custom NC area, but there's an >odd problem: >When I create the control using .Create(...), its all fine, >but when I subclass the control, the NC messages are never sent! Which WM_NC* messages in particular? Presumably the WM_NCCREATE message won't be caught...

questions of subclassing
hi all I derieved a button class called cmybutton, I want to replace all button in my application with cmybutton so I use subclass but the question is, if the button is created by my resource templates, it works, but failed in other resource templates such as Message Boxs' buttons. That is, if I use AfxmessageBox to display a dialog box, the buttons in the dialog didn't display it seems the subclassing doesn't work what can I do many thanks That's because you cannot subclass messagebox buttons. Subclassing in MFC works only because it is a fiction maintained by MFC ...