• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 337
  • Last Modified:

Add CWnd object to a MDI project?

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

1 Solution
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 ?
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.

danigrafAuthor Commented:
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
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now