Label Box

This is a discussion on Label Box within the Windows Programming forums, part of the Platform Specific Boards category; I have a wondering here. This code I have below is working great except of one thing that doesn´t make ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    383

    Label Box

    I have a wondering here. This code I have below is working great except of one thing that doesn´t make sense to me.
    I use a while-loop inside a for-loop as seen.
    The for-loop is counting from 1-49 and for each count the while-loop will read a .txt file and put some info to a file.
    Notice now in my code in the for-loop that I have put "Display this" to a label on my form.

    This should be shown for the first count in the foor-loop wich is 1 ?
    What happens in this code is that "Display this" will be shown First when the count is ready, wich then is count = 49.
    Why is this happening. It should be shown directly and not in the end of the loop ?

    HowEver if I put this message box in the same place instead of "Label1" then it will
    Display a new messagebox for each count wich meens 49 MessageBoxes

    Code:
    MessageBox::Show("Display this");
    Code:
    std::string Line;
    ofstream MainFile;
    MainFile.open ("Main.txt");
    
    
    	for (int count= 1; count < (50); count++)
    	{ 
    		
    		Label1->Text = "Display this";
    				
    	
    		ifstream File ("DGD.txt");
    		while	(    getline(File, Line, '\n')  )           		
    		{
    		
    			MainFile << "Hello" << ',' << "Hello2" << '\n';
    
    		}
    
    
    	}

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    The form is only updated during a paint message. If you invalidate the form right after the "Display this" statement it should change each loop iteration. Of course if you put the same text in the same place you won't notice.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    383
    Okay, I am not sure how to do that. You meen that I will put some code the line under this line in order to invalidate the form ?

    Code:
    Label1->Text = "Display this";

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    The way I've done it, in MFC, is :

    // Invalidate the label
    label->Invalidate();

    // tell it to paint
    SendMessage(WM_PAINT);

    Assuming label is a pointer to a static control or something similar.

    But this can cause excessive flicker in the application.
    Last edited by DaveH; 02-22-2008 at 01:46 PM.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    383
    Ok, I have tried to put it like this, It does compile but it doesn&#180;t work. If I also put the line SendMessage(WM_PAINT); under the ->Invalidate(), I will have a compiler Error that says:
    WM_PAINT undeclared identifier.

    I dont know what is nesscary to do. Do I have to declare something or #include anything.
    Thanks...

    Code:
    CurrentSymbol->Text = "Display this";
    CurrentSymbol->Invalidate();
    Last edited by Coding; 02-22-2008 at 03:20 PM.

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Why not post in C# when you're using it? Windows subforum is more for... native programming.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Dec 2007
    Posts
    383
    Yes I will do that instead, thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 01:59 PM
  2. How to program a "back" button with MFC
    By 99atlantic in forum Windows Programming
    Replies: 3
    Last Post: 04-26-2005, 08:34 PM
  3. New Theme
    By XSquared in forum A Brief History of Cprogramming.com
    Replies: 160
    Last Post: 04-01-2004, 07:00 PM
  4. Replies: 1
    Last Post: 07-13-2002, 05:45 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21