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. CComboBox list Appears After Trying to Close out Dialog

CComboBox list Appears After Trying to Close out Dialog

Scheduled Pinned Locked Moved C / C++ / MFC
hostingdata-structureshelpquestion
6 Posts 2 Posters 2 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 Decided to start a new thread because for a moment I thought I had fixed my problem of the Disappearing list with the following code I added a point to an array pointer for the strings I wanted to add

    class Casidcombo : public CComboBox
    {
    DECLARE_DYNAMIC(Casidcombo)
    private:
    int cright, cbottom, ctop;

    public:
    Casidcombo();
    ~Casidcombo();
    char **arrayptr;
    protected:

    virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
    virtual void DrawItem(LPDRAWITEMSTRUCT pdi);
    virtual int CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct);
    virtual void DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct);
    DECLARE\_MESSAGE\_MAP()
    

    };

    its the arrayptr not knowing exactly how may entries I would have I initialize it in the OnInitDialogBox of the the Hosting Dialog

    m_Simple.arrayptr = new char *[j+1];
    for (int i = 0; i < j + 1; i++)
    m_Simple.arrayptr[i] = NULL;

    In the DrawItem For The Combobox I copy of over part of the string

    if(arrayptr[pdi->itemID] == NULL)
    arrayptr[pdi->itemID] = new char(9);
    memset(arrayptr[pdi->itemID], 0x00, 9);
    memcpy(arrayptr[pdi->itemID], lpszText, 8);

    I then write it out

    dc.DrawText(
    arrayptr[pdi->itemID],
    8,
    &pdi->rcItem,
    DT_CENTER | DT_SINGLELINE | DT_VCENTER);

    The list now re-appears After I try closing out the Dialog by clicking on the 'X' in the right hand Corner I guess this drives the DrawItem function My question is after appearing and disappearing initially (the list) of the ComboBox the vertical scroll bar is missing as well until I clisk on the 'X' in the right hand corner after which everything re-appears I guess that most Drive DrawItem I am still Baffled Why initially it disappears along with the scroll bar This the last piece of code in the OnInitDialog

    ShowWindow(SW_SHOW);
    ShowWindow(SW_SHOW);

    	return TRUE;
    

    This is my message map I only have a Measure Item Message
    BEGIN_MESSAGE_MAP(Casidcombo, CComboBox)
    ON_WM_MEASUREITEM()
    END_MESSAGE_MAP()

    L 1 Reply Last reply
    0
    • F ForNow

      Hi I Decided to start a new thread because for a moment I thought I had fixed my problem of the Disappearing list with the following code I added a point to an array pointer for the strings I wanted to add

      class Casidcombo : public CComboBox
      {
      DECLARE_DYNAMIC(Casidcombo)
      private:
      int cright, cbottom, ctop;

      public:
      Casidcombo();
      ~Casidcombo();
      char **arrayptr;
      protected:

      virtual void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
      virtual void DrawItem(LPDRAWITEMSTRUCT pdi);
      virtual int CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct);
      virtual void DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct);
      DECLARE\_MESSAGE\_MAP()
      

      };

      its the arrayptr not knowing exactly how may entries I would have I initialize it in the OnInitDialogBox of the the Hosting Dialog

      m_Simple.arrayptr = new char *[j+1];
      for (int i = 0; i < j + 1; i++)
      m_Simple.arrayptr[i] = NULL;

      In the DrawItem For The Combobox I copy of over part of the string

      if(arrayptr[pdi->itemID] == NULL)
      arrayptr[pdi->itemID] = new char(9);
      memset(arrayptr[pdi->itemID], 0x00, 9);
      memcpy(arrayptr[pdi->itemID], lpszText, 8);

      I then write it out

      dc.DrawText(
      arrayptr[pdi->itemID],
      8,
      &pdi->rcItem,
      DT_CENTER | DT_SINGLELINE | DT_VCENTER);

      The list now re-appears After I try closing out the Dialog by clicking on the 'X' in the right hand Corner I guess this drives the DrawItem function My question is after appearing and disappearing initially (the list) of the ComboBox the vertical scroll bar is missing as well until I clisk on the 'X' in the right hand corner after which everything re-appears I guess that most Drive DrawItem I am still Baffled Why initially it disappears along with the scroll bar This the last piece of code in the OnInitDialog

      ShowWindow(SW_SHOW);
      ShowWindow(SW_SHOW);

      	return TRUE;
      

      This is my message map I only have a Measure Item Message
      BEGIN_MESSAGE_MAP(Casidcombo, CComboBox)
      ON_WM_MEASUREITEM()
      END_MESSAGE_MAP()

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I have used user drawn ListView controls without problem in the past. I notice that you are using a CDC to draw the text in the view rather than responding to the notification messages and returning the relevant data. However, my sample does not use MFC so I may well be on the wrong track.

      F 1 Reply Last reply
      0
      • L Lost User

        I have used user drawn ListView controls without problem in the past. I notice that you are using a CDC to draw the text in the view rather than responding to the notification messages and returning the relevant data. However, my sample does not use MFC so I may well be on the wrong track.

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

        Richard there are two api in DrawItem that are not supported in Native Win32 FillSolidRect only thing close is FillRect which takes a brush Regardless I was getting a heap corruption so I ran my code in debug with the following

        // InitCommonControlsEx(&InitCtrls);
        #if _DEBUG
        afxMemDF = allocMemDF | checkAlwaysMemDF;
        #endif

        and at exiting DrawItem got the following

        #if defined _NO_CRT_STDIO_INLINE
        ;
        #else
        {
        int const _Result = __stdio_common_vsnprintf_s(
        _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS,
        _Buffer, _BufferCount, _MaxCount, _Format, _Locale, _ArgList);

        return \_Result < 0 ? -1 : \_Result;
        

        }
        #endif

        Exiting DrawItem I am getting a heap corruption

        L 1 Reply Last reply
        0
        • F ForNow

          Richard there are two api in DrawItem that are not supported in Native Win32 FillSolidRect only thing close is FillRect which takes a brush Regardless I was getting a heap corruption so I ran my code in debug with the following

          // InitCommonControlsEx(&InitCtrls);
          #if _DEBUG
          afxMemDF = allocMemDF | checkAlwaysMemDF;
          #endif

          and at exiting DrawItem got the following

          #if defined _NO_CRT_STDIO_INLINE
          ;
          #else
          {
          int const _Result = __stdio_common_vsnprintf_s(
          _CRT_INTERNAL_LOCAL_PRINTF_OPTIONS,
          _Buffer, _BufferCount, _MaxCount, _Format, _Locale, _ArgList);

          return \_Result < 0 ? -1 : \_Result;
          

          }
          #endif

          Exiting DrawItem I am getting a heap corruption

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          You need to actually trace the code to see where the heap is getting corrupted. It is usually caused by writing too many bytes into an allocated buffer. Notice that __stdio_common_vsnprintf_s takes two values which indicate the length, so one of them could be wrong.

          F 1 Reply Last reply
          0
          • L Lost User

            You need to actually trace the code to see where the heap is getting corrupted. It is usually caused by writing too many bytes into an allocated buffer. Notice that __stdio_common_vsnprintf_s takes two values which indicate the length, so one of them could be wrong.

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

            I Did but I don't understand why I am getting a list of Addreess Spaces information from z/os I only want to Add the the list box the Job Name. Asid information is 45 bytes the first 8 is the JobName. So the First would be *Master* I moved the code which copies the first 8 charcates from CComboBox::DrawItem to the DialogBox just got Debug Assert on the AddString I think I am doing everything right;

            m_Simple.arrayptr = new char *[j+1];
            traverse = instr;
            for (int i = 0; i < j + 1; i++)
            {
            m_Simple.arrayptr[i] = new char(9);
            memset(m_Simple.arrayptr[i], 0x00, 9);
            memcpy(m_Simple.arrayptr[i], traverse, 8);
            m_Simple.AddString(m_Simple.arrayptr[i]);
            traverse = (char *)traverse + 45;
            }

            The twisted Arrow after the Debug Heap Assertion is pointing to

            traverse = (char *)traverse + 45

            So I guess there is a problem with AddString Not sure what I am doing wrong

            L 1 Reply Last reply
            0
            • F ForNow

              I Did but I don't understand why I am getting a list of Addreess Spaces information from z/os I only want to Add the the list box the Job Name. Asid information is 45 bytes the first 8 is the JobName. So the First would be *Master* I moved the code which copies the first 8 charcates from CComboBox::DrawItem to the DialogBox just got Debug Assert on the AddString I think I am doing everything right;

              m_Simple.arrayptr = new char *[j+1];
              traverse = instr;
              for (int i = 0; i < j + 1; i++)
              {
              m_Simple.arrayptr[i] = new char(9);
              memset(m_Simple.arrayptr[i], 0x00, 9);
              memcpy(m_Simple.arrayptr[i], traverse, 8);
              m_Simple.AddString(m_Simple.arrayptr[i]);
              traverse = (char *)traverse + 45;
              }

              The twisted Arrow after the Debug Heap Assertion is pointing to

              traverse = (char *)traverse + 45

              So I guess there is a problem with AddString Not sure what I am doing wrong

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              I can only assume that your instr variable does not contain the number of 45 character fields that you think. However only the debugger could confirm that.

              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