OnActivateView problem

I have a class derived from CView, say CViewA. I have controls in a
CDialogBar. when the view CViewA is activated I enable the button on
the dialogbar and when it is deactivated I disable the buttons on the
dialog bar. But i donot want the buttons to enable or disable when
there is switch between same type of view. This is creating refreshing
problem.

First the CViewA, OnActivateView is called with bActivate equal to
False, then the same function is called with bActivate equals to true.

I used the following code to find which view is getting active:-

CMainFrame *frame = (CMainFrame *)AfxGetApp()->GetMainWnd();
CMDIChildWnd* pActiveChildFrame = frame->MDIGetActive();
CView* view = pActiveChildFrame->GetActiveView();
if(bActivate==false && !(view->IsKindOf(RUNTIME_CLASS(CViewA)))
    //donot disable the buttons..

But CView retunns CViewA when its bActivate==false. So in the
OnActivateView function when bActivate==False, I donot I know which
View is getting active, so that if the same view is getting active,
then i donot do enabling/disabling of buttons ?

Is this a limitation of CView ?
0
sagkumar (32)
3/4/2008 6:07:03 AM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
1623 Views

Similar Articles

[PageSpeed] 15

Kuenga,

>I have a class derived from CView, say CViewA. I have controls in a
> CDialogBar. when the view CViewA is activated I enable the button on
> the dialogbar and when it is deactivated I disable the buttons on the
> dialog bar. But i donot want the buttons to enable or disable when
> there is switch between same type of view. This is creating refreshing
> problem.
>
> First the CViewA, OnActivateView is called with bActivate equal to
> False, then the same function is called with bActivate equals to true.

This is not the way to handle this. You should be handling your 
enable/disable code the same way it is handled for regular MFC toolbar 
buttons.

However, according to your requirements, I don't see how this is a problem. 
If OnActivateView is called with bActivate == FALSE, then you should disable 
the controls. And if it's called again with bActivate == TRUE, then you 
should enable the controls. The result could be a flicker but it seems like 
the result is exactly what you're asking for.

If the problem that you mean some of the same type of views should enable 
the controls while others should not, simply have some way to determine if 
the current view should enable the controls and then check that when 
bActivate == TRUE.

> But CView retunns CViewA when its bActivate==false. So in the
> OnActivateView function when bActivate==False, I donot I know which
> View is getting active, so that if the same view is getting active,
> then i donot do enabling/disabling of buttons ?

If bActivate == FALSE, then no view is getting activated *at that point*. 
Why not just wait until bActivate == TRUE?

-- 
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com

0
jwood (1291)
3/4/2008 4:56:16 PM
On Mar 4, 9:56=A0pm, "Jonathan Wood" <jw...@softcircuits.com> wrote:
> Kuenga,
>
> >I have a class derived from CView, say CViewA. I have controls in a
> > CDialogBar. when the view CViewA is activated I enable the button on
> > the dialogbar and when it is deactivated I disable the buttons on the
> > dialog bar. But i donot want the buttons to enable or disable when
> > there is switch between same type of view. This is creating refreshing
> > problem.
>
> > First the CViewA, OnActivateView is called with bActivate equal to
> > False, then the same function is called with bActivate equals to true.
>
> This is not the way to handle this. You should be handling your
> enable/disable code the same way it is handled for regular MFC toolbar
> buttons.
>
> However, according to your requirements, I don't see how this is a problem=
..
> If OnActivateView is called with bActivate =3D=3D FALSE, then you should d=
isable
> the controls. And if it's called again with bActivate =3D=3D TRUE, then yo=
u
> should enable the controls. The result could be a flicker but it seems lik=
e
> the result is exactly what you're asking for.
>
> If the problem that you mean some of the same type of views should enable
> the controls while others should not, simply have some way to determine if=

> the current view should enable the controls and then check that when
> bActivate =3D=3D TRUE.
>
> > But CView retunns CViewA when its bActivate=3D=3Dfalse. So in the
> > OnActivateView function when bActivate=3D=3DFalse, I donot I know which
> > View is getting active, so that if the same view is getting active,
> > then i donot do enabling/disabling of buttons ?
>
> If bActivate =3D=3D FALSE, then no view is getting activated *at that poin=
t*.
> Why not just wait until bActivate =3D=3D TRUE?
>
> --
> Jonathan Wood
> SoftCircuits Programminghttp://www.softcircuits.com

Thanks Jonathan for your time..I had tried that way before but it
didnot solve my problem.

I have a ListBox Control on the dialog bar, which I cannot handle like
toolbars.

My document is same but different views. So when different views of
the same document is being switched, I donot want to disable the
buttons. But in the OnActivateView function, when bActivate =3D=3D FALSE,
if i write the following code

CMainFrame *frame =3D (CMainFrame *)AfxGetApp()->GetMainWnd();
CMDIChildWnd* pActiveChildFrame =3D frame->MDIGetActive();
CView* view =3D pActiveChildFrame->GetActiveView();

it gives me the view that is getting deactivated. Not the view that is
getting activated.

If in the OnActivateView when bActivate =3D=3D FALSE, i get the view which
is being activated then I can put the following check

if(bActivate=3D=3Dfalse && !(view->IsKindOf(RUNTIME_CLASS(CViewA)))

then enable the buttons. And my problem will be solved ..

So my question is in OnActivateView function when bActivate=3D=3Dfalse,
how do I know which view is getting active ?


0
sagkumar (32)
3/5/2008 3:48:55 AM
On Mar 5, 8:48=A0am, Kuenga <sagku...@gmail.com> wrote:
> On Mar 4, 9:56=A0pm, "Jonathan Wood" <jw...@softcircuits.com> wrote:
>
>
>
>
>
> > Kuenga,
>
> > >I have a class derived from CView, say CViewA. I have controls in a
> > > CDialogBar. when the view CViewA is activated I enable the button on
> > > the dialogbar and when it is deactivated I disable the buttons on the
> > > dialog bar. But i donot want the buttons to enable or disable when
> > > there is switch between same type of view. This is creating refreshing=

> > > problem.
>
> > > First the CViewA, OnActivateView is called with bActivate equal to
> > > False, then the same function is called with bActivate equals to true.=

>
> > This is not the way to handle this. You should be handling your
> > enable/disable code the same way it is handled for regular MFC toolbar
> > buttons.
>
> > However, according to your requirements, I don't see how this is a probl=
em.
> > If OnActivateView is called with bActivate =3D=3D FALSE, then you should=
 disable
> > the controls. And if it's called again with bActivate =3D=3D TRUE, then =
you
> > should enable the controls. The result could be a flicker but it seems l=
ike
> > the result is exactly what you're asking for.
>
> > If the problem that you mean some of the same type of views should enabl=
e
> > the controls while others should not, simply have some way to determine =
if
> > the current view should enable the controls and then check that when
> > bActivate =3D=3D TRUE.
>
> > > But CView retunns CViewA when its bActivate=3D=3Dfalse. So in the
> > > OnActivateView function when bActivate=3D=3DFalse, I donot I know whic=
h
> > > View is getting active, so that if the same view is getting active,
> > > then i donot do enabling/disabling of buttons ?
>
> > If bActivate =3D=3D FALSE, then no view is getting activated *at that po=
int*.
> > Why not just wait until bActivate =3D=3D TRUE?
>
> > --
> > Jonathan Wood
> > SoftCircuits Programminghttp://www.softcircuits.com
>
> Thanks Jonathan for your time..I had tried that way before but it
> didnot solve my problem.
>
> I have a ListBox Control on the dialog bar, which I cannot handle like
> toolbars.
>
> My document is same but different views. So when different views of
> the same document is being switched, I donot want to disable the
> buttons. But in the OnActivateView function, when bActivate =3D=3D FALSE,
> if i write the following code
>
> CMainFrame *frame =3D (CMainFrame *)AfxGetApp()->GetMainWnd();
> CMDIChildWnd* pActiveChildFrame =3D frame->MDIGetActive();
> CView* view =3D pActiveChildFrame->GetActiveView();
>
> it gives me the view that is getting deactivated. Not the view that is
> getting activated.
>
> If in the OnActivateView when bActivate =3D=3D FALSE, i get the view which=

> is being activated then I can put the following check
>
> if(bActivate=3D=3Dfalse && !(view->IsKindOf(RUNTIME_CLASS(CViewA)))
>
> then enable the buttons. And my problem will be solved ..
>
> So my question is in OnActivateView function when bActivate=3D=3Dfalse,
> how do I know which view is getting active ?- Hide quoted text -
>
> - Show quoted text -

Is there any work around for this problem ?
0
sagkumar (32)
3/10/2008 4:19:17 AM
"Kuenga" <sagkumar@gmail.com> wrote in message 
news:1a27cd53-04f6-4e73-8786-d0cf72ee83f5@i12g2000prf.googlegroups.com...
On Mar 5, 8:48 am, Kuenga <sagku...@gmail.com> wrote:
>
> Thanks Jonathan for your time..I had tried that way before but it
> didnot solve my problem.
>
> I have a ListBox Control on the dialog bar, which I cannot handle like
> toolbars.
>
> My document is same but different views. So when different views of
> the same document is being switched, I donot want to disable the
> buttons. But in the OnActivateView function, when bActivate == FALSE,
> if i write the following code
>
> CMainFrame *frame = (CMainFrame *)AfxGetApp()->GetMainWnd();
> CMDIChildWnd* pActiveChildFrame = frame->MDIGetActive();
> CView* view = pActiveChildFrame->GetActiveView();
>
> it gives me the view that is getting deactivated. Not the view that is
> getting activated.
>
> If in the OnActivateView when bActivate == FALSE, i get the view which
> is being activated then I can put the following check
>
> if(bActivate==false && !(view->IsKindOf(RUNTIME_CLASS(CViewA)))
>
> then enable the buttons. And my problem will be solved ..
>
> So my question is in OnActivateView function when bActivate==false,
> how do I know which view is getting active ?- Hide quoted text -
>
> - Show quoted text -


> Is there any work around for this problem ?

Why is this a problem?  When bActivate is false your code should return a 
pointer to the view being deactivated, that's why bActivate is false.  One 
question would be why are you going through all those hoops to get a pointer 
to the view when it is being passed to OnActivateView?

void CViewA::OnActivateView( BOOL bActivate, CView* pActivateView, CView* 
pDeactiveView )
{
    // Is it just because the application regained focus (from user 
switching applications)
    if ( pActivateView == pDeactiveView )
        return;    // Yep, don't need to do anything...

    // Do we need to disable anything...
    if ( bActivate == FALSE )
    {
        // Maybe, let's do some more checking...
        if ( pDeactivateView == NULL )
        {
            // Not sure if this would actually happen but I suppose it could 
if the
            // application was being shutdown with only the one view open...
            // do whatever makes since in your app here...
        }
        else if ( !(pActivateView->IsKindOf(RUNTIME_CLASS(CViewA))) &&
            (pDeactivateView->IsKindOf(RUNTIME_CLASS(CViewA))) )
        {
            // Yep, new view is not derived from CViewA but the old one was 
so disable the stuff...
        }
    }
    else
    {
        if ( (pActivateView->IsKindOf(RUNTIME_CLASS(CViewA))) )
        {
            // Activating a CViewA derived class, enable the dialog bar 
stuff...
        }
    }
}

This is off the top of me head so you will need to adjust it to your 
needs...

-- 
============
Frank Hickman
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply. 


0
3/10/2008 6:27:06 AM
Reply:

Similar Artilces:

Excel Problem
I have a 23.8 meg excel 2000 spreadsheet set for manual calculation saved to my local hard drive. Every time I try to open it, it takes forver and sometimes never opens but I do not get any error messages, let me just tell you that I am running a P4, 1 GB memory, Office 2K with SP3, and nothing else running when I try to open it. As I said it is set for manual calculation, and it is cleared to not auto calculate when opening or closing. Any idea's as to why this is happening? -- Todd I don't know why you're having this problem but I would like to point something out for w...

do i have a problem??
A few weeks ago my exchange 2003 server started messing me around. I posted here and got a few pieces of help, but I think that I fixed that issues by applying several exchange specific patches, then server 2003 SP1, then enabling the directory filtering and the tarpit with a 5 second timeout. The box has stopped crashing (previously it would stop delivering main to the mailboxes, filling up the queues with many thousands of messages) Now I have a new problem. In the last week I have started getting memory errors from the system notification. I found a previous posting that offered u...

IE8
Hi I am having problems using IE8 on XP SP3. Basically the browser is unresponsive regularly, hangs regularly on exit (especially after downloads and multi-tabbing). Poor performance at times as well. I am a little dissapointed I must say. For example, I can no longer browse to CodePlex - HTTP Status is: 400 Bad Request. I know it's the browser because none of these problems happen whatsoever when using Firefox. I have tried clearing all History and temp files, cookies etc.... no effect. Perhaps in the next service pack someone can sort this out once and for all. ...

Open relay problem
We are running Exchange 5.5 SP4 on NT4SP6 with GFI mail essential 3.3. Our server is sending hundreds of spam mails everyday using our domain name. I followed the advise from TechNet to tick the following check boxes on connections in IMS properties; 1. Hosts and clients that successfully authenticate. 2. Hosts and clients with these IP_addresses Our server is still sending hundreds of spam. Can anybody help? try unchecking the authentication checkbox, spammers might use an account on your server to authenticate and send mail Gyula Karakas orf support www.vamsoft.com/orf "C...

Excel 2003 Problems with charting
Has anyone come across the following problem with Excel 2003. I am using Pivot charts and they work fine in Excel 2000. But in 2003 the stacked columns lose their colour or don't colour in properly. Also if I add a gradient background it produces a very odd appearance. Is this a known Bug? If so is there a fix? I don't see any problem with the colour in Excel 2003 pivot charts, compared to earlier versions. You could check the printer manufacturer's web site, and download the latest copy of the print driver for your operating system. For example, if for an HP printer, check he...

Help needed with form problem
Workbook contains several forms of varying style and function. One form shows the results of 10 recent tests in a countdown fashion, showing just the results of one test, followed by a one-second delay, followed by just the results of the second test, and so on until the result of each of the 10 tests has been shown. Then the program proceeds on to the next step by calling up a different form. The problem . . . Sometimes when the program starts running one or two of the forms are blanked out ("white" with just the top header showing). The forms continue to function within the ...

Combo Box Sorting Problem
Hello experts, My report deals with data for wells. I have a combo box where the user will choose the name of the well, then it will display the appropriate report. It works great. However, the list in teh combo box shows as follows: paramount 1 denver Atlas Bailey 1 Bailey 5 Bell 10 Bell 12 Bell 14 Bell 17 Bell 2 Bell 5 Bell 6 Borie 1 BELMOT 1 BELMOT 12 BELMOT 2 BELMOT 3 Obviously, the issues are: upper/lower case not consistent; the numbers next to names are not sorted properly. Is there a code that would allow no case sensitivity and sort names with numbers appropriately? I a...

Problems with excel please help
I am new to excel and can't find an answer to my problem i'm sure its easy. I have a cell/field with about 100 numbers in which i want to copy which ive done and then multply it by 100 and display the result automaticallyhow can this be done. If you just want to multiply cell A1 by 100 and put the result in B1, you need the following equation in B1 =A1*100 "Paul Moseley" wrote: > I am new to excel and can't find an answer to my problem i'm sure its > easy. I have a cell/field with about 100 numbers in which i want to > copy which ive done and then multp...

commandbar problems
On My PC with Excel 2000, I have developed an Excel workbook with a custom command bar. The resulting 'xls' file is in a folder on our network and available to everyone in our company. When opening this Excel workbook on other PCs in my office with Excel 2003 or Excel 2000, the custom command bar is missing some of the controls and appears to be an older version of the one that shows on my own PC where the command bar was created and where any modifications are performed. I believe the problem is related to the command bars being stored locally along with the Excel applicatio...

Vista Bussines and Framwork CRM Install Problem
hi i try to install the crm 3.0 outlook client on my vista bussines (last update)but it will not work ,setup says framwork 1 or 1.1 is need but i have install framwork 3.0. i try deinstall framwork 3 and reistall but not work. cd relase is x13-09468 thx for help You need to install the .NET Framework 1.1 (As MS Dynamics CRM uses .NET 1.1) and you probably want to check on .NET 2.0 as well. -- Anne Stanton, MBSCP-CRM President, The Norwich Group Principal, GlobalBrain LLC The CRM Lady at www.CRMLady.com ----------------------------------------------------------------------------------...

WM_MOUSEWHEEL problem!
I created a window as following /////////////////////code m_pSecondWnd = new CWnd; m_pSecondWnd->Create (m_lpszSecondClassName, NULL,WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL, CRect (0,0,0,0),this, 1005); OldProc = (WNDPROC)::GetWindowLong(m_pSecondWnd->m_hWnd, GWL_WNDPROC); ::SetWindowLong (m_pSecondWnd->m_hWnd, GWL_WNDPROC, (long)ScrollProc); /////////////////////code ends However, I cannot catch the WM_MOUSEWHEEL message in the ScrollProc. Why? No one know this? Please google the 100,000 or so web pages on making good newsgroup posts. -- - Mark...

Exel Problems!
Any help with my 2 problems would be much appreciated. 1) I have selected 'wrap text' format for a number of cells - however the text is not wrapping and does not display. The cell does not extend and the text cannot be seen. 2) I have saved my spreadsheet with another one open - now I have 'Links' to other pages. When I open the spreadsheet I get a message notifying me of this. I have gone to the Edit - Links option - which lets me see the links. However I really want to delete them. Cheers, Phil Hi 2): goto: http://oaltd.co.uk/MVP/Default.htm and search for Findlin...

Problem with OnActivateView
Hi all... This is a MDI Application in Visual C++ 6.0 When a user open more than one document of the same template, the Window menu is filled with all opened documents, giving the chance to make active any document the user wants (to make it on top of the other documents). When that action occurs, depending on which document view was activated, a CTreeCtrl node has to be selected (this tree control is in a dialog bar). To accomplish it, I used OnActivateView so that when the view get activated, OnActivateView selects the tree control node if bActivate parameters is TRUE. Well.. all works p...

tough IF problem
I download a file into excel & have to deal with the fact that it does not come out in a particular order. So I have data as: B1 C1 D1 E1 410 410-xxx data Result My formula states =IF(LEFT(C1,3)=RIGHT(B1,3),E1,"") and I get the answer "Result" However, the download also places info as follows: B1 C1 D1 E1 A222XXX HF01 Result 6.5 I have done an interim fix which will result in a long winded route of getting all the "Results" in 1 column but is there any way of having a single cell formula that will pick up both "Results" w...

Report Problem with Access 2007
I have a report that I created with Access 2003 that is 8 1/2 x 3 1/2 inches. It worked great in Access 2003, but in Access 2007 it prints the 1st page ok (info centered where I want it), but prints the info on the 2nd page moved to the top of the page (almost like there is no margin). The strange thing is that after the bad 2nd page, all other pages print just fine.?.? The pages selected to print are entered in a range from a query. Thanks WWV ...

Shadow Copy problem
I am running CRM 1.2 on sbs2k3. Shadow copy isnt working because of the SQL server running on the same SBS machine. Does anyone know how to fix this? repost to microsoft.public.windows.server.sbs "Jeremiah" <anonymous@discussions.microsoft.com> wrote in message news:216a01c427a6$f71a0af0$a601280a@phx.gbl... > I am running CRM 1.2 on sbs2k3. Shadow copy isnt working > because of the SQL server running on the same SBS > machine. Does anyone know how to fix this? ...

Function problem
Please help.I am new to VBA. I want to create a public function and embed it in my startup splash form that quits the application if date() > mydate unless a user puts in a value(input box in the function will take this value and assign it to a variable). Please help. hi, niclive@gmail.com wrote: > Please help.I am new to VBA. > I want to create a public function and embed it in my startup splash > form that quits the application if date() > mydate unless a user puts > in a value(input box in the function will take this value and assign > it to a variable). Public S...

Problem with sending PO as PDF
I have one user who all of a sudden is not able to email Purchase Orders as PDF. He can do it as text. He can send other reports (such as Service calls) as PDF. All other users can do it either as text or PDF The client is Outlook 2003 and the full Adobe PDF package is installed. Any ideas? TIA What version of GP are you using? What version of Adobe? "Jeff Metcalf" wrote: > I have one user who all of a sudden is not able to email Purchase Orders as > PDF. > He can do it as text. > He can send other reports (such as Service calls) as PDF. > All other users can ...

Boot problem
After installing and removing the program "Paragon Partition manager 10.0 Personal" I got a hold-up in the PC upstart. In Dos booting I see now a black page with a text message lines: drive 0 : primary 00 Vista/2008/7 NTFS and primary 00 Linux. Insert startup disk in floppy drive and press F2 to run setup. By pressing "enter" Windows 7 Professional starts and runs further normally. Is there any suggestion to remove this startup page Search for EasyBCD.exe and download and run it. You will be presented with options to edit/modify your boot condition...

outgoing SMTP problem
I have a test Exchange 2003 server, running on Windows 2003 server with a weird problem. There have been instances of this server sending multiple copies of files that have large attachments, something that has been seen on another similar instance on Exchange 2003. However my current problem is that all outgoing SMTP queues are clear within Exchange manager. The C:\Program Files\Exchsrvr\Mailroot\Vsi 1 subdirectories are all empty, Yet if I stop and start the SMTP service - either with Exchange System manager or directly via services then the server forms an SMTP connection with ...

(CStringList)...folder_list.Find(...) problem.
Hello all, I hope this is in the right place this time.... MFC. I am trying to create a basic app with a treeview control that displays just the folders of the hard drive... This part i have achieved but with bugs (sort of) so far i have only been iterating through the HDD contents with a simple while loop but i really need to test against the drives contents - so i don't repeat the folders in my list - It displays about 50 Windows and Westwood Folders at the end of the list. Im trying to use: <CStringList variable>.Find(.....); to test weather or not the folder that is abou...

link viewer problem
First off - I am running Excel 2000. I have a workbook that has several sheets. On one sheet when I click an icon that is linked to a file on my hard drive it opens the right viewer (ACDSee). On another sheet it opens the wrong viewer(Paint Shop Pro). I have checked file associations in ACDSee, Paint Shop Pro, and Windows Explorer/ folder options/ file types. Any suggestions would be greatly appreciated as I have about 1000 links to do. Thanks in advance, Carol ...

Problems creating my own AFX_MODULE_STATE for multiple gui threads
I'm trying to convert a single gui threaded application to use multiple threads (one for each main window). I've created my own CWinThread subclass and use that to spawn new gui threads. Everything runs properly until I try to shut down my applications and close my threads -- various asserts start to fire. The shutdown of a gui thread invokes the function AfxEndThread which will call AfxOleTermOrFreeLib, which eventually calls COleObjectFactory::RevokeAll, and here is my problem. RevokeAll will go through all the class factory objects registered in the module state's m_factoryL...

Problem with first page of tabbed form
The second and third pages of my form work fine. No matter what I put on the first page it takes up the entire screen when viewed, with no tabs visible. I'm carefully avoiding puting the controls on the main form -- I put them within the black box that appears when the tab is clicked. If I leave the first page blank the other pages work well. If I move the second page up to the top of the page order, I have the same problem -- the form tabs no longer show. How can the same page work correctly when it is in the number 2 position and not when it is in the number 1 position? What a...

Performance problems
Hi! We are experiencing a lot of problems when user jump between mails and opening attachments. It can take up to a minute to open an attachment (.doc, ..xls, .pdf etc.) on the LAN (100 mbit). The server is not using much processor (10-20%) and no cpu queues or nothing. The RPC ops /sec is peaking to 818 and averages to about 80%sec. Is this much? I cannot see why it would do this since it's not "doing" anything more at theese times. We have about 160 accounts/mailboxes on this IBM x225 with 1 x 2.67 Ghz Proc and 2.5 GB memory (uses 1,8) Here are the Perfmon for it. Plea...