Thread: Building a tab custom control

  1. #16
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
              static int *ids;
              static LPSTR *titles;
              static HWND *pages;
              ts->ids = ids;
              ts->titles = titles;
              ts->pages = pages;
    static variables start off as zero. So the above code is equivalent to:

    Code:
              ts->ids = NULL;
              ts->titles = NULL;
              ts->pages = NULL;
    However, I don't know why you are crashing.

  2. #17
    Well based on the when the program crashes I believe that it is something to do with the way that I am deleting tabs.

    Code:
    case MCC_CLOSETAB: {
              bool done=false;
              for ( int i = 0; i < ts->nTabs; i++ ) {
                 
                 if ( i == wParam ) {
                    DestroyWindow( ts->pages[i] );
                    for ( int j = i; j < ts->nTabs-i-1; i++ ) {
                      
                      ts->titles[j] = ts->titles[j+1];
                      ts->pages[j] = ts->pages[j+1];
                      ts->ids[j] = ts->ids[j+1];
                    }
                    done=true;
                    break;
                 }
                 if ( done )
                  break;
              }
              if ( done ) {
               ts->nTabs--;
               if ( ts->active > ts->nTabs ) {
                ts->active--;
               }else{
                if ( ts->active == 1 && ts->nTabs < 2 ) {
                 ts->set = false;
                }else{
                 if ( ts->active > 1 )ts->active--;
                }
               }
                
              }
              return 0;
            }
    Last edited by Mithoric; 03-05-2004 at 02:31 AM.

  3. #18
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
    for ( int j = i; j < ts->nTabs-i-1; i++ )
    Running through it I don't think you want the '-i' here. Also you are incrementing i while testing against j!

    If you consider i to equal 1 and nTabs to equal 3 you get:
    Code:
    for ( int j = 1; j < 1; i++ )
    Not what you want.

    You may want to consider using memmove instead of a loop:
    Code:
    memmove(&ts->titles[i], &ts->titles[i+1], (ts->nTabs-i-1) * sizeof(ts->titles[0]));

  4. #19
    I'll have a go at implementing memmove and try to tidy up that whole lot of code and see if I still get problems.

    Thanks.

  5. #20
    Okey, no crashes now.. But the only reason that is happening is because I've gone for a fixed memory block. From the start there is MAX_TABS and you can't have any more than MAX_TABS.

    No doubt I will change this is the future but I'm spending way to much time on these tabs and and not enough on my other controls I need to finish my program.

    I don't think I'll be needing any help on them anytime soon as everything works now..

    - Adding tabs
    - Removing tabs
    - Retriving page handles
    - Moving tabs
    - Context events
    - Cycling Back/Forward
    - Finding tab ( a few different methods, eg; by title, by active, by id etc )
    - Ordering tabs
    - Setting tab styles ( currently just 2 but planning for a few more )

    All I have to do now is quickly fix a bunch of memory leaks and it'll be ready. If anyone is interested, when my server comes back up I'll post a link to the source/libs for it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  2. Tab order in Tab Control
    By Halloko in forum Windows Programming
    Replies: 2
    Last Post: 05-08-2005, 11:08 PM
  3. tab control
    By tyouk in forum Windows Programming
    Replies: 6
    Last Post: 02-07-2005, 11:47 PM
  4. Custom Tab Control
    By PrivatePanic in forum Windows Programming
    Replies: 8
    Last Post: 07-19-2002, 01:23 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM