Message Routing from Librarys
Christopher Snyder -- csnyder@bobcat.ent.ohiou.edu
Tuesday, February 13, 1996
I am writing an app in MSVC++ 1.5 using the Quinn-Curtis Charting
Tools for Windows version 2.1.
The graphs created using the library exist in a CView derived class.
The problem I am having is having messages sent to the correct place.
Specifically, the mouse button clicks. The graphing library traps them
first in a function defined as follows
LRESULT CALLBACK _export GraphProc (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam);
which I have access to. The problem is that this funtion is called for
EVERY graph regardless of which class it belongs. I want to have class
specific message handling for graph messages. When I use the class
wizard and create the OnRButtonDown() function, for example, it is
never called.
How can I get my messages passed back to my CView object?
If more information is needed please let me know.
(I have MSDN, Petzold, & Inside Visual C++ v1.5))
__..
~~ + ':
___\: /';___
\ ( (_____/ Christopher A. Snyder
\ \ \___/ Graduate Student at
\ \ \ / Ohio University Avionics Center
\ \ V (614) 593-1524
\ \ Go http://www.ent.ohiou.edu/~csnyder/
\/ Penguins!
Jim Lavin -- ooptech@Onramp.NET
Thursday, February 15, 1996
Christopher Snyder wrote:
>
> I am writing an app in MSVC++ 1.5 using the Quinn-Curtis Charting
> Tools for Windows version 2.1.
>
> The graphs created using the library exist in a CView derived class.
> The problem I am having is having messages sent to the correct place.
> Specifically, the mouse button clicks. The graphing library traps them
> first in a function defined as follows
>
> LRESULT CALLBACK _export GraphProc (HWND hwnd, UINT message,
> WPARAM wParam, LPARAM lParam);
>
> which I have access to. The problem is that this funtion is called for
> EVERY graph regardless of which class it belongs. I want to have class
> specific message handling for graph messages. When I use the class
> wizard and create the OnRButtonDown() function, for example, it is
> never called.
>
> How can I get my messages passed back to my CView object?
>
> If more information is needed please let me know.
>
> (I have MSDN, Petzold, & Inside Visual C++ v1.5))
>
> __..
> ~~ + ':
> ___\: /';___
> \ ( (_____/ Christopher A. Snyder
> \ \ \___/ Graduate Student at
> \ \ \ / Ohio University Avionics Center
> \ \ V (614) 593-1524
> \ \ Go http://www.ent.ohiou.edu/~csnyder/
> \/ Penguins!
You need to look at the MSDN on subclassing of controls under MFC. If
you want to be able to use a class in conjunction with the control;
such as CListBox with a ListBox control. You'll need to do a little
extra work but by subclassing the control you'll be able to handle the
messages how you want.
J Ride up Okajima -- j-okajim@nmite92.nmit.mt.nec.co.jp
Saturday, February 17, 1996
"Christopher Snyder":
> The graphs created using the library exist in a CView derived class.
> The problem I am having is having messages sent to the correct place.
> Specifically, the mouse button clicks. The graphing library traps them
> first in a function defined as follows
>
> LRESULT CALLBACK _export GraphProc (HWND hwnd, UINT message,
> WPARAM wParam, LPARAM lParam);
>
> which I have access to. The problem is that this funtion is called for
> EVERY graph regardless of which class it belongs. I want to have class
> specific message handling for graph messages. When I use the class
> wizard and create the OnRButtonDown() function, for example, it is
> never called.
>
> How can I get my messages passed back to my CView object?
Hello, I am new to this Mailing list.
I guess the function CView::WindowProc() calls GraphProc().
So why don't you override and customize YourCView::WindowProc() to
pass the event to original way, e.g. CView::WindowProc().
Junjiro Okajima
Christopher Snyder -- csnyder@bobcat.ent.ohiou.edu
Sunday, February 18, 1996
> "Junjiro Okajima":
> "Christopher Snyder":
> > The graphs created using the library exist in a CView derived
> > class. The problem I am having is having messages sent to the
> > correct place. Specifically, the mouse button clicks. The graphing
> > library traps them first in a function defined as follows
> >
> > LRESULT CALLBACK _export GraphProc (HWND hwnd, UINT message,
> > WPARAM wParam, LPARAM lParam);
> >
> > which I have access to. The problem is that this funtion is called
> > for EVERY graph regardless of which class it belongs. I want to
> > have class specific message handling for graph messages. When I
> > use the class wizard and create the OnRButtonDown() function, for
> > example, it is never called.
> >
> > How can I get my messages passed back to my CView object?
>
> Hello, I am new to this Mailing list.
>
> I guess the function CView::WindowProc() calls GraphProc().
> So why don't you override and customize YourCView::WindowProc() to
> pass the event to original way, e.g. CView::WindowProc().
>
Let me explain the structure of the library with MFC. First you
create your CView class. The view class contatins an instance of
the library's page class. The page class then contains an instance of
the library's graph class.
class MyGraph : public QCBaseGraph {
double data_to_graph
...
};
class MyPage : public QCBasePage {
private:
MyGraph* graphs; // array of graph pointers
virtual void BuildPage (PPAGE_DEF); // user function initializing
page
...
};
class MyView : public CView {
private:
MyPage* m_page; // pointer to the page object
...
};
The CMyView::OnInitialUpdate() allocates and creates the m_page object
and then calls a library function WGCreatePage(). This function then
calls the BuildPage() virtual function that contains all the
information necessary to make the MyGraph objects. There can be
several on a single page.
Now back to the original problem. When a message, ie mouse message,
occures in the MyGraph window, (the graphs are child windows of the
view) these message are trapped and sent by the DLL routines to a C
function called GraphProc() which processes all messages. In response
to Junjiro Okajima, I don't know what calls GraphProc() because it
comes from the library.
One possible solution I received, have not had a chance to try it yet,
was to add code to the GraphProc() to get a pointer back to the view
that had the message.
...
CMyView* pView = NULL;
CMDIFrameWnd * pFrame = (CMDIFrameWnd *) AfxGetMainWnd();
pView = (CMyView*) (pFrame->MDIGetActive()->GetWindow(GW_CHILD));
...
>From here I can call the CMyView() message handlers for the specific
messages trapped.
Thanks to all who have responded.
__..
~~ + ':
___\: /';___
\ ( (_____/ Christopher A. Snyder
\ \ \___/ Graduate Student at
\ \ \ / Ohio University Avionics Center
\ \ V (614) 593-1524
\ \ Go http://www.ent.ohiou.edu/~csnyder/
\/ Penguins!
Niels Ull Jacobsen -- nuj@kruger.dk
Tuesday, February 20, 1996
>
> > "Junjiro Okajima":
> > "Christopher Snyder":
> > > The graphs created using the library exist in a CView derived
> > > class. The problem I am having is having messages sent to the
> > > correct place. Specifically, the mouse button clicks. The graphing
> > > library traps them first in a function defined as follows
> > >
> > > LRESULT CALLBACK _export GraphProc (HWND hwnd, UINT message,
> > > WPARAM wParam, LPARAM lParam);
> > >
> > > which I have access to. The problem is that this funtion is called
> > > for EVERY graph regardless of which class it belongs. I want to
> > > have class specific message handling for graph messages. When I
> > > use the class wizard and create the OnRButtonDown() function, for
> > > example, it is never called.
> > >
> > > How can I get my messages passed back to my CView object?
> >
>
> Let me explain the structure of the library with MFC. First you
> create your CView class. The view class contatins an instance of
> the library's page class. The page class then contains an instance of
> the library's graph class.
>
> class MyGraph : public QCBaseGraph {
> double data_to_graph
> ...
> };
>
> class MyPage : public QCBasePage {
> private:
> MyGraph* graphs; // array of graph pointers
> virtual void BuildPage (PPAGE_DEF); // user function initializing
> page
> ...
> };
>
> class MyView : public CView {
> private:
> MyPage* m_page; // pointer to the page object
> ...
> };
>
> The CMyView::OnInitialUpdate() allocates and creates the m_page object
> and then calls a library function WGCreatePage(). This function then
> calls the BuildPage() virtual function that contains all the
> information necessary to make the MyGraph objects. There can be
> several on a single page.
>
> Now back to the original problem. When a message, ie mouse message,
> occures in the MyGraph window, (the graphs are child windows of the
> view) these message are trapped and sent by the DLL routines to a C
> function called GraphProc() which processes all messages. In response
> to Junjiro Okajima, I don't know what calls GraphProc() because it
> comes from the library.
I'm also using Quinn-Curtis.
GraphProc is simply the windows procedure for the graph window. The
"Windows procedure" is the routine that handles all messages for a
window, but it is encapsulated by MFC, so people who only use MFC may
not be familiar with the concept. I recommend (as always) reading Petzold :-).
Anyway, the simplest way to find your view from the GraphProc is
probably to "loop" backwards with GetParent, until you find a window
which IsKindOf(RUNTIME_CLASS(CView)). You should probably store the
graph handle also, so you can determine which graph recieved the
event.
You may want to get the new MFC encapsulation of Quinn-Curtis, which
handles most of this for you. It's still not quite simple to interface
with MFC, though, particularly when it comes to the user interface part.
>
> One possible solution I received, have not had a chance to try it yet,
> was to add code to the GraphProc() to get a pointer back to the view
> that had the message.
>
> ...
> CMyView* pView = NULL;
> CMDIFrameWnd * pFrame = (CMDIFrameWnd *) AfxGetMainWnd();
> pView = (CMyView*) (pFrame->MDIGetActive()->GetWindow(GW_CHILD));
> ...
>
>
> >From here I can call the CMyView() message handlers for the specific
> messages trapped.
>
> Thanks to all who have responded.
>
>
> __..
> ~~ + ':
> ___\: /';___
> \ ( (_____/ Christopher A. Snyder
> \ \ \___/ Graduate Student at
> \ \ \ / Ohio University Avionics Center
> \ \ V (614) 593-1524
> \ \ Go http://www.ent.ohiou.edu/~csnyder/
> \/ Penguins!
>
>
--
Niels Ull Jacobsen, Kruger A/S
Everything stated herein is THE OFFICIAL POLICY of the entire Kruger
group and should be taken as legally binding in every respect. Pigs
will grow wings and fly.
| Вернуться в корень Архива
|