how do I make text that stays in place and update

This is a discussion on how do I make text that stays in place and update within the C Programming forums, part of the General Programming Boards category; I've seen programs before such as games which display text e.g score,user,etc.. The text is display on the screen but ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    16

    how do I make text that stays in place and update

    I've seen programs before such as games which display text e.g score,user,etc.. The text is display on the screen but it can be changed without redisplaying it.For example the score will just increase without changing where it is.

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    What you can do is use gotoxy(x,y) to move to that section of the screen, then update the score or whatever and then use the function again to move back to where you want. You can use this in a loop to continually update the score.

    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    16
    does that work in non-gui apps?

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >does that work in non-gui apps?
    Yes, but it is platform dependent. If you use a Borland compiler then you will already have gotoxy defined in conio.h, otherwise you will have to write it yourself either with the Windows API for Windows systems or another method for other systems (curses are always a good bet).

    -Prelude
    My best code is written with the delete key.

  5. #5
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    Early versions of Microsoft's C / C++ compilers had _settextpostion(x,y) defined in graphics.h or graph.h I forget. However, I found that in pure dos I could use inline assembly for much of the con i/o. I don't know if this is acceptable programming or not, but it works for me using MSVC 1.0

    Code:
    void setCusor(int x, int y);
    
    void setCursor(int x, int y)
    {
         _asm
         {
              mov ah,2
              xor bx,bx
              mov dh,byte ptr x
              mov dl,byte ptr y
              int 10h
          }
    }
    This will cause a general protection fault in windows though if compiled using MSVC 6 and as a console app.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  6. #6
    Banned borko_b's Avatar
    Join Date
    Jun 2002
    Location
    Well... I live in Bulgaria :)
    Posts
    100
    Code:
    void setCursor(int x, int y)
    {
         _asm
         {
              mov ah,2
              xor bx,bx
              mov dh,byte ptr x
              mov dl,byte ptr y
              int 10h
          }
    }
    This thing will crash when compiled in 32bit MSVC 6.0

    I think that you can't use interrupts like that
    only building it with 16 bit compiler will do the job...

    Win32API is not using any interrupts like
    DOS programming...
    (meaning that you won't program with interrupts
    not that the Win is not using them at all)

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >This thing will crash when compiled in 32bit MSVC 6.0

    I tried the setCursor code on a Windows NT computer. It didn't crash, but it didn't move the cursor either. I wish it would have worked.

  8. #8
    Unregistered
    Guest
    >>..I tried the setCursor code on a Windows NT computer. It didn't ...

    Well it does to my Win98...

    May be NT is preventing it somehow...

    (hmm... may not those are interrupts!)

  9. #9
    Casual Visitor
    Join Date
    Oct 2001
    Posts
    350
    guys, I pointed out that this code will not work with a 32 bit compiler it uses 16 bit registers directly. It was compiled as a 16 bit dos app using MSVC 1.0.

    I use it as

    Code:
    setCursor(12,30,0), printf("Text String");
    The 0 is used to set the active page... though that code snippit is not included in the code above.
    I haven't used a compiler in ages, so please be gentle as I try to reacclimate myself. :P

  10. #10
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I would suggest using gotoxy(). This will work on newer machines, but beware of strange behaviour when out-of-bound coords are used!
    Mainly though, the real difficuty lies in the fact that for many applications, the updating should be run in it's own thread. This allows non-interrupted refreshes that do not depend on the main program "loop". Threads are amazingly easy to set up and shut down. Look up CreateThread(), GetExitCodeThread(), and others as well...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Constantly updated editable colored text
    By _Elixia_ in forum Windows Programming
    Replies: 2
    Last Post: 06-15-2003, 05:21 PM

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