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. CComobox::DrawItem list box entries Disappears In Release Mode

CComobox::DrawItem list box entries Disappears In Release Mode

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingcsharpvisual-studiotutorialannouncement
7 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.
  • F Offline
    F Offline
    ForNow
    wrote on last edited by
    #1

    Hi I have CBS_SIMPLE CBS_OWNERDRAWVARIABLE ComboBox that I populate via DrawItem using DrawText everything works fine in debug mode and for that matter in release mode while under the Visual Studio Debugger However When I run code in Release not under the debugger the list box entries appear for a instant and then disappear Any Suggestion how to go about debugging would be appreciated

    L V 2 Replies Last reply
    0
    • F ForNow

      Hi I have CBS_SIMPLE CBS_OWNERDRAWVARIABLE ComboBox that I populate via DrawItem using DrawText everything works fine in debug mode and for that matter in release mode while under the Visual Studio Debugger However When I run code in Release not under the debugger the list box entries appear for a instant and then disappear Any Suggestion how to go about debugging would be appreciated

      L Offline
      L Offline
      leon de boer
      wrote on last edited by
      #2

      Your code is relying on a local variable value to start zero and it won't be in release (they start unset usually just junk whatever was on the stack beforehand when it gets allocated) but in debug it zeros all local variables. It is one of the core differences between debug and release mode. Usually its something like a bool flag that is assumed to start false (0) which won't in release mode as any non zero value means true. Just check which local variable(s) you are assuming starts as zero and set the thing to zero manually :-)

      /* this will behave the same as someGoodFunc in debug but not in release */
      void someWrongFunc (void)
      {
      bool IamaBadBool;
      }

      void someGoodFunc (void)
      {
      bool IamGoodBool = 0;
      }

      In vino veritas

      F 1 Reply Last reply
      0
      • F ForNow

        Hi I have CBS_SIMPLE CBS_OWNERDRAWVARIABLE ComboBox that I populate via DrawItem using DrawText everything works fine in debug mode and for that matter in release mode while under the Visual Studio Debugger However When I run code in Release not under the debugger the list box entries appear for a instant and then disappear Any Suggestion how to go about debugging would be appreciated

        V Offline
        V Offline
        Victor Nijegorodov
        wrote on last edited by
        #3

        Have a look at this great Joe Newcomer's essay: [Debug vs. Release](http://www.flounder.com/debug\_release.htm)

        F 1 Reply Last reply
        0
        • L leon de boer

          Your code is relying on a local variable value to start zero and it won't be in release (they start unset usually just junk whatever was on the stack beforehand when it gets allocated) but in debug it zeros all local variables. It is one of the core differences between debug and release mode. Usually its something like a bool flag that is assumed to start false (0) which won't in release mode as any non zero value means true. Just check which local variable(s) you are assuming starts as zero and set the thing to zero manually :-)

          /* this will behave the same as someGoodFunc in debug but not in release */
          void someWrongFunc (void)
          {
          bool IamaBadBool;
          }

          void someGoodFunc (void)
          {
          bool IamGoodBool = 0;
          }

          In vino veritas

          F Offline
          F Offline
          ForNow
          wrote on last edited by
          #4

          the only thing I can come with first is this piece of code I only display part of the string in the list box

          void Casidcombo::DrawItem(LPDRAWITEMSTRUCT pdi)
          {
          ASSERT(pdi->CtlType == ODT_COMBOBOX);
          LPCTSTR lpszText = (LPCTSTR)pdi->itemData;

          ASSERT(lpszText == NULL);
          CDC dc;
          CWnd\* phwnd = CWnd::FromHandle(pdi->hwndItem);
          
          dc.Attach(pdi->hDC);
          CString str(lpszText,8);   // Get the first 8 charcaters
          

          and later write it out

          // Draw the text.
          dc.DrawText(
          str,
          (int)_tcslen(str),
          &pdi->rcItem,
          DT_CENTER | DT_SINGLELINE | DT_VCENTER);

          However str is on the stack and would disappear after exiting draw item ? I'll try it out

          L V 2 Replies Last reply
          0
          • V Victor Nijegorodov

            Have a look at this great Joe Newcomer's essay: [Debug vs. Release](http://www.flounder.com/debug\_release.htm)

            F Offline
            F Offline
            ForNow
            wrote on last edited by
            #5

            thanks

            1 Reply Last reply
            0
            • F ForNow

              the only thing I can come with first is this piece of code I only display part of the string in the list box

              void Casidcombo::DrawItem(LPDRAWITEMSTRUCT pdi)
              {
              ASSERT(pdi->CtlType == ODT_COMBOBOX);
              LPCTSTR lpszText = (LPCTSTR)pdi->itemData;

              ASSERT(lpszText == NULL);
              CDC dc;
              CWnd\* phwnd = CWnd::FromHandle(pdi->hwndItem);
              
              dc.Attach(pdi->hDC);
              CString str(lpszText,8);   // Get the first 8 charcaters
              

              and later write it out

              // Draw the text.
              dc.DrawText(
              str,
              (int)_tcslen(str),
              &pdi->rcItem,
              DT_CENTER | DT_SINGLELINE | DT_VCENTER);

              However str is on the stack and would disappear after exiting draw item ? I'll try it out

              L Offline
              L Offline
              leon de boer
              wrote on last edited by
              #6

              Str is on the stack and will go bye bye as soon as you leave the function.

              In vino veritas

              1 Reply Last reply
              0
              • F ForNow

                the only thing I can come with first is this piece of code I only display part of the string in the list box

                void Casidcombo::DrawItem(LPDRAWITEMSTRUCT pdi)
                {
                ASSERT(pdi->CtlType == ODT_COMBOBOX);
                LPCTSTR lpszText = (LPCTSTR)pdi->itemData;

                ASSERT(lpszText == NULL);
                CDC dc;
                CWnd\* phwnd = CWnd::FromHandle(pdi->hwndItem);
                
                dc.Attach(pdi->hDC);
                CString str(lpszText,8);   // Get the first 8 charcaters
                

                and later write it out

                // Draw the text.
                dc.DrawText(
                str,
                (int)_tcslen(str),
                &pdi->rcItem,
                DT_CENTER | DT_SINGLELINE | DT_VCENTER);

                However str is on the stack and would disappear after exiting draw item ? I'll try it out

                V Offline
                V Offline
                Victor Nijegorodov
                wrote on last edited by
                #7

                ForNow wrote:

                dc.Attach(pdi->hDC);
                CString str(lpszText,8); // Get the first 8 charcaters

                and later write it out

                // Draw the text.
                dc.DrawText(
                str,
                (int)_tcslen(str),

                BTW, if you are using CString then you have to use CString::GetLength(), not the C-runtime _tcslen(str).

                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