Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Code only works with breakpoint

Code only works with breakpoint

Scheduled Pinned Locked Moved C / C++ / MFC
c++cssdebugginghelpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Steen Krogsgaard
    wrote on last edited by
    #1

    Hi, I have a very spurious problem. I have a MFC Grid (thanks, Chris!) in a view in a MFC app. I want the grid to change the sort order of the items when the user clicks the header. So if the first item is selected when the header is clicked the grid should reverse the items and scroll down to the last item. I have implemented the scrolling part this way:

    void CMyGridCtrlDerivative::SetNewPosition(int nPos)
    {
    ...code
    SetScrollPos32(SB_VERT, nPos * GetRowHeight(nPos));
    SendMessage(WM_VSCROLL, SB_THUMBPOSITION, 0);
    }

    where nPos is the new position (linenumber) to scroll to. All items have the same height, so I use the height of the nPos'th item to convert from linenumber to pixel. This does not work when I execute the program with Go (F5) - the items are reversed after click on header but the grid does not scroll down, and the thumb position on the scroll bar is not changed. However, if I put a breakpoint on the SendMessage-line, and the execute with Go (F5) and press Go (F5) again when the app breaks, then everything works as planned! I don't change anything during the break, I just press F5. I have tried to put a pause (Sleep(5000)) between the SetScrollPos32 and SendMessage calls, didn't work. I changed the SendMessage to a PostMessage, didn't work. What the f*** is going on????? Cheers Steen. "To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"

    Y S 2 Replies Last reply
    0
    • S Steen Krogsgaard

      Hi, I have a very spurious problem. I have a MFC Grid (thanks, Chris!) in a view in a MFC app. I want the grid to change the sort order of the items when the user clicks the header. So if the first item is selected when the header is clicked the grid should reverse the items and scroll down to the last item. I have implemented the scrolling part this way:

      void CMyGridCtrlDerivative::SetNewPosition(int nPos)
      {
      ...code
      SetScrollPos32(SB_VERT, nPos * GetRowHeight(nPos));
      SendMessage(WM_VSCROLL, SB_THUMBPOSITION, 0);
      }

      where nPos is the new position (linenumber) to scroll to. All items have the same height, so I use the height of the nPos'th item to convert from linenumber to pixel. This does not work when I execute the program with Go (F5) - the items are reversed after click on header but the grid does not scroll down, and the thumb position on the scroll bar is not changed. However, if I put a breakpoint on the SendMessage-line, and the execute with Go (F5) and press Go (F5) again when the app breaks, then everything works as planned! I don't change anything during the break, I just press F5. I have tried to put a pause (Sleep(5000)) between the SetScrollPos32 and SendMessage calls, didn't work. I changed the SendMessage to a PostMessage, didn't work. What the f*** is going on????? Cheers Steen. "To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"

      Y Offline
      Y Offline
      YoSilver
      wrote on last edited by
      #2

      It is not a good idea to handle scrolling by sending WM_xSCROLL messages, as there many problem will arise, as you call SetScrollPos32 and then send WM_VSCROLL + SB_THUMBPOSITION which is processed internally so that it interferes with previous call of SetScrollPos32. Also read the excellent book by Richter on Win32 programming, namely - section on message queuing. You'd better deal with functions that perform necessary operations when WM_xSCROLL messages are received. Just an example: void CMyGridCtrlDerivative::SetNewPosition(int nPos) { ...code SetScrollPos32(SB_VERT, nPos * GetRowHeight(nPos)); // SendMessage(WM_VSCROLL, SB_THUMBPOSITION, 0); DoProcessWmVscroll(SB_THUMBPOSITION); }

      1 Reply Last reply
      0
      • S Steen Krogsgaard

        Hi, I have a very spurious problem. I have a MFC Grid (thanks, Chris!) in a view in a MFC app. I want the grid to change the sort order of the items when the user clicks the header. So if the first item is selected when the header is clicked the grid should reverse the items and scroll down to the last item. I have implemented the scrolling part this way:

        void CMyGridCtrlDerivative::SetNewPosition(int nPos)
        {
        ...code
        SetScrollPos32(SB_VERT, nPos * GetRowHeight(nPos));
        SendMessage(WM_VSCROLL, SB_THUMBPOSITION, 0);
        }

        where nPos is the new position (linenumber) to scroll to. All items have the same height, so I use the height of the nPos'th item to convert from linenumber to pixel. This does not work when I execute the program with Go (F5) - the items are reversed after click on header but the grid does not scroll down, and the thumb position on the scroll bar is not changed. However, if I put a breakpoint on the SendMessage-line, and the execute with Go (F5) and press Go (F5) again when the app breaks, then everything works as planned! I don't change anything during the break, I just press F5. I have tried to put a pause (Sleep(5000)) between the SetScrollPos32 and SendMessage calls, didn't work. I changed the SendMessage to a PostMessage, didn't work. What the f*** is going on????? Cheers Steen. "To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"

        S Offline
        S Offline
        Stephane Rodriguez
        wrote on last edited by
        #3

        If you put a breakpoint, it totally changes both the message queue and the paint workflow ( additional Invalidate() and Update() methods, plus WM_PAINT commands will be sent to your window(s) ). That's due to the app switch to the breakpoint. And that's the reason the behavior of your app foes not change if you post some messages or add Sleep().


        MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site. Support for development will ship at the same time as the Windows XP Service Pack 1 (SP1) release.

        S 1 Reply Last reply
        0
        • S Stephane Rodriguez

          If you put a breakpoint, it totally changes both the message queue and the paint workflow ( additional Invalidate() and Update() methods, plus WM_PAINT commands will be sent to your window(s) ). That's due to the app switch to the breakpoint. And that's the reason the behavior of your app foes not change if you post some messages or add Sleep().


          MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site. Support for development will ship at the same time as the Windows XP Service Pack 1 (SP1) release.

          S Offline
          S Offline
          Steen Krogsgaard
          wrote on last edited by
          #4

          Thanks for the replies. I finaly figured out what was wrong, and as you suggested the breakpoint-thing was due to a WM_PAINT being send to the grid between the statements. The problem was that SetScrollPos32 uses SetScrollInfo, where you can set the scroll bar position but not the thumb track position. The WM_VSCROLL handler in the grid would read the thumb track position (and not the scroll bar position) in response to SB_THUMBPOSITION and this would in turn set the first item to be displayed to a wrong value. The WM_PAINT message send by the break/continue event would invoke OnDraw, where the first item to be displayed would be set from the scroll bar position (and not the thumb track position), hence this worked. I just removed the SendMessage(WM_VSCROLL, SB_THUMBPOSITION, 0) and replaced it with a call to Invalidate() - and then everything worked. Thanks for yourhelp Cheers Steen. "To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups