|
What about Invalidate and UpdateWindow?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
I don't understand how to call Invalidate and UpdateWindow.
When I put Invalidate(); into my code I get a compiler error stating that this is an undeclared identifier. I don't understand how to get rid of that error.
Thanks
|
|
|
|
|
Are you using MFC or Win32 APIs? Can you put a code snippet and the error?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
|
Here's the more general question I have, which will answer my WM_PAINT post.
I'm using Visual C++ 6.0 MFC in an SDI application.
From another class (defined in separate .h & .cpp files) I would like to call a function called "OnViewShowTest" that is defined in the main program - MainFrm.cpp In my MainFrm.cpp, this OnViewShowTest is called when a Menu Item is clicked. I don't know how to call this same function from a function in another class to do the same thing that happens win the menu item is clicked because I don't understand what object it is associated with. Here's the code snippets
In a header file called MainFrm.h the following snippet is defined:
// MainFrm.h
class CMainFrame : public CFrameWnd
{
protected: // create from serialization only
CMainFrame();
DECLARE_DYNCREATE(CMainFrame)
// Implementation
public:
virtual ~CMainFrame();
afx_msg void OnViewShowwall();
protected: // control bar embedded members
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
// Generated message map functions
protected:
//{{AFX_MSG(CMainFrame)
afx_msg void OnViewShowTest();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
// Now the code for OnViewShowTest is in MainFrm.cpp shown as:
void CMainFrame::OnViewShowTest()
{
// TODO: Add your command handler code here
}
Now I have a function that gets called in another class (actually its in the doc class of my program). That function snippet is:
void CTestProgramDoc::OnNewjobmenu()
{
// I would like to call the OnViewShowTest() from here but I
//don't know how to set things up to do that
}
|
|
|
|
|
I think you are missunderstanding how it works. The MainFrm actually is not the best place to draw things on the "screen", this is better to be done in the CView-derived class. In Grosso Modo the main frame is the class that controls the blue title bar and the menu, not the white surface where the things come
As you are using MFC and Doc-View architechture with SDI application I would make it in other way. You should have a class called CTestProgramView as well. There is the place to handle the things that you are seeing in your application. There is where you should have to code your OnDraw code and the update can be managed with CDocument::UpdateAllViews (NULL), that will call the OnDraw on all views from the document, but as you are in a SDI programm only one view will be drawn. Or, another possibility, inside the CTestProgrammView itself, then you can use Invalidate () and UpdateWindow () as I told you in my first answer, that will "erase" the contents of the view and force it to redraw calling the OnDraw ().
BTW, if you want to make it with your structure, then you can make more or less like that:
extern CTestProgramApp theApp;
CMainFrame *pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
pFrame->OnViewShowTest ();
But as I told you... I would use the Doc-View performance, it will make things easier for you.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Thanks for the very useful and informative reply. I don't understand
where to learn about things like:
CDocument::UpdateAllViews (NULL)
other than posting a question on sites like these.
Is there some book I should have, or do I need a programming class, or what is the best way to learn about things like this and the other 1000 things I may have questions about with Visual C++ MFC
|
|
|
|
|
You are wellcome
I found some quite good pdfs on the net when I started. One was developing the same example at every chapter, just increasing the code with the new topics. It was quite good. Just take some unused time of your day and do a patient search in google with "Learn MFC", "VC++" and so on, but checking more pages than just the 3 first ones. Pay attention into the description and the end of the link, if it is a pdf you can check it out.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
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() ;
|
|
|
|