Pls Help with SetCapture()...

Hi, I'm trying to use the SetCapture() API and am having a few problems with 
it. It has worked fine for me in the past, so I'm not quite sure what the 
problem is and whether its in MFC or Win32.

Here is the scenario:

I'm trying to implement "full drag" MFC control bars. For the sake of 
argument a CToolBar. By "full drag" I mean Office 2003 style where the 
toolbar is moved around in real time and you can see it completely rather 
then the lame stock MFC "outline style drag". I've got this part all 
working.

Here is the problem:

I can drag the toolbars and they dock, float correctly. When a toolbar is 
docked, and I click on the gripper and drag it around, it floats and I can 
drag it all around the screen no problem and redock it to my hearts content.

BUT... if the toolbar is FLOATING and I go to drag it by clicking on the 
caption, I can drag it around too, but I loose control of it if I move the 
mouse outside the main frame window?!?!?! What gives??? I no longer get 
WM_MOUSEMOVE messages. But if I started the drag from a docked position, 
this works perfectly fine.

So the toolbar is floating, I click on the gripper to start a drag and the 
mouse cursor turns to a cross-hair. I drag it across and it docks where its 
supposed to, but once I move outside the frame, the cursor turns back an 
arrow, and the toolbar no longer moves if I move back into the frame, I 
suddenly regain control.

I've seen some references on the net where SetCapture() will only capture 
messages for windows belonging to the current thread, but never saw a reason 
why or how to work around it.

The mouse button IS down when I call SetCapture() as I'm calling it from 
WM_NCLBUTTONDOWN.

I sort of worked around it by installing a Mouse Hook and a Low Level Mouse 
hook system wide and redirecting messages to my callback window. This worked 
fine (or so I thought) with only a minor performance hit, and I only left 
the hooks installed during a drag operation. Recently I noticed it doesn't 
seem to catch all the mouse movements (like if I am mousing over a DOS 
window or Media Player).

I found another work around by installing a journal hook instead of the 
other two hooks, but that journal hook seems to cause a bigger performance 
hit then the other two combined.

Seems like the most efficient would be to get the SetCapture() method 
working... but why is it only trapping messages when the mouse is over my 
process (or always when the drag is started from a docked position).


0
nobody8050 (131)
4/5/2005 2:32:32 AM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
1023 Views

Similar Articles

[PageSpeed] 12

Does this from MSDN explain it?

"Only the foreground window can capture the mouse. When a background window 
attempts to do so, the window receives messages only for mouse events that 
occur when the cursor hot spot is within the visible portion of the window. 
Also, even if the foreground window has captured the mouse, the user can 
still click another window, bringing it to the foreground. "


-- 

Ken Wickes [MSFT]
This posting is provided "AS IS" with no warranties, and confers no rights.


"Nobody" <nobody@cox.net> wrote in message 
news:8Nm4e.72085$AN1.24738@fed1read03...
> Hi, I'm trying to use the SetCapture() API and am having a few problems 
> with it. It has worked fine for me in the past, so I'm not quite sure what 
> the problem is and whether its in MFC or Win32.
>
> Here is the scenario:
>
> I'm trying to implement "full drag" MFC control bars. For the sake of 
> argument a CToolBar. By "full drag" I mean Office 2003 style where the 
> toolbar is moved around in real time and you can see it completely rather 
> then the lame stock MFC "outline style drag". I've got this part all 
> working.
>
> Here is the problem:
>
> I can drag the toolbars and they dock, float correctly. When a toolbar is 
> docked, and I click on the gripper and drag it around, it floats and I can 
> drag it all around the screen no problem and redock it to my hearts 
> content.
>
> BUT... if the toolbar is FLOATING and I go to drag it by clicking on the 
> caption, I can drag it around too, but I loose control of it if I move the 
> mouse outside the main frame window?!?!?! What gives??? I no longer get 
> WM_MOUSEMOVE messages. But if I started the drag from a docked position, 
> this works perfectly fine.
>
> So the toolbar is floating, I click on the gripper to start a drag and the 
> mouse cursor turns to a cross-hair. I drag it across and it docks where 
> its supposed to, but once I move outside the frame, the cursor turns back 
> an arrow, and the toolbar no longer moves if I move back into the frame, I 
> suddenly regain control.
>
> I've seen some references on the net where SetCapture() will only capture 
> messages for windows belonging to the current thread, but never saw a 
> reason why or how to work around it.
>
> The mouse button IS down when I call SetCapture() as I'm calling it from 
> WM_NCLBUTTONDOWN.
>
> I sort of worked around it by installing a Mouse Hook and a Low Level 
> Mouse hook system wide and redirecting messages to my callback window. 
> This worked fine (or so I thought) with only a minor performance hit, and 
> I only left the hooks installed during a drag operation. Recently I 
> noticed it doesn't seem to catch all the mouse movements (like if I am 
> mousing over a DOS window or Media Player).
>
> I found another work around by installing a journal hook instead of the 
> other two hooks, but that journal hook seems to cause a bigger performance 
> hit then the other two combined.
>
> Seems like the most efficient would be to get the SetCapture() method 
> working... but why is it only trapping messages when the mouse is over my 
> process (or always when the drag is started from a docked position).
>
> 


0
kenwic (2)
4/7/2005 10:50:18 PM
Yeah, I saw this, but I am the foreground Window.

"Ken Wickes [MSFT]" <kenwic@online.microsoft.com> wrote in message 
news:u1Xo2P8OFHA.3704@TK2MSFTNGP12.phx.gbl...
> Does this from MSDN explain it?
>
> "Only the foreground window can capture the mouse. When a background 
> window attempts to do so, the window receives messages only for mouse 
> events that occur when the cursor hot spot is within the visible portion 
> of the window. Also, even if the foreground window has captured the mouse, 
> the user can still click another window, bringing it to the foreground. "
>
>
> -- 
>
> Ken Wickes [MSFT]
> This posting is provided "AS IS" with no warranties, and confers no 
> rights.
>
>
> "Nobody" <nobody@cox.net> wrote in message 
> news:8Nm4e.72085$AN1.24738@fed1read03...
>> Hi, I'm trying to use the SetCapture() API and am having a few problems 
>> with it. It has worked fine for me in the past, so I'm not quite sure 
>> what the problem is and whether its in MFC or Win32.
>>
>> Here is the scenario:
>>
>> I'm trying to implement "full drag" MFC control bars. For the sake of 
>> argument a CToolBar. By "full drag" I mean Office 2003 style where the 
>> toolbar is moved around in real time and you can see it completely rather 
>> then the lame stock MFC "outline style drag". I've got this part all 
>> working.
>>
>> Here is the problem:
>>
>> I can drag the toolbars and they dock, float correctly. When a toolbar is 
>> docked, and I click on the gripper and drag it around, it floats and I 
>> can drag it all around the screen no problem and redock it to my hearts 
>> content.
>>
>> BUT... if the toolbar is FLOATING and I go to drag it by clicking on the 
>> caption, I can drag it around too, but I loose control of it if I move 
>> the mouse outside the main frame window?!?!?! What gives??? I no longer 
>> get WM_MOUSEMOVE messages. But if I started the drag from a docked 
>> position, this works perfectly fine.
>>
>> So the toolbar is floating, I click on the gripper to start a drag and 
>> the mouse cursor turns to a cross-hair. I drag it across and it docks 
>> where its supposed to, but once I move outside the frame, the cursor 
>> turns back an arrow, and the toolbar no longer moves if I move back into 
>> the frame, I suddenly regain control.
>>
>> I've seen some references on the net where SetCapture() will only capture 
>> messages for windows belonging to the current thread, but never saw a 
>> reason why or how to work around it.
>>
>> The mouse button IS down when I call SetCapture() as I'm calling it from 
>> WM_NCLBUTTONDOWN.
>>
>> I sort of worked around it by installing a Mouse Hook and a Low Level 
>> Mouse hook system wide and redirecting messages to my callback window. 
>> This worked fine (or so I thought) with only a minor performance hit, and 
>> I only left the hooks installed during a drag operation. Recently I 
>> noticed it doesn't seem to catch all the mouse movements (like if I am 
>> mousing over a DOS window or Media Player).
>>
>> I found another work around by installing a journal hook instead of the 
>> other two hooks, but that journal hook seems to cause a bigger 
>> performance hit then the other two combined.
>>
>> Seems like the most efficient would be to get the SetCapture() method 
>> working... but why is it only trapping messages when the mouse is over my 
>> process (or always when the drag is started from a docked position).
>>
>>
>
> 


0
nobody8050 (131)
4/8/2005 4:23:58 AM
Nobody wrote:

> Hi, I'm trying to use the SetCapture() API and am having a few 
> problems with it. It has worked fine for me in the past, so I'm 
> not quite sure what the problem is and whether its in MFC or 
> Win32.

This is a real shot in the dark quite but quite some time ago I 
was also having issues with mouse capture. Eventually I tracked 
it down to a obscure bug/feature of Win32? 

If my memory is correct, I found that while the mouse was captured 
calling what looked like an unrelated Win32 API would in fact force
the the current capture to be released and the only indication of 
this would be the fact that WM_MOUSE message would no longer be
recieved. 

From memory I think that Win32 API in question was either a call 
to SetCursor or SetFocus.

Jussi Jumppanen
Author of: Zeus for Windows, Win32 (Brief, Emacs, etc) FTP Text Editor
"The C/C++, Java, HTML, FTP, Python, PHP, Perl folding editor"
Home Page: http://www.zeusedit.com
0
jussij (16)
6/14/2005 10:29:21 PM
On Wed, 15 Jun 2005 08:29:21 +1000, Jussi Jumppanen wrote:

> Nobody wrote:
> 
>> Hi, I'm trying to use the SetCapture() API and am having a few 
>> problems with it. It has worked fine for me in the past, so I'm 
>> not quite sure what the problem is and whether its in MFC or 
>> Win32.
> 
> This is a real shot in the dark quite but quite some time ago I 
> was also having issues with mouse capture. Eventually I tracked 
> it down to a obscure bug/feature of Win32? 
> 
> If my memory is correct, I found that while the mouse was captured 
> calling what looked like an unrelated Win32 API would in fact force
> the the current capture to be released and the only indication of 
> this would be the fact that WM_MOUSE message would no longer be
> recieved. 
> 
> From memory I think that Win32 API in question was either a call 
> to SetCursor or SetFocus.

I'd be surprised if SetCursor canceled the capture, but in general you
should handle WM_CANCELMODE and WM_CAPTURECHANGED. Hopefully one or both
those messages will tell you when the system takes the capture away from
you.

-- 
Doug Harrison
Microsoft MVP - Visual C++
0
dsh (2498)
6/14/2005 11:45:20 PM
Reply:

Similar Artilces:

Need help with CListCtrl
Using CListCtrl, but when I sort the indexes do not go along with the records. Here's what I mean: Suppose I add these items: Row 0: John Row 1: Bob Row 2: Tom Now when I click on the header and sort them in alphabetical order: Row 1: Bob Row 0: John Row 2: Tom Now when I call GetItemData(0) I am expecting to get "John". 0 is where I added "John". But instead, I get "Bob" (the new sort ordered index). So this presents a problem. I have no idea where John is anymore.. in case I wanted to edit that item later, I have to scan through all the items. You...

Reporting in CRM help!!!!!!!
Hi guys, It would be great if anyone could help me with this one. In the Sales Pipline report instead of using estimatedvalue for my calculations I want to use another custom field. Does anyone know how this can be done and if so how. I don't want to change any of the functionality of the report just simple change the field that use. My custom field is also a Money field Thanks Will Assuming you are using v3.0, You need visual studio to modify reports. Reports are saved in SQL reporting Services. If you are using 1.2, you customize reports using crystal "Will" wrote: ...

Please help #3
What does it mean when your publication has a blue screen with a pink background? That is what happens when I open Publisher. I cannot tell what colors are what. It means yucky colour scheme. -- "If you don't know where you are going, any road will take you there!" mlyon1@hotmail.com wrote: > What does it mean when your publication has a blue screen > with a pink background? That is what happens when I open > Publisher. I cannot tell what colors are what. =========================== Maybe the info at the following link will help: http://www.mvps.org/the_nerd...

Help needed with Vlookup code
I have noticed other vlookup codes in excel and after looking at them have started to try and use them myself. 2 questions. 1) The codes i saw had a lot of $ signs in them. I dont use them when i use vlookup and it seems to work fine. Is there a reason $ signs are added? 2) I have a vlookup code "=VLOOKUP(A9,Database!A1:F8000,2,FALSE)" and so on for a few lines and when it finds a blank box it puts 0 in there to represent that. Is there a way i can have it so that instead of putting a zero in it just leaves the box blank? -- Help Needed -------------------------------------...

very interesting query- please help
Ost Ocity Dstate Dcity Carrier Price Rank Diff A B C D X 1200 1 100 A B C D Y 1300 2 100 A B C D Z 1350 3 100 A B C D W 1789 4 100 A1 B1 C1 D1 X1 785 1 A1 B1 C1 D1 Y1 789 2 The rank for every carrier is based on the price . If rank1 carrier is not a pariticular carrier(say if it is not X1 or Y1 or Z1), then i want to calculate the difference be...

Bar Code
I'm opening a new retail business and would like to use the Manufactures bar code on many of my items......but for the life of me I can't figure out how to load the information into my system. I've serched the HELP screens, but no answers. I'm desperate - Can anyone guide me on how to do this? Sincere, thanks to anyone who can help :) Monica If using the UPC as your ILC doesn't work, you can add the UPC codes to the Alias tab of the Item Properties. Then if you're searching for WIDGET you don't need to memorize the UPC codes. HTH, Tom "Monica" ...

please help....
been trying to find how i can get office microsoft publisher,word,excel,templates and i own a windows 98 SECOND EDITION machine...I know it is somewhere yet i dont know where to look to find it...Can you please assist me in where i may locate on how to find it?Would like to download this too my system...Did have a windows 98 at the office i use to work at and we had microsoft there so i do believe it is somewhere.. thank you...kittenjasmine KittenJasmine, The only way you have Office is if you paid for it. It has nothing to do with which version of Windows that is installed on your compu...

HELP!!! How do you create a query crieria for multi values??
Hello all, please hyelp, its an emergency!!! Need to create a query where one of the searches is male or female, how do I allow user to enter both as the search options?? Also how do I convert tix boxes into a query criteria (e.g. serach for all ticked) Thanks so much for your help ...

Dlookup HELP 02-01-08
I am trying to use a DLOOKUP in a report To lookup a value in a stored query from information that is the report. I have a report that gives me a customers parent account name and I am trying to then use that parent account name to look up a comment stored in another query. This is how my formula looks =DLookUp("TXTFIELD","Query","Query.ParentAccount"="ParentAccountFromReport") Any sugesstions? Perhaps something along the lines of =DLookUp("TXTFIELD","Query","ParentAccount=""" & ParentAccountFromReport &a...

Macro help: Adding Specified Blank Formatted Rows Automatically?
How do I make a macro that will prompt with a dialog box to copy the rows a certain number of times. For example, if I have 2 rows of data and I want to be able to specified any number of copies of the 2 rows blank without the data but maintain the formats (colors, condition, formulas, code, etc.). I want to add the rows to the existing worksheet. Also, I would want to this macro to be flexible to maintain it�s function if I add or delete columns from the chart. See sample chart File Attached: http://www.exceltip.com/forum/attachment.php?postid=279064 (question5 sample1.xls) ----------------...

HELP: Email body deleted when I receive voting response
Hi All, I am sending emails in outlook through excel with voting buttons. But, whenever I vote using voting buttons in outlook, Email body gets deleted when the voting response email is sent. Is there any outlook property that I can use to keep the email body when the voting responses are sent? So for eg: If I have enabled voting buttons and asked to vote on something from person xyz, the person xyz votes "accept" or "reject" and the email body is deleted when I receive the vote response email. Is there a solution for this? I want the email body to stay w...

help 04-20-10
since yesterday when ever i try and open an icon on my desk top this message comes up windows cannot access the specified file, pathway you may not have permission to access it? what does this mean and how do i fix it???? Also about a week ago when i was on the internet these system messages kept coming up saying my computer was in trouble and peple were trying to access my personal information and i needed to upgrage my spyware. i couldnt go into any programes except the windows security site and then i had to buy the 6 month protection to access anything on my computer. now ...

Currently no help is associated with this page.
I use Excel 2003 on Vista. A couple of days ago, I was getting this response to many helps such as F1; Search VLOOKUP; Click VLOOKUP. The problem went when I rebooted and tried again. I am hit again by this problem. I googled without finding anything. The problem seems to be with access to "local" help; Internet help is still found. Again, a reboot cured the immediate problem. I googled again and got 2 hits. Neither went anywhere effective. I would appreciate an explanation and a less destructive fix. Thanks! -- Walter Briscoe Some versions of Excel allow you to enabl...

Simple Date problem -_- Please Help !
Hi everyone, I have list of times in hh:mm format from cell A1 to A730 e.g. 9:30, 13:00, 13:32, 12:12 etc... How do I put number of minutes passed from 9:00AM i.e. if A1 has 9:30 then B1 must display 30, if A2 has 14:12 then B2 displays 312 and so on. What kind of function do I need to use? Please help! Thanks alot :D format cell as [mm] and use =A1-TIME(9,0,0) James8309 wrote: > Hi everyone, > > I have list of times in hh:mm format from cell A1 to A730 > > e.g. 9:30, 13:00, 13:32, 12:12 etc... > > How do I put number of minutes passed from 9:00AM > >...

help hyperlinks
plz help me I have a spreadsheet column containing hyperlinks (paths) t different jpg files. How can I get it to work so that if I click on an of the hyperlinks, it will open the jpg in a Imaging application? using micros thank -- Message posted from http://www.ExcelForum.com Hi If you have created hyperlinks using Excels 'Insert hyperlink' functionality and an image application is associated to *jpg files clicking on such a hyperlink will automatically invoke your application But if you currently only have the filename as text (that is no hyperlink), you may try the following in...

Help Creating XmlNode / XmlAttribute Elegantly
I am creating a configuration class to read / write a standard configuration file. <?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="ConnectionString" value="server=(local);" /> </appSettings> </configuration> I am using a XmlDocument for my base implementation. I am looking to see if there is a better way to add a new node / attribute than using XmlDocument.InnerXml. I would consider this to be a hack but couldn't really see another way of doing this without definin...

urgent help
hi members how can I insert rows after every fiftth row I have data of more than 6000 rows that means I want to insert 2000 rows in that sequenc -- b166e ----------------------------------------------------------------------- b166er's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3491 View this thread: http://www.excelforum.com/showthread.php?threadid=55456 See other post. -- HTH Bob Phillips (replace xxxx in the email address with gmail if mailing direct) "b166er" <b166er.29t4vb_1150986001.8819@excelforum-nospam.com> wrote in message news...

help with uniforms
I have a database, I use for ordering uniform and keeping a check on employees allocation. The company we use to supply the uniform have changed their pricing structure, which is causing me a few problems. Any outsize orders are liable for a 10%, 20% , 30% or 40% mark-up At the moment all my prices are generated when you pick an item from a combo box, it automatically fills in the price. The size is input by the user. Because of the pricing changes and the sizing differences with my stock: Shirts 14” –22” Blazers 34” - 58” I was hoping to have a combo that recognises the 14” – 18.5...

Confident no one can help with this booklet issue...
Please tell me what the problem is with printing booklets. Everytime I print one the First days of teh calendar appear on page one and the the last three days and the notes appear on page two. In other versions of Outlook they printed on page two and three. Which is the way they should. Is no one printing out calendars any more? I've posted many times for help on this and can't get any. I'm using outlook XP. Is there a fix for this problem? Eric ...

Help settings up SBS 2003 with PPPoE
Hey everyone, We currently have a server in our office running sbs 2003 with a single NIC with client computers connected. We were just using a dynamic IP through DSL, but switched out to a static. I am working on setting up the static through PPPoE but know adjustments must be made. Can anyone guide me through the setup? I had trouble finding a guide online. Do I need to switch to a two NIC config? What adjustments need to be made through the router and sbs connection set up? I'm a little confused on all of it. Any help would be appreciated!! Thanks Alex What r...

HELP: Need to transfer/share files between 2 PC through Internet.
I need to develop a program to conncet two systems through dial up connection and to share the files/folders of that tho systems.... any idea.. any guidance... warm welcome..... regards, Aji. ...

Item / ItemDynamic Help
We are running HQ and SO 1.3r. We have an "outside" application that has loaded some items into the HQ database. However, the programmer failed to load the corresponding ItemDynamic entries. Can someone provide me with a SQL program that will search through the ITEM table and add the appropriate ITEMDYNAMIC entries for each of our stores? So, far - no inventory has been received for these items but they soon will be and then this problem will only be compounded. Your SQL expert assistance is requested. Thank you ... in advance. This is a multi-part message in MIME format. -...

Need help in coding outlook
Hi, For Each oMailItem In oInbox.Items Debug.Print oMailItem.SenderName Next The above codes are part of my code. The issue is when the inbox item is not mail item the code will be error. When the inbox item is a report item (delivery failure notification) the code will be error. How to fixed that? Regards, Gunawan You can use the .Class property to determine what kind of item it is, before you invoke the properties and methods of a particular type of Outlook item. FYI, there is a newsgroup specifically for general Outlook programming issues "down the hall" at microsoft.pu...

Help with vba autorunning macro?
Hello, How do I automate (write code in Access) to tell it to run a macro I had created in Access everyday at 6AM? I tried using Windows XP Task Scheduler, but it didn't work. Any help is appreciated. THanks What does "it didn't work" mean in the context of trying to use Task Scheduler? What command line did you try? -- Doug Steele, Microsoft Access MVP http://www.AccessMVP.com/DJSteele Co-author: Access 2010 Solutions, published by Wiley (no e-mails, please!) "Cam" <Cam@discussions.microsoft.com> wrote in message news:99EABB88-3DDA-...

Very basic help request
I have a database that has 6 columns and 2000 rows. Row 1 has 27 different types of category text entries. I wish to create 27 different databases from the big one, each containing all and only the rows/entries corresponding to each of the 27 categories. Can someone give me a pointer as to the method, or the terminology that I should Google for or lok in the Help for. Very basic I am sure but not easy when one doesn't know the terminology. Thanks for any help. Brian Tozer "KiwiBrian" <briantoz@ihug.co.nz> wrote in message news:%23aFPhOaiEHA.2992@TK2MSFTNGP12.phx.gbl... ...