Results 1 to 9 of 9

Thread: [RESOLVED] Clear Screen

  1. #1

    Thread Starter
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444

    [RESOLVED] Clear Screen

    I got loads of questions today So how do I clear the screen? I found

    Code:
    #include <stdlib.h>
    int main()
    {
        system("cls");
    }
    But is that the best way to do it?
    Last edited by Rick Bull; Sep 14th, 2002 at 02:17 PM.

  2. #2
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    This works fine for console mode. Otherwise, for windows you have to resort to api calls or DirectX

    For example, you use SendMessage with WM_CLEAR to clear a textbox or editbox. In the Windows Environment you do not usually wipe the whole window (DirectX and gaming excepted),
    just some of the embedded controls.

  3. #3

    Thread Starter
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    Oh thanks. I only wanted it for console mode, I was just wondering if you're better off doing it another way so that it would be compatible on other non-windows systems or something.

  4. #4
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    You can use clrscr() of conio.h

  5. #5
    Addicted Member jmiller's Avatar
    Join Date
    Jul 2002
    Location
    University of Michigan
    Posts
    238
    FYI, clrscr() doesn't work with the Visual Studio 98 compiler.

  6. #6
    Addicted Member ChuckB's Avatar
    Join Date
    Jul 2002
    Location
    South Carolina, USA
    Posts
    157
    Hi Rick,
    For what it's worth, I spent last month learning a lot of console stuff. C++ allows for tons of commands which I found in a help file and printed out just for consoles.

    I am attaching a ZIP file with 21 demos, each with comments. Demo 21 demontrates color, positioning cursor and clearing the screen with functions constructed from these functions. Being an old QBASIC programmer, I have built CLS, QBCOLOR and LOCATE. Not sure if this is the best, but it sure works for my purposes.

    These are all written for Dev-C++ 4.01 so they have a system("pause") in each of them to keep the console from disappearing on you.

    Oh year, I put some functions in a demo.h file. I know you're not supposed to do that...but I'm a new guy...that's my excuse. ;-)

    Regards,
    ChuckB
    Attached Files Attached Files

  7. #7

    Thread Starter
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    Thanks very much Chuck, it's much appreciated.

    And I couldn't get the clrscr to work in conio under VC++ (I knew about it because we breifly did C++ at college). VC++ doesn't seem to like a lot of things, I'd permanently move to Dev-C++ if it had the tooltip thing for function arguments

  8. #8
    Addicted Member ChuckB's Avatar
    Join Date
    Jul 2002
    Location
    South Carolina, USA
    Posts
    157
    Hi Rick,

    The code I sent works for VC++. Just do this.

    1. Create Win32 console, empty project in VC.
    2. Add demo.h and main21.cpp.
    3. Add "using namespace std;" just below the includes. I had forgot this. Dev-C++ doens't care but VC does.
    4. Build and Run.

    All of the commands in this sample above can be found by searching your VC help file...so you don't need to leave VC.

    Here is a tip that you might find useful.

    I have made shortcuts to my taskbar for the following help files associated with MSDN and VC++:

    Winbase.chm //console references
    VCCore.chm
    VCLang.chm
    VCMFC.chm

    So, if you don't want to use VC++ but want to use the MSDN help stuff along with Dev-C++, this makes for a nice compromise.

    Regards,
    ChuckB

  9. #9

    Thread Starter
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    I got all the files to work anyway Chuck. Although I don't think I have the MSDN help files as I installed the Student Licence. I think there was a CD for the help files but it didn't work, or something like that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width