Solved

Window handle in ATL COM object

Posted on 2002-05-02
11
529 Views
Last Modified: 2013-12-14
I've a ATL COM OBJECT and I add the dialog into it.

I would like to add icon into my system tray. when the user double click on the icon. I will display the dialog that will display the statistics from the COM obecjt.

The question is:

If I use Shell_NotifyIcon, how do I get Window handle from ATL com?


0
Comment
Question by:EDDYKT
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6986714
I fear that you are pretty much out of luck here. Even if you manage to get the window handle, you will have to process the notification message, otherwise the system will remove the tray icon.
0
 
LVL 26

Author Comment

by:EDDYKT
ID: 6986738
Is any example that I can follow?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6987135
jkr,
Wouldn't it be possible to create the dialogbox and hide it, but leave it alive for handling notifications?  I know that I do something like that in a system service.

-- Dan
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 86

Expert Comment

by:jkr
ID: 6987162
>>Wouldn't it be possible to create the dialogbox and hide
>>it, but leave it alive for handling notifications?

In this case, you could also just create an invisible window that receives the notification msgs...
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6987511
EDDYKT,
I would recommend that when your COM object gets loaded, it create the dialogbox, in a hidden state.  In the dialogbox initialization, set up the tray icon (do you know how to do that?  - it involves calling Shell_NotifyIcon( NIM_ADD,...) and you must provide a message ID and the hwnd of the window to handle the tray callback messages).

When you get the notification to display the status, just unhide the dialogbox and update the screen elements.

-- Dan
0
 
LVL 22

Expert Comment

by:ambience
ID: 6987882
I donot think there is any need at all to create a separate window for handling windows messages. The control itself has a window. If it doesnt already then you can set the m_bWindowOnly flag to force the control to always have a window. m_hWndCD contains the handle to the controls window.

And processing that window messages in that control is simple by using ATL macros for adding event handler just like you do in MFC's CWnd derived classes, though here the classwizard wont help you, and you have to add that yourself.

BEGIN_MSG_MAP(CYourControl)
   MESSAGE_HANDLER(WM_PAINT, OnPaint)
   ...
END_MSG_MAP()

LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

this way you can also add the handlers for Tray notfications.
0
 
LVL 22

Expert Comment

by:ambience
ID: 6987888
this should be pretty straight forward to implement.

MESSAGE_HANDLER(WM_CREATE , OnCreate)

OnCreate(...)
{
 //add icon to tray.
}

or maybe use FinalConstruct for adding items to tray, that would ensure that the control has been initialized.
0
 
LVL 22

Expert Comment

by:ambience
ID: 6987892
GOSH!!! , sorry guys i mis-read the question, EDDYKT what i have posted earlier applies to ATL controls and not a regular ATL COM objects.

If yours is not a control then what DanRollins has said holds true.
0
 
LVL 22

Expert Comment

by:ambience
ID: 6987898
unless ofcourse if you inherit your object from CWindowImpl and create a hidden window for your object, then you'll be able to process messages inside the object and outside the contained dialog.

0
 
LVL 26

Author Comment

by:EDDYKT
ID: 6991079
To DanRollins,

How do I get the window handle. What is my window handle in this case. As in the question, I need to pass window handle into the structure so that I can call Shell_NotifyIcon. Where is my window handle?
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 150 total points
ID: 6991895
>>How do I get the window handle.

The window handle is always available... If your program has created a window, then your program knows its handle.

-- Dan
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

791 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