CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Mar 2004
    Posts
    119

    Weird "bug" with CStatic controls

    OK I just discovered something weird. If you set the "notify" property of a static control to true then any time you double click on that control it copies the text of the control to the clipboard. I've traced this down to something inside MFC because I can create a very simple dialog based app, with all the defaults, set the static control in the middle with "TODO: Place dialog controls here." to notify and if I run it and double click the static that text is copied to the clipboard every time.

    This is using VS2010

    Does anyone know of anyway to turn that off? We have a static control in our app that when double click launches a dialog that allows you to change a value. By copying the value of the static it overwrites whatever the user already has on their clipboard, which is usually what they intend to paste into the dialog. So it's very annoying. Plus I was always told it's bad practice to overwrite the clipboard without the user specifically requesting it.

    Dan

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Weird "bug" with CStatic controls

    This problem is described here. it is delphi, however the problem is the same.
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Weird "bug" with CStatic controls

    Attached you can find the minimalistic Win32 API and MFC apps. Neither of those produces the effect you described. The OS is Windows 7 x64 SP1.

    PS. Just made sure, neither is does in Vista x32 SP1.
    Attached Files Attached Files
    Last edited by Igor Vartanov; March 4th, 2015 at 03:11 AM.
    Best regards,
    Igor

  4. #4
    Join Date
    Mar 2004
    Posts
    119

    Re: Weird "bug" with CStatic controls

    After some research I narrowed it down to the manifest. If you don't include a manifest it doesn't do it, but if you do then it does. However without the manifest the controls all look like crap, so that's not a viable option for our product.

  5. #5
    Join Date
    Mar 2004
    Posts
    119

    Re: Weird "bug" with CStatic controls

    Also subclassing the control and handling the double click myself does not work because the copy happens before the double click handler is called. I verified by adding a break point to the top of the double click handler and checking the clipboard as soon as it breaks.

    This is a stupid "feature" they decided to add. Why would they just assume everyone wants to copy the contents of a static control on double click?

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Weird "bug" with CStatic controls

    Quote Originally Posted by Dan203 View Post
    This is a stupid "feature" they decided to add. Why would they just assume everyone wants to copy the contents of a static control on double click?
    I agree it looks like "stupid".
    I wonder, however, why you are using static control with double-clicking on it. Why not use a button? A read-only edit control?
    Victor Nijegorodov

  7. #7
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Weird "bug" with CStatic controls

    I would disagree about stupid thing.

    Being not able to copy a label text is same stupid, or even worse stupid. You might object that it's not that frequent situation when people need a label copy, but the same infrequent label double-clicking is. I assure you, for all those years I deal with Windows, until today, I never had a thought about double-clicking static. Just because I know its a static. Why would anybody double-click static at all?

    At the same time I was in need of copying label text too many times, and each time I thought "why wouldn't they make it a read-only edit box?"
    Best regards,
    Igor

  8. #8
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Weird "bug" with CStatic controls

    This is an awesome feature, and the biggest fail with it is that they totally forgot to do anything significant with it in the most obvious of places when Windows Vista came around.

    For example: It would have been awesome if messageboxes had the message text static control have SS_NOTIFY, but alas...

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Weird "bug" with CStatic controls

    Quote Originally Posted by OReubens View Post
    It would have been awesome if messageboxes had the message text static control have SS_NOTIFY, but alas...
    Well, classical message box supports Ctrl-C. You should give it a try.
    Best regards,
    Igor

  10. #10
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Weird "bug" with CStatic controls

    Quote Originally Posted by Dan203 View Post
    Also subclassing the control and handling the double click myself does not work because the copy happens before the double click handler is called. I verified by adding a break point to the top of the double click handler and checking the clipboard as soon as it breaks.
    Interesting. The subclassing and handling WM_LBUTTONDBLCLK message (without calling base class' CStatic::OnLButtonDblClk(nFlags, point) works fine for me.
    The copy obviously happens in CStatic control's handler for double-click.
    Are you sure you have correctly subclass it?
    Can you show your code?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  11. #11
    Join Date
    Mar 2004
    Posts
    119

    Re: Weird "bug" with CStatic controls

    Quote Originally Posted by VladimirF View Post
    Interesting. The subclassing and handling WM_LBUTTONDBLCLK message (without calling base class' CStatic::OnLButtonDblClk(nFlags, point) works fine for me.
    The copy obviously happens in CStatic control's handler for double-click.
    Are you sure you have correctly subclass it?
    Can you show your code?
    You're right I was using STN_DBLCLICK in the subclass, which is called after the copy. If I use WM_LBUTTONDBLCLK instead then I can catch it before the copy happens.

    Still think this is stupid. If people wanted to copy the contents of a static they could sub class it and handle the double click themselves. Not sure why they make it the default.

  12. #12
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Weird "bug" with CStatic controls

    Quote Originally Posted by Dan203 View Post
    You're right I was using STN_DBLCLICK in the subclass, which is called after the copy. If I use WM_LBUTTONDBLCLK instead then I can catch it before the copy happens.
    Glad it worked.

    Still think this is stupid. If people wanted to copy the contents of a static they could sub class it and handle the double click themselves. Not sure why they make it the default.
    Well, some might think that trying to double-click static control to get some action out of it is also not very intuitive.
    However, did you know that a simple message box like that:
    Code:
    ::MessageBox(m_hWnd, L"This is a test", L"Caption", MB_OK);
    supports a Copy command? Hitting Ctrl+C copies this to the clipboard:
    ---------------------------
    Caption
    ---------------------------
    This is a test
    ---------------------------
    OK
    ---------------------------
    <Oops... I see that Igor already mentioned that>
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  13. #13
    Join Date
    Mar 2004
    Posts
    119

    Re: Weird "bug" with CStatic controls

    We have a video editing app called VideoReDo. The static control in question is the one displaying the current timecode. Double clicking on it brings up a dialog that allows you to jump to any time code in the file. The same action can be triggered via a menu item and a key combination, but it makes sense to double click as well. Apparently this "bug" has been there for a while, we just had one of our customers bring it to our attention for the first time.

  14. #14
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Weird "bug" with CStatic controls

    The whole situation just confirms once again the rule of my own: don't mess with classical "old" controls, like static, edit box, list box or combo. Just don't. You want something fancy, you create your own one.
    Best regards,
    Igor

  15. #15
    Join Date
    Mar 2004
    Posts
    119

    Re: Weird "bug" with CStatic controls

    The control was already subclassed, as we offer skinning and everything is custom drawn, but I use the MFC base classes because it makes it easier to lay everything out in the dialog editor and allows us to use DDX to set the values.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured