Thread: how to delete a CStatic text

  1. #1
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257

    how to delete a CStatic text

    Hey,

    I have a dlg based gui and I create a bunch of text on it dynamicaly. I'd like to add a reset button which would clear everything off of the window. I can delete the edit boxes, but I don't know how to delete the CStatic objects.

    Thanks.
    Everything is relative...

  2. #2
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    NVM, doenst work
    My Website
    010000110010101100101011
    Add Color To Your Code!

  3. #3
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    I guess I have to use soemthing else, like a button control that can be deleted, eh?
    Everything is relative...

  4. #4
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    What do you mean deleted? Do you mean remove them from the dialog or just not show them anymore? You can always use
    Code:
    item->showwindow(sw_hide)
    to change the visibility, or you could use
    Code:
    SetDlgItemText( ID, "" )
    as well to change the item to "invisible".

  5. #5
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    static text doesn't have an ID. so I don't think I can do SetDlgItemText.
    and I'm not sure how showwindow(sw_hide) work and what exactly it does/parameters it takes.

    Basicly the text is dynamically created depending on how much data there is. If the user runs the function twice the old text from last run should not appear. Right now it just writes over as much as is avalable the second time, but the rest still stays.

    I'll look into the showwindow- hide business.
    Everything is relative...

  6. #6
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    OK, showwindow() would hide the whole window. I want to keep the window and just get rid of the text on it.
    Everything is relative...

  7. #7
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    A CStatic does have an ID associated with it...

    as do all controls associated with a window (CStatic or otherwise)
    Last edited by dpro; 08-26-2005 at 03:06 PM. Reason: Making more clear

  8. #8
    Magically delicious LuckY's Avatar
    Join Date
    Oct 2001
    Posts
    856
    Quote Originally Posted by earth_angel
    static text doesn't have an ID
    Incorrect.

    Quote Originally Posted by dpro
    A CStatic does have an ID associated with it...
    Correct.

    By default, when you create a CStatic object it's ID is IDC_STATIC which is equivalent to 0xFFFFFFFF and used automatically under the assumption you won't send/receive any messages with the control. Just specify a unique ID instead. (This is all assuming you're using MFC, which it sounds like you are.)

  9. #9
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    Oh, OK.
    I didn't know you can specify an ID for static text.

    I'm trying to do this now:
    Code:
    CStatic* pstatic;
    	i=0;
    
    	while((pstatic = (CStatic*) GetDlgItem(i+700)) != NULL) 
    	{
    		pstatic->SetDlgItemText(i+700, "" ) ; 
    		i++;
    	}
    I also tried delete pstatic; but it doesn't destroy the text or make it invisible. Here's how I make it:
    Code:
    myStaticf = new CStatic;
    myStaticf->Create(_T(FAD.vectDL[i].Param), WS_CHILD|WS_VISIBLE|SS_CENTER,
    			CRect(x1,y,x2,y+h), this, i+700);
    and I am using MFC with MS VC++ 6.0
    Last edited by earth_angel; 08-29-2005 at 07:16 AM.
    Everything is relative...

  10. #10
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Did you actually set the ID for the item?

    What I am catching from this is that, you have an ID which is 700-7nm where n and m are numbers. You are iterating through each one, and doing something to them, i.e. changing something about them, hiding them, or showing them correct?


    As for showing and hiding the "window -> i.e. cstatic" I was mistaken.

    You should use this if possible.

    Code:
    GetDlgItem( ITEM_ID )->EnableWindow( TRUE/FALSE );
    True will "show" the cstatic and false will "hide" the cstatic.

  11. #11
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    i set the id to 700+i where i goes from 0 to whatever. So the IDs are 700, 701, 702, 703, etc.

    EnableWindow() still leaves the text on the window, it is just not active, ie.. it's grey instead of black.

    I'm running out of ideas to get rid of this stupid text.
    Everything is relative...

  12. #12
    I am me, who else?
    Join Date
    Oct 2002
    Posts
    250
    Can you post a larger snippet of the code so I can get a better look on how you are using it?

    And well I was right the first time, use showwindow... not enablewindow..
    Last edited by dpro; 08-29-2005 at 03:09 PM. Reason: Silly mistake...

  13. #13
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >>pstatic->SetDlgItemText(i+700, "" ) ;

    this sets a child window of pStatic's text to "" (not the text of pStatic)

    use something like

    Code:
    //test to see if we have a static with that ID
    while((pstatic = (CStatic*) GetDlgItem(i+700)) != NULL) 
    {
              SetDlgItemText(i+700, "" ) ;
              i++;
    }
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  14. #14
    Registered User
    Join Date
    May 2005
    Location
    Toronto, Canada
    Posts
    257
    Here's the whole thing:
    Creation:
    Code:
    CStatic* myStaticf;
    
    	x1=215, y=125, x2=300, h=15;
    
    	structLink templink;
    
    	templink.BParam = '\0';
    	
    	for(i=0; i< FAD.vectDL.size(); i++)
    	{
    		myStaticf = new CStatic;
    
    		if ( strncmp(FAD.vectDL[i].Param, "ENDL", 4) != 0 
               && strncmp(FAD.vectDL[i].Param, "END", 3) != 0)
    		{
    			myStaticf->Create(_T(FAD.vectDL[i].Param), WS_CHILD|WS_VISIBLE|SS_CENTER,
    			CRect(x1,y,x2,y+h), this, i+700);
    			
    			y+=19;
    
    		}
    	}
    At the top of the function I try to check if there is text already and get rid of it if there is and write a new set.
    Code:
    	CStatic* pstatic;
    	i=0;
    
    	// FAD
    	while((pstatic = (CStatic*) GetDlgItem(i+700)) != NULL) 
    	{
    		pstatic->ShowWindow(SW_HIDE);
    		i++;
    	}
    Running this, I get some of the text hidden, but it seems to be very random. I've attached the display after the function has been run twice. So it fist loaded a file with 17 labels to be printed and then with only 10. So the text with no edit boxes beside it shouldn't be there.

    Edit: Couldn't attach it. They say whatever size I put it's too large.
    Last edited by earth_angel; 08-30-2005 at 06:36 AM.
    Everything is relative...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Deleting Text from a Text file
    By Daved in forum C++ Programming
    Replies: 5
    Last Post: 11-04-2006, 09:47 PM
  2. Deleting / Changing a record in a text file
    By clearrtc in forum C Programming
    Replies: 9
    Last Post: 08-21-2006, 12:09 AM
  3. How to delete every other line in a text file?
    By mr2999 in forum C++ Programming
    Replies: 6
    Last Post: 01-20-2005, 06:08 PM
  4. Accessing a Specific Text Line Inside CEditView :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 04-14-2002, 08:12 PM
  5. How do i delete a certain part of a text file?
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 09-08-2001, 06:00 PM