CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [RESOLVED] [win32] - strange effect with mouse leave and mouse enter in cyle way :(

    Name:  mouse leave and mouse enter in cyle.gif
Views: 177
Size:  74.8 KB
    see the image... more or less where is that arrow(pixel less pixel... sorry i can't print screen with the mouse cursor ) the Mouse Enter and Mouse Leave are executed in infinite cycle until i move to another place. can anyone explain how these is possible?

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: [win32] - strange effect with mouse leave and mouse enter in cyle way :(

    Quote Originally Posted by Cambalinho View Post
    Name:  mouse leave and mouse enter in cyle.gif
Views: 177
Size:  74.8 KB
    see the image... more or less where is that arrow(pixel less pixel... sorry i can't print screen with the mouse cursor ) the Mouse Enter and Mouse Leave are executed in infinite cycle until i move to another place. can anyone explain how these is possible?
    Let's talk code, and not pictures.

    The reason why an infinite loop occurs is if you process a message, and that message triggers another message, and eventually those messages leads to one or more of the previous messages being sent. Thus you have an infinite loop.

    So debug your code to figure out which message starts this chain of events.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [win32] - strange effect with mouse leave and mouse enter in cyle way :(

    Quote Originally Posted by Paul McKenzie View Post
    Let's talk code, and not pictures.

    The reason why an infinite loop occurs is if you process a message, and that message triggers another message, and eventually those messages leads to one or more of the previous messages being sent. Thus you have an infinite loop.

    So debug your code to figure out which message starts this chain of events.

    Regards,

    Paul McKenzie
    when i move the mouse(enter) the text is changed and if the autosize is true resize the control. depending on control size and if we don't move the mouse, these effect will happen in cyle.
    thanks for all

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: [RESOLVED] [win32] - strange effect with mouse leave and mouse enter in cyle way

    So debug the code. Find out what messages are being received in what order and trace through how you are handling these. As Paul stated in his post #2, in processing a particular message you may cause the same message to be generated, which causes the same message to be generated ad-infinitum - an infinite loop. Once you have determined what part of your code is causing this then you will need to consider how you want to deal with it. Note that this may not be as simple as Message A generating another Message A. In complex windows code you might find something like this
    Message A -> Message B -> Message C -> Message D -> Message A

    Oh the fun to be had!
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [RESOLVED] [win32] - strange effect with mouse leave and mouse enter in cyle way

    Quote Originally Posted by 2kaud View Post
    So debug the code. Find out what messages are being received in what order and trace through how you are handling these. As Paul stated in his post #2, in processing a particular message you may cause the same message to be generated, which causes the same message to be generated ad-infinitum - an infinite loop. Once you have determined what part of your code is causing this then you will need to consider how you want to deal with it. Note that this may not be as simple as Message A generating another Message A. In complex windows code you might find something like this
    Message A -> Message B -> Message C -> Message D -> Message A

    Oh the fun to be had!
    these type of loop can't be resolved, unless i avoid use mouse leave or mouse enter when autosize is true

  6. #6
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: [RESOLVED] [win32] - strange effect with mouse leave and mouse enter in cyle way

    these type of loop can't be resolved,
    Yes it can but it isn't nice. First find out which message corresponds to Message A - ie the first message in the loop. For each window define a state flag and set to false. Then at the start of the code for Message A test the flag and if set to true, just break out of message processing. If false then set to true, perform the rest of the message code and before normal exit reset the state back to false. Thus when Message A gets called again before Message A has completed it just exits and does nothing so breaks the loop. If you have multiple threads use the interlockxxx set of functions to set/reset and test the state flag.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

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