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. changing text of listCtrl-header - part two

changing text of listCtrl-header - part two

Scheduled Pinned Locked Moved C / C++ / MFC
helpdebuggingtutorialquestionannouncement
8 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.
  • E Offline
    E Offline
    ensger
    wrote on last edited by
    #1

    Got good help last week for changing text of listCtrl-header and I thougth, my problem is solved. I've the following code: void koarkstewView::alterheadercontent() { LVCOLUMN lvc; CString titel; CListCtrl &listCtrl = GetListCtrl(); koarkstewDoc* pDoc = GetDocument(); karkst *karkstanz; karkstanz = pDoc->karkstanz; pDoc->SetTitle("KAR->KST"); int i = 3; if (karkstanz->wdfirst()) do { i++; titel = karkstanz->wdgetkarnr() + "\n"; titel = titel + gettitel(0, karkstanz->wdgetdatenart(), karkstanz->wdgetvon(), karkstanz->wdgetbis()); listCtrl.GetColumn(i, &lvc); lvc.pszText = titel.GetBuffer(0); titel.ReleaseBuffer(); listCtrl.SetColumn(i, &lvc); } while(karkstanz->wdnext()); } Works fine - but only in debug-mode!! In release-mode, the text doesn't change:mad: But how to debug the code, if it work's in debug-mode:confused: Any proposals?? Thanks, Gerhard

    P D 2 Replies Last reply
    0
    • E ensger

      Got good help last week for changing text of listCtrl-header and I thougth, my problem is solved. I've the following code: void koarkstewView::alterheadercontent() { LVCOLUMN lvc; CString titel; CListCtrl &listCtrl = GetListCtrl(); koarkstewDoc* pDoc = GetDocument(); karkst *karkstanz; karkstanz = pDoc->karkstanz; pDoc->SetTitle("KAR->KST"); int i = 3; if (karkstanz->wdfirst()) do { i++; titel = karkstanz->wdgetkarnr() + "\n"; titel = titel + gettitel(0, karkstanz->wdgetdatenart(), karkstanz->wdgetvon(), karkstanz->wdgetbis()); listCtrl.GetColumn(i, &lvc); lvc.pszText = titel.GetBuffer(0); titel.ReleaseBuffer(); listCtrl.SetColumn(i, &lvc); } while(karkstanz->wdnext()); } Works fine - but only in debug-mode!! In release-mode, the text doesn't change:mad: But how to debug the code, if it work's in debug-mode:confused: Any proposals?? Thanks, Gerhard

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      ensger wrote:

      listCtrl.GetColumn(i, &lvc); lvc.pszText = titel.GetBuffer(0); titel.ReleaseBuffer(); listCtrl.SetColumn(i, &lvc);

      Modify this to,

      LVCOLUMN lvc= {0};
      listCtrl.GetColumn(i, &lvc);
      lvc.mask = LVCF_TEXT ;
      lvc.pszText = titel.GetBuffer(0);
      titel.ReleaseBuffer();
      listCtrl.SetColumn(i, &lvc);

      Read this[^] article for better understanding of difference betn release and debug configuration.

      Prasad Notifier using ATL | Operator new[],delete[][^]

      E 1 Reply Last reply
      0
      • P prasad_som

        ensger wrote:

        listCtrl.GetColumn(i, &lvc); lvc.pszText = titel.GetBuffer(0); titel.ReleaseBuffer(); listCtrl.SetColumn(i, &lvc);

        Modify this to,

        LVCOLUMN lvc= {0};
        listCtrl.GetColumn(i, &lvc);
        lvc.mask = LVCF_TEXT ;
        lvc.pszText = titel.GetBuffer(0);
        titel.ReleaseBuffer();
        listCtrl.SetColumn(i, &lvc);

        Read this[^] article for better understanding of difference betn release and debug configuration.

        Prasad Notifier using ATL | Operator new[],delete[][^]

        E Offline
        E Offline
        ensger
        wrote on last edited by
        #3

        Many thanks, it work's. And thank's for the link. I'll have to read cause I didn't recognice till yet, that programs that work in debug-mode maybe will not work in release-mode.

        P 1 Reply Last reply
        0
        • E ensger

          Many thanks, it work's. And thank's for the link. I'll have to read cause I didn't recognice till yet, that programs that work in debug-mode maybe will not work in release-mode.

          P Offline
          P Offline
          prasad_som
          wrote on last edited by
          #4

          ensger wrote:

          didn't recognice till yet, that programs that work in debug-mode maybe will not work in release-mode

          On broader level, in debug mode, lots of things would be taken care of. One of them is variable initialization. In your case though, you did miss to mention mask. And its always good practice to initialize variables.

          Prasad Notifier using ATL | Operator new[],delete[][^]

          1 Reply Last reply
          0
          • E ensger

            Got good help last week for changing text of listCtrl-header and I thougth, my problem is solved. I've the following code: void koarkstewView::alterheadercontent() { LVCOLUMN lvc; CString titel; CListCtrl &listCtrl = GetListCtrl(); koarkstewDoc* pDoc = GetDocument(); karkst *karkstanz; karkstanz = pDoc->karkstanz; pDoc->SetTitle("KAR->KST"); int i = 3; if (karkstanz->wdfirst()) do { i++; titel = karkstanz->wdgetkarnr() + "\n"; titel = titel + gettitel(0, karkstanz->wdgetdatenart(), karkstanz->wdgetvon(), karkstanz->wdgetbis()); listCtrl.GetColumn(i, &lvc); lvc.pszText = titel.GetBuffer(0); titel.ReleaseBuffer(); listCtrl.SetColumn(i, &lvc); } while(karkstanz->wdnext()); } Works fine - but only in debug-mode!! In release-mode, the text doesn't change:mad: But how to debug the code, if it work's in debug-mode:confused: Any proposals?? Thanks, Gerhard

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            ensger wrote:

            lvc.pszText = titel.GetBuffer(0);

            Why are you calling GetBuffer() unnecessarily? I don't see that you are modifying titel.


            "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

            "Judge not by the eye but by the heart." - Native American Proverb

            E 1 Reply Last reply
            0
            • D David Crow

              ensger wrote:

              lvc.pszText = titel.GetBuffer(0);

              Why are you calling GetBuffer() unnecessarily? I don't see that you are modifying titel.


              "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

              "Judge not by the eye but by the heart." - Native American Proverb

              E Offline
              E Offline
              ensger
              wrote on last edited by
              #6

              Because lvc.pszText = titel; results in an error-message like 'no operator defined, that accepts a right-sided operator of type 'class CString''. I didn't even know the existence of 'GetBuffer()' till last week - but it works ;)

              D 1 Reply Last reply
              0
              • E ensger

                Because lvc.pszText = titel; results in an error-message like 'no operator defined, that accepts a right-sided operator of type 'class CString''. I didn't even know the existence of 'GetBuffer()' till last week - but it works ;)

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                ensger wrote:

                ...but it works

                Of course it does, but GetBuffer() exposes the underlying char* object to possible (unwanted) changes. Try:

                lvc.pszText = (LPTSTR) ((LPCTSTR) titel);

                Now titel cannot be accidentally changed.


                "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                "Judge not by the eye but by the heart." - Native American Proverb

                E 1 Reply Last reply
                0
                • D David Crow

                  ensger wrote:

                  ...but it works

                  Of course it does, but GetBuffer() exposes the underlying char* object to possible (unwanted) changes. Try:

                  lvc.pszText = (LPTSTR) ((LPCTSTR) titel);

                  Now titel cannot be accidentally changed.


                  "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

                  "Judge not by the eye but by the heart." - Native American Proverb

                  E Offline
                  E Offline
                  ensger
                  wrote on last edited by
                  #8

                  I tried and it works. And the sense of this statement is even more obvious for me. So, many thanks

                  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