Solved

SetCapture from tasktray icon

Posted on 2004-09-07
12
560 Views
Last Modified: 2012-05-05
Had this question on MFC for 2 days....no bites so I moved it over here.

I have a dialog that I minimize to the IconTray.
I need to click on the Icon and drag mouse to anywhere on the screen while getting the mouse position.
I am wondering if I can SetCapture to get the mouse position anywhere in the window while dragging.
So far it only gets the position over the Icon.

I know I could use a set timer function (already implemented) , Only I don't want to do that method if I don't have to.
I have never used any kind of window hooks, but I am willing to explore the Idea(but not at a cost to performance).
Of course I would rather do it as simple as possible, hopefully SetCapture or something that easy.

Any Ideas?
 
0
Comment
Question by:cafechris
12 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 60 total points
ID: 12001829
You can make a trick, but I have never tried: at the beginning of your "dragging process", create a window with transparent background, bigger than the screen to avoid to show the frame of caption, direct the SetCapture to this window, user will not notice it is there an you will ensure to trap all mouse events, without hooks.
Good luck,
Jaime.
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 156 total points
ID: 12003704
Using CWnd::GetCapture you should get the window that has the mouse capture. With CWnd::SetCapture the current window

>> receives mouse input whether or not the cursor is within its borders (MSDN)

So, i don't think you need a transparent frame window for this. Simply call SetCapture() by your current window and drag mouse events then.

Regards, Alex
0
 
LVL 22

Expert Comment

by:grg99
ID: 12004859
Have you looked at shellapi and  NOTIFYICONDATA ?   The docs imply that you can get mouse movement messages this way.

0
 
LVL 1

Author Comment

by:cafechris
ID: 12018302
 
----jaime_olivares  
Thanks but ....
I have a few hack ways of doing it already, I don't really want this. It always bites you in the butt down the line and OS's later.
So the transparent window is not a reasonable option for this.


----itsmeandnobodyelse
I have tried setCapture, but it doesn't seem to work from the Icon tray. Even if I use FindWindow(NULL, "Notification Area"), which gets the handle to the notification area. and then use SetCapture from there.

I am opening up a simple little dialog to give information as I drag from the Icontray, but set capture doesn't seem to work if I use it. I think this is because the mouse is pressed down->then the dialog is launched and the mouse needs re-pressed on the dialog to have SetCapture work.
I will try using mouse_event() and see if this is plausable, I have just not had a lot of luck with mouse_event working for what I need the way I need in the past.


----grg99
I have looked into the NOTIFYICONDATA. the docs are right, but they only get the mouse info if it is over the icon area, and I believe from my tests that it is only over that specific Icon.


0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 12019706
>> So far it only gets the position over the Icon.

Could you post that part of code where you handle that mouse event, i. e. where you notice that the icon is going to get dragged?


>> I have tried setCapture, but it doesn't seem to work from the Icon tray

SetCapture needs a CWnd that currently has the mouse. So, you either have to find out  what window currently has the mouse or you have to create a 'transparent' window (at your icon) that could call SetCapture,

Regards, Alex


0
 
LVL 1

Author Comment

by:cafechris
ID: 12020314
Its been 4 days, so I will need to organize and uncomment everything so it is how it used to be. (may take a bit a few hours, as I am very busy today...and this is for fun).
One question I have, if I do get the current CWnd and I set capture for that window, don't I then need to set a hook into its WM_MOUSEMOVE to get the info. Then I would guess that I am back to testing how hooks work.

chris
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:cafechris
ID: 12030765
sorry still have been to busy to post it, I will try tonight when I get home.
0
 

Assisted Solution

by:mikeant78
mikeant78 earned 84 total points
ID: 12060711
Can't you just create your own "dummy" popup window of size (0,0), and and SetCapture to it? Then you could process the messages and destroy the window when dragging has ended...
0
 
LVL 1

Author Comment

by:cafechris
ID: 12066897
I already create a dialog that opens when I press down. The problem is that I don't know how to set the capture to that window.

I finally figured out how to make mouse_event work.
 Maybe I can simulate a  mouse click/drag on that dialog. I already tried:

myLittleDialog->SetCapture() and this didn't work. (probably because I am not actually on the dialog when I click in the Icon tray.)
Let me know If there are any ways to SetCapture() to a dialog that your mouse is never over. ( actually move this dialog with the cursor so It can give information to the user while dragging....but the window is to the top right of the cursor and never touches it)

hmmmm????
0
 
LVL 1

Author Comment

by:cafechris
ID: 12067937
Yep got it by using mouse_event.

The problem was that I was trying to process the mouse move from my trayIcon proc and my mainDialog proc.

I had to do it in the littleDialog proc.

STUPID.....STUPID.....STUPID.....

Well, I am going to look over everything and see if I can give some points to those who helped.

thanks everyone-
0
 
LVL 1

Author Comment

by:cafechris
ID: 12068415
I have never solved my own question on a post here before an expert did. So I am going to try to do what I think is right and give some points were deserved. If I am breaking any rules here please let me know. I would also like to know how to split some of the points between experts.

Well I looked everything over and It is tough because everyone was basically leading me toward the discovery. Since the problem resided in the fact that I was in the incorrect winProc, I am going to give points to those whom I felt sparked the Idea when I reread the post the last time. So here goes.....

25pts to jaime_olivares
I don't know why, but I believe it started my Idea of using my dialog.

65pts to itsmeandnobodyelse
for some reason your second post really got me thinking in the right direction.
And thanks for your efforts, I am sorry I couldn't get post my code...I have just been slammed at work.

35pts to mikeant78
Yours was the last one I read before I thought to use the other winProc. I know you didn't say anything much different than the others, but I it all helped.

This is what I want to do...Now how do I split up part of the points amongst you guys.

I searched the help and didn't see any way of doing this. Is there a moderator I can post to or email? Let me know if this is possible. If not, please let me know of some options that I may have.

Thank you everyone,

Chris Reid
0
 
LVL 1

Author Comment

by:cafechris
ID: 12261516
Ok sick of waiting,
I will just split the points up proportianally so that you all get them. Only problem is that I will have to pick an answer. There should be a way to do what I wanted above. Oh well, I don't know of any way.
I will just pick the first person who answered as the answer .

Sorry for any unfairness, I just don't know of any other way to do it.

Chris
0

Featured Post

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

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 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

24 Experts available now in Live!

Get 1:1 Help Now