From: bernd on 3 Jun 2010 09:12 Hi, I want to modify some CButtons in the OnCreate() method of the class (CMainFrame : public CFrameWnd) int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { m_btn1.SetButtonImg(IDC_BUTTON1, IDC_BUTTON1); m_btn1.SetButtonText("Test"); m_btn1.SetFont("Arial",16); m_btn1.SubclassDlgItem(IDOK, this); return 0; } But these information are not taken place, because the DrawItem method (class CButton) will never be called. Which steps do I have to do - getting called the DrawItem function (Cbutton-class)? m_btn1 is created within a dialog-field in the resource editor . best regards Bernd
From: Seetharam on 3 Jun 2010 10:07 Do you have your button property set to OwnerDrawn = TRUE? You could do this: class YourDialog { [...] MyButton m_Button; }; class MyButton : public CButton { DECLARE_DYNAMIC(MyButton) public: MyButton(); // standard constructor virtual ~MyButton(); protected: DECLARE_MESSAGE_MAP() public: virtual void DrawItem(LPDRAWITEMSTRUCT /*lpDrawItemStruct*/); }; IMPLEMENT_DYNAMIC(MyButton, CButton) MyButton::MyButton() : CButton() { } MyButton::~MyButton() { } BEGIN_MESSAGE_MAP(MyButton, CButton) END_MESSAGE_MAP() // MyButton message handlers void MyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { //your drawing code goes in here... CRect rc = lpDrawItemStruct->rcItem; CBrush br; br.CreateSolidBrush(RGB(255,0,0)); ::FillRect(lpDrawItemStruct->hDC,rc,br); } -Seetharam
From: Scott McPhillips [MVP] on 3 Jun 2010 10:16 "bernd" <bernd.schuster12(a)googlemail.com> wrote in message news:2ab6b65b-fcaf-46ae-b0df-a1b3cc63475c(a)c22g2000vbb.googlegroups.com... > Hi, > > I want to modify some CButtons in the OnCreate() method of the > class (CMainFrame : public CFrameWnd) > > int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) > { > m_btn1.SetButtonImg(IDC_BUTTON1, IDC_BUTTON1); > m_btn1.SetButtonText("Test"); > m_btn1.SetFont("Arial",16); > m_btn1.SubclassDlgItem(IDOK, this); > > return 0; > } > > But these information are not taken place, because the DrawItem method > (class CButton) will never be called. > > Which steps do I have to do - getting called the DrawItem function > (Cbutton-class)? > > m_btn1 is created within a dialog-field in the resource editor . > > best regards > Bernd If the buttons are created within a dialog resource why are the CButton member variables in CMainFrame? There are no buttons in a CMainFrame. The CButton member variables must be in the class of their parent dialog. None of this has anything to do with DrawItem. It is used only with buttons that have the owner-draw style, which means buttons that you are going to paint with your own custom code. -- Scott McPhillips [VC++ MVP]
From: Joseph M. Newcomer on 3 Jun 2010 11:04 See below... On Thu, 3 Jun 2010 06:12:17 -0700 (PDT), bernd <bernd.schuster12(a)googlemail.com> wrote: >Hi, > >I want to modify some CButtons in the OnCreate() method of the >class (CMainFrame : public CFrameWnd) > >int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) >{ > m_btn1.SetButtonImg(IDC_BUTTON1, IDC_BUTTON1); **** Why is it that everyone has this fixation that names like "IDC_BUTTON1" and m_btn1 have meaning? This button probably does something useful to you, and you should rename the ID to be meaningful (e.g., IDC_PAINT_BITS_PURPLE, or whatever it is supposed to do) and give its control variable a meaningful name like c_PaintBitsPurple. > m_btn1.SetButtonText("Test"); > m_btn1.SetFont("Arial",16); > m_btn1.SubclassDlgItem(IDOK, this); **** What is with the SubclassDlgItem? Why is your button not declared CMyOwnButton m_btn1; this is what should be done. You should never write SubclassDlgItem in a piece of MFC code! Note that this is in the CMainFrame, and I see no code to actually create a button here! How did it get created? joe **** > > return 0; >} > >But these information are not taken place, because the DrawItem method >(class CButton) will never be called. **** The CButton::DrawItem I believe does an ASSERT(FALSE); > >Which steps do I have to do - getting called the DrawItem function >(Cbutton-class)? > >m_btn1 is created within a dialog-field in the resource editor . **** All of the code, above, is suspicious. You didn't say you are using a CFormView. joe **** > >best regards >Bernd > Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Joseph M. Newcomer on 3 Jun 2010 15:00 See below... (I had to rush to an appointment and didn't have time to finish answering the question) On Thu, 3 Jun 2010 06:12:17 -0700 (PDT), bernd <bernd.schuster12(a)googlemail.com> wrote: >Hi, > >I want to modify some CButtons in the OnCreate() method of the >class (CMainFrame : public CFrameWnd) > >int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) **** What are we doing in CMainFrame? This doesn't make sense. If you are using a CFormView in SDI, it will be in your CView-derived class, in which case, OnCreate is *always* the wrong place to do this! If it is a dialog-based app, OnCreate is *always* the wrong place to do this. In a CFormView-derived class, you will put the code to manipulate the button state in the OnInitialUpdate handler. In a CDialog-derived class, you will put the code to manipulate the button in OnInitialUpdate. NEVER in OnCreate! **** >{ > m_btn1.SetButtonImg(IDC_BUTTON1, IDC_BUTTON1); **** Presumably you have a bitmap or icon with the ID IDC_BUTTON1. But again, why did you use the silly names the Dialog editor give you instead of choosing names with meaning. Since you set the text as "Test", it would have made more sense to change the ID to IDC_TEST. **** > m_btn1.SetButtonText("Test"); > m_btn1.SetFont("Arial",16); **** CWnd::SetFont only takes a pointer to a font and an optional BOOL which defaults to TRUE. So presumably this is a method of your class. If it is one of your methods, presumably you would have shown us the code. Likewise, SetButtonText (why use a special method when "SetWindowText" would do just as well? And why not set the text in the dialog editor, instead of committing the serious implmentation error of putting a hardwired English word into the source code? And why use "Test" when you should have said _T("Test")? **** > m_btn1.SubclassDlgItem(IDOK, this); *** As I already pointed out, you should never write a SubclassDlgItem call in an MFC program. And if your concern is IDC_BUTTON1, what did you expect that subclassing IDOK would do for this button? **** > > return 0; >} > >But these information are not taken place, because the DrawItem method >(class CButton) will never be called. **** Actually, since there is almost nothing correct in the code above (starting with and directly related to it being in OnCreate), I'm not surprised that nothing works. Avoid OnCreate handlers in general. **** > >Which steps do I have to do - getting called the DrawItem function >(Cbutton-class)? > >m_btn1 is created within a dialog-field in the resource editor . **** Why is it not called m_test? Would make more sense, given the caption... joe **** > >best regards >Bernd > Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
|
Pages: 1 Prev: OnAccept getting socket handle Next: Vista/VS2008 Cannot open type library file: ’msxml.dll’ |