|
-
April 22nd, 2002, 10:14 AM
#1
How to enable buttons in my view ?
Hi everybody,
Here a strange problem for me.
In the OnInitialUpdate of my CView class, I disable buttons and control lists because no data is loaded.
When the user opens a file, in my CMyDoc::Serialize function, I tell my view to enable buttons. But it doesn't work. Look at this code.
void CMyDoc::Serialize(...)
{
if(!ar.IsStoring())
{
...
POSITION pos = GetFirstViewPosition();
CMyView* pView = (CMyView*) GetNextView(pos);
pView->EnableTheControls();
}
}
...
void CMyView::EnableTheControls()
{
CButton* pButton = (CButton*) GetDlgItem(IDC_BUTTON);
pButton->EnableWindow(TRUE);
}
The code below doesn't work, the controls are still disable. Can someone tell me why ? I try the UpdateWindow() function also in the CMyView function but I don't get anything more. Please help !
-
April 22nd, 2002, 11:24 AM
#2
Re: How to enable buttons in my view ?
Put breakpoints and observe if they are getting called in the right sequence. Step through your code and verify that EnableTheControls() is being called.
Rating Helps!!
þ|êâšë rä??*è rëþ|ïëš ??*hª??* hë|þëd
-
April 22nd, 2002, 11:29 AM
#3
Re: How to enable buttons in my view ?
check if u have disabled the buttons in the base class and enabling them in the derived class.
-
April 22nd, 2002, 11:31 AM
#4
Re: How to enable buttons in my view ?
The correct way to do this is to handle the OnSyncToDoc() message in your view. In OnSyncToDoc() you need to add your view to the document, and then this is where you will want to disable/enable your buttons.
LRESULT CYourClass::OnSyncToDoc(WPARAM wParam, LPARAM lParam)
{
CDocument* pNewDoc = lParam;
CDocument* pDoc = NULL;
BOOL bClosing = (BOOL)wParam;
//newdoc may be NULL
ASSERT_VALID(pNewDoc)
CDocument* pCurDoc = GetDocument();
if(pNewDoc)
//If we have a new doc use it.
pDoc = pNewDoc;
else
{
//Otherwize, use the current doc.
if(pCurDoc)
pDoc = pCurDoc;
}
if(bClosing)
{
//pNewDoc != pCurDoc if already changed to doc of another Eds4View
if(pCurDoc && (pNewDoc == pCurDoc || !pNewDoc))
{
pCurDoc->RemoveView(this);
UpdateToDoc();
}
EnableTheControls(FALSE) //Disable
}
else if(pNewDoc != pCurDoc)
{
if(pCurDoc)
pCurDoc->RemoveView(this);
if(pNewDoc)
{
pNewDoc->AddView(this);
EnableTheControls();
}
}
return 0; //result has no meaning
}
Hope that helps! Good luck.
Wade
-
April 23rd, 2002, 02:45 AM
#5
Sorry, I can't do it
Hi,
Thanks for your help. I can't find any documentation above the OnSyncToDoc function.
And I cannot compile it correctly because the UpdateToDoc function doesn't exist.
Can you give me more details above your code please ? Thx.
-
April 23rd, 2002, 03:05 AM
#6
Another bug
Another bug in my program.
In the OnInitialUpdate function of my view class, I add columns in a list control. When the user (me) opens a file, this function is called once again and it adds once again columns in the list control. Of course, I can remember if it is the first time or not that the function is called, but I would like to know if this is normal or not.
-
April 23rd, 2002, 03:35 AM
#7
I just understand the problem now
Well, I can understand why the controls can't be enabled in my program.
It's simply because I disable them in the OnInitialUpdate function of my view class. But I didn't know that this function is called each time a user opens a file. So, even if I enable them in another function, OnInitialUpdate is called after all and disable the controls.
Where can I initialize my controls if OnInitialUpdate is called not one time (as I thought first) but many times during the execution of the application ?
Thx.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|