?
Solved

Window handle in ATL COM object

Posted on 2002-05-02
11
Medium Priority
?
533 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 600 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

765 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