?
Solved

SendMessage not working

Posted on 2005-04-07
7
Medium Priority
?
424 Views
Last Modified: 2010-04-17
who can call SendMessage(hwnd, WM_USER+1, WPARAM, LPARAM)?

Can a non-dialog class call it?

How does it go about calling it? simply like so:

SendMessage(dialogHwnd, WM_USER+1, 0, (LPARAM)"some text");

or ::SendMessage(dialogHwnd, WM_USER+1, 0, (LPARAM)"some text");

how do you know if the dialogHwnd is a valid handle?

I'm not getting any errors but my onMyMessage() func is not being invoked...

and yes, I do have the message map already....like so:


BEGIN_MESSAGE_MAP(TabFive, CDialog)
      ON_MESSAGE(WM_USER+1, OnMyMessage)
END_MESSAGE_MAP()
0
Comment
Question by:jade03
  • 4
  • 3
7 Comments
 
LVL 9

Accepted Solution

by:
rcarlan earned 400 total points
ID: 13731848
>>Can a non-dialog class call it [SendMessage]?

Yes.


>>How does it go about calling it?

::SendMessage(dialogHwnd, WM_USER+1, 0, (LPARAM)"some text");



>>how do you know if the dialogHwnd is a valid handle?

IsWindow(dialogHwnd);


1. How is onMyMessage declared?
2. Have you tried sending the message from within a TabFive class instance (object)?

Do this in one of the other message handlers in your TabFive class (e.g. in a button click message):
SendMessage(WM_USER+1);

Start the app, place a breakpopint in onMyMessage, bring up the TabFive dialog and invoke the corresponding function. Note that LPARAM will be NULL on entry in onMyMessage, but a least you'll see if it gets there.

Radu
0
 

Author Comment

by:jade03
ID: 13731964

k, I tried calling SendMessage() from a TabFive instance, and it does go into onMyMessage();

however, it's still not going into onMyMessage() when called inside a non-dialog class using:

::SendMessage(dialogHwnd, WM_USER+1, 0, (LPARAM)"some text");

I checked dialogHwnd to see if it's null like so:

if(((CMyTabExampleDlg*)AfxGetMainWnd())->m_tabFive.m_tabFiveDlgHandle == NULL)
    AfxMessageBox("handle is null");
else
{
   AfxMessageBox("handle not null");  <-------  PRINTS OUT THIS LINE

    if(IsWindow(((CMyTabExampleDlg*)AfxGetMainWnd())->m_tabFive.m_tabFiveDlgHandle))
         AfxMessageBox("handle is valid");   <---------BUT NOT THIS LINE!!
}


so what does it mean it's NOT null but yet it's NOT a valid handle??

confused...
0
 
LVL 9

Expert Comment

by:rcarlan
ID: 13732005
The C++ object was created but not the window. You obviously cannot send messages to a window that doesn't exit, but you can call methods on the C++ object.

Consider this piece of code:

class CMyDialog : public CDialog
{
    // stuff
};


// somewhere in your program:

CMyDialog dlg;  
// C++ object created but not the window
dlg.DoModal();  // while executing this, the corresponding window exists
// C++ object still exists but no the window (DoModal returns when the window is closed)

Radu
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jade03
ID: 13732042
I'm sorry, Radu...so ur suggestion is...??

I should call DoModal on tabfive? but when I do that, the whole application doesn't show up anymore...
0
 
LVL 9

Expert Comment

by:rcarlan
ID: 13732288
Well, you have to think about the logic of your application.
What is it that you're trying to achieve by sending the message?
Who needs to send the message and why? What should be the result of handling the message?

Are you trying to update some data in your TabFive object? Call a method instead of sending a message.

Are you trying to update something rendered in the window corresponding to a TabFive object? Send a message - if the window is not up, there's nothing to update, no? When it is up, it will respond to the message.

Sequence diagrams usually help (they are sometimes called interaction or activity diagrams).

For example (I'm not sure how well aligned the diagram below will be when rendered):

wait for user cmd
(run app/main message loop)
                          ------> Invoke Menu Cmd -----> create TabFive object
                                                                         display TabFive window ------> run modal message loop
                                                                                                                                                            ------> Click on button -----> update or do whatever
                                                                                                                                                           <-------------------------------
                                                                                                                                                            --------> Click on OK  ------> update TabFive internal data and close window
                                                                                                            <---------------------------------------------------------------------
                                                                         process TabFive data
                          <-----------------------------------

I've used leading uppercase letter for user action and leading lowercase letter for program action.

Radu
0
 
LVL 9

Expert Comment

by:rcarlan
ID: 13732302
Well, the diagram doesn't look too bad on my screen. But then again, I'm running in 1920x1440 :-)

Radu
0
 

Author Comment

by:jade03
ID: 13732365
Thank you, Radu. It's working now...I gave up on trying to access the handle from the object that I created...instead, I went down to the bottom of hte code and grabbed that dialog from where it is created in another file...

you hint on calling ::SendMessage() was helpful, and I appreciate the diagram! :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Six Sigma Control Plans

839 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