I was having problems with splitter windows and I posted a question to this
group. One of the replies referred me to Code Project with a link to someones
article on the subject. This is a snippit of that code with a comment stating
derived from CView.
here.
//GetActiveDocument() also can't be used because it calls GetActiveView().
would work so I have been trying to make EnumChildWindows work. I appoligize
for the misunderstanding I had with this. I take it that the above comment is
my misunderstanding.
"Joseph M. Newcomer" wrote:
This seems unnecessarily complex; since any view will do, GetActiveView should suffice! Is
this an MDI app or an SDI app, and if MDI, why is it that any view of any document is
sufficient? Or why not use GetActiveDocument and call UpdateAllViews? For SDI,
GetActiveView will do exactly what you need.
Instead of asking us to debug code whose purpose is unfathomable, why not state what your
problem is and ask if there is a reasonable solution. I would not consider using
EnumChildWindows as a solution for finding an arbitrary view of my app; in fact, I'm not
sure why I would want to find just any view of just any document in the first place, which
is why I find this code unfathomable.
joe
On Wed, 24 Oct 2007 19:57:00 -0700, Al <Al@discussions.microsoft.com> wrote:
Hi Giovanni Dicanio
I am looking over the code that you sent here and I am trying to figure out
how I can change it to meet my needs. Sorry about the time laps but I am
trying to figure it out too. Here is my code and let me know where I am going
wrong or how I can adapt it to your code if you could
<code>
// Declaration
static bool CALLBACK MyWndEnumProc(HWND hWnd, LPARAM lParam);
// The function
bool CALLBACK CMainFrame::MyWndEnumProc(HWND hWnd, LPARAM ppWndLPARAM)
{
CWnd* pWndChild = CWnd::FromHandlePermanent(hWnd);
CWnd** ppWndTemp = (CWnd**)ppWndLPARAM;
****
First, as already observed, you should make this a static *class member* (a static global
function adds a global function, which is usually a bad idea). Making it a static class
member also allows you to access protected variables in the class, since the function is a
class method, but to do so, as already pointed out, you need to pass 'this' in.
****
if( pWndChild && pWndChild->IsKindOf(RUNTIME_CLASS(CView)) )
{
//any view that is found will work:
*ppWndTemp = pWndChild; //pass ptr to found CView back to calling function
return FALSE; //stop enumeration
}
else
{
*ppWndTemp = NULL;
return TRUE; //continue enumeration
}
}
// The call
CWnd* pWnd;
::EnumChildWindows(m_hWnd, pMyWndEnumProc, (LPARAM)&(pWnd));
****
I also agree with the earlier question: why do you need a pointer variable here? It
serves no useful purpose unless this function can call DIFFERENT enumeration functions for
the callback. If its purpose is only to call the function shown above, just give the
function name! It is a common misconception that when a parameter is given as a type, it
means you must have a variable of that type; the actual semantics of the language means
that you need an *expression* which evaluates to that type, and the name of a function
evaluates to the type of the function.
joe
*****
<end code>
This initializes the pointer pWnd so later in the code, tests can be done.
I am a little confused with the code that you left me at trying to
initialize the pointer pWnd. If you could enlighten me I would greatly
appreciate it. I am still reading "Beginning MFC Programming" by Ivor Horton.
This here is a little bit of a leep for me.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm