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

SendMessage not working

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
jade03
Asked:
jade03
  • 4
  • 3
1 Solution
 
rcarlanCommented:
>>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
 
jade03Author Commented:

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
 
rcarlanCommented:
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
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.

 
jade03Author Commented:
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
 
rcarlanCommented:
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
 
rcarlanCommented:
Well, the diagram doesn't look too bad on my screen. But then again, I'm running in 1920x1440 :-)

Radu
0
 
jade03Author Commented:
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
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

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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