Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Add CWnd object to a MDI project?

Posted on 1999-07-15
4
Medium Priority
?
331 Views
Last Modified: 2008-02-01
I use a serial port class, which requires a CWnd object to handle the messages. My project is a MDI project. I don't want to use one of the existing MDI objects to receive the messages. That means I could create a generic CWnd class (no displaying), which handles the messages.

How does that work? How can I add a new message handler class to my existing MDI project?

Or is there a easier way to do it?

I'm using NT4.0 and VC++ 6.0.

Thanks a lot
Daniel

0
Comment
Question by:danigraf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 3

Expert Comment

by:Shay050799
ID: 1200273
you have to be more specific, what the window for if you don't want to display it ?
what messages ? and where they are comming from ?
0
 

Expert Comment

by:johnorear
ID: 1200274
If you just want to add a cwnd object, just go into ClassWizard, choose the Add Class dropdown button, select New...

You'll get a New Class dialog. Enter class name,etc...

The critical part is the Base Class dropdown box. At the bottom is Generic CWnd. Select this, and you have your class, complete with message handlers you can implement using class wizard.


If you're doing serial port work, you may want to base your class off of CAsyncSocket, instead. It will get you the message handlers you're after.

Another option: if you're after messages that class wizard can generate - and it sounds like you are, you may want to roll your own SerialPort object and create public functions for the messages you want to handle. Then, use your active cwnd or view to capture the messages and call the methods you've put into your serial object.


0
 

Author Comment

by:danigraf
ID: 1200275
Sorry, I think I wasn't that specific. Here are more details about my problem:

I have a special serial port class and in that class I have to call:
m_Serial.InitPort(this, 1, 9600,'N',8,1,EV_RXCHAR,512);
The first parameter is important for message handling. It requires CWnd* pPortOwner.

What I want know is my own message handler class. I don't wanna use any classes of my MDI application. How can I implement that? Somehow, this message handler class (CWnd object?) has to know my MDI application. Otherwise it can't receive messages. I don't know how to do that.

If I pass my applications view class as message handler to InitPort(...), it works fine. But I want a separate class as message handler.

I hope that is enough information.

Thanks again
Daniel
0
 
LVL 1

Accepted Solution

by:
alex1234 earned 400 total points
ID: 1200276
This is the code to create a valid invisible CWnd object:

CWnd *CreateDummyWnd(CWnd *pParent)
{
CWnd *pWnd;
CRect r;

pWnd = new CWnd;
LPCTSTR szClName = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW);

if(pWnd->Create(szClName, "Dummy", WS_CHILD, r, pParent, 0))
{
return pWnd;
}

return NULL;
}

pParent can be the MDI window you make m_Serial.InitPort(this, 1, 9600,'N',8,1,EV_RXCHAR,512); call from.


0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question