[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Window handle in ATL COM object

Posted on 2002-05-02
11
Medium Priority
?
534 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
Technology Partners: 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 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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 viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

656 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