|
I am trying to use CObject *pHint in CView OnUpdate.
Here is my instantiation of CObject derived class:
....
m_C_Parameters = new C_Parameters(); // CObject base class
VERIFY(m_C_Parameters);
m_C_Parameters->hello = 10; // set test variable
m_CCCC_ParserDoc->UpdateAllViews(NULL,RED,m_C_Parameters);
....
Variable int hello is declared in C_Parameters();
Here is my OnUpdate override in CView dereived class:
void C_List_View_::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
int test = pHint->hello;
.......
However,
the compiler gets me an error:
error C2039: 'hello' : is not a member of 'CObject'
f:\program files\microsoft visual studio\vc98\mfc\include\afx.h(666) : see declaration of 'CObject'
What did I missed?
Thanks for yor help.
Vaclav
<div class="ForumMod">modified on Friday, May 16, 2008 1:01 PM</div>
|
|
|
|
|
You need to cast pHint to C_Parameters* before you can call hello on it.
Henry David Thoreau wrote: Beware of all enterprises that require new clothes.
|
|
|
|
|
Dang, Michael, you beat me to the answer by a minute.
Kelly Herald
Software Developer
|
|
|
|
|
You forgot to cast pHint to your derived class.
C_Parameters *pParameters = (C_Parameters*)pHint;
int test = pParameters->hello;
Kelly Herald
Software Developer
|
|
|
|
|
Thanks a milion! I hope I did not start any feud between both of you!
Vaclav
|
|
|
|
|
I want to know the encoding format of .rc file in VS 2005.
It is neither in UTF-8 encoding not unicode?
So what is the encoding format?
|
|
|
|
|
It's ANSI in my environment.
Henry David Thoreau wrote: Beware of all enterprises that require new clothes.
|
|
|
|
|
Hi all,
I have a simple dialog with a combo box control, of the Drop-List type.
class CDlg : public CDialog
{
DECLARE_DYNAMIC(CDlg)
public:
CDlg(CWnd* pParent = NULL);
virtual ~CDlg();
void AddOpc() ;
enum { IDD = IDD_DIALOG1 };
protected:
virtual void DoDataExchange(CDataExchange* pDX);
DECLARE_MESSAGE_MAP()
public:
CComboBox m_cbDropList;
};
void CDlg::AddOpc()
{
CString csOpc ;
csOpc = "1st option" ;
m_cbDropList.AddString("1st option") ;
}
And the line in which a string is added makes the program crash.
Any idea??
|
|
|
|
|
is your combobox correctly constructed at that time ?
|
|
|
|
|
What do you mean?
The constructor is called correctly, and the dialog shown properly. It crashes in that precise line m_cbDropList.AddString("1st option") ; . It happens the same with cbDropList.InsertString(...)
|
|
|
|
|
Where is it called?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
My application is a .dll called from a CAM application. I'm testing the combo box, so this dialog is directly called from the dll.
|
|
|
|
|
Hence maybe the function populating the combobox is called before the dialog is actually loaded.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
I don't understand. How can that be possible??
|
|
|
|
|
Creating an instance of a CDialog class doesn't create a dialog window (and its controls). Hence you have a CComboBox variable but not the related control (i.e. window). The dialog window (and its controls) are created during DoModal call.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
oooh
that's new... thanks.
|
|
|
|
|
in the main program:
CDlg Dialog ;
Dialog.AddOpc() ;
Dialog.DoModal() ;
|
|
|
|
|
Yes, as stated, your dialog is not created at the time you try to add:
CDlg Dialog ;
Dialog.AddOpc() ;
Dialog.DoModal() ;
You need to call the AddProc from within the dialog itself - perhaps during the OnInitDialog method.
Hope that helps.
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
|
|
|
|
|
If I call AddOpc() in the constructor I get exactly the same error.
|
|
|
|
|
the constrols are not constructed yet in the dialog constructor. you have to do all this in the OnInitDialog() method...
|
|
|
|
|
piul wrote: CDlg Dialog ;
Dialog.AddOpc() ;
Dialog.DoModal() ;
The second line is wrong since the dialog isn't yet created.
Since (due to modal nature of the dialog) you need to add strings before the DoDialog call but you can't add them directly to the combo box that isn't yet alive, hence you should modify AddOpc method to store passed strings inside a string array and use the latter to initilize the combo box inside the OnInitDialog method.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Ok!
How do I include that in OnInitDialog?? Where's that method? Do I have to overload it somehow?
(As you can tell I'm not very experienced in dialog... it's all very confusing..)
|
|
|
|
|
I give you a simple example:
void CDlg::CDlg()
{
m_iItemCount=0;
}
void CDlg::AddOpc(CString szItem)
{
if ( m_iItemCount < 10)
{
m_szItem[m_iItemCount] = szItem;
m_iItemCount;
}
}
BOOL CDlg::OnInitDialog()
{
for (int i=0; i<m_iitemcount; i++)<br="" mode="hold" /> {
m_cbDropList.AddString(m_szItem[i]);
}
return TRUE;
}
Where m_iItemCount is a CDlg int member variable and m_szItem is an array CStrings having 10 elements, also member of CDlg .
(I used a fixed size array to keep things simple).
The calling code will be
CDlg Dialog;
Dialog.AddOpc("foo");
Dialog.AddOpc("piul");
Dialog.DoModal()
To override OnInitDialog , select your CDlg class, go to the properties pane, click the overrides button, and choose <add>OnInitDialog</add> .
Hope that helps.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Ooops! It works if I call AddOpc() from an event handler of a button, for example
|
|
|
|
|
How to let CPropertyPage look like 3d?
http://cid-fbeb6373d9321a7f.skydrive.live.com/self.aspx/Questions/sheetandpage.rar
I put my source code in the web.
There are two project in the rar file.
First project called "C25 ListProperty" has 3d-look property-page. That is sample of a book about vc++ 6.0 MFC(chinese tradition lang)
Second project called "ShadowTool" has flat-look property-page.
I create "ShadowTool" in vc++ 2005.
The difference between the two projects is that the "ShadowTool" use the sheet is inherited from CPropertySheet.
|
|
|
|