Solved

Window handle in ATL COM object

Posted on 2002-05-02
11
531 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
[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
  • 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
Independent Software Vendors: 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!

 
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

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

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

717 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