Solved

Window handle in ATL COM object

Posted on 2002-05-02
11
524 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
Comment Utility
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
Comment Utility
Is any example that I can follow?
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
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
 
LVL 86

Expert Comment

by:jkr
Comment Utility
>>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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 22

Expert Comment

by:ambience
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>>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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now