[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 575
  • Last Modified:

SetCapture from tasktray icon

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
cafechris
Asked:
cafechris
3 Solutions
 
Jaime OlivaresCommented:
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
 
itsmeandnobodyelseCommented:
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
 
grg99Commented:
Have you looked at shellapi and  NOTIFYICONDATA ?   The docs imply that you can get mouse movement messages this way.

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.

 
cafechrisAuthor Commented:
 
----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
 
itsmeandnobodyelseCommented:
>> 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
 
cafechrisAuthor Commented:
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
 
cafechrisAuthor Commented:
sorry still have been to busy to post it, I will try tonight when I get home.
0
 
mikeant78Commented:
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
 
cafechrisAuthor Commented:
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
 
cafechrisAuthor Commented:
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
 
cafechrisAuthor Commented:
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
 
cafechrisAuthor Commented:
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now