Anyone? (MSVC++)help Plz.

This is a discussion on Anyone? (MSVC++)help Plz. within the C++ Programming forums, part of the General Programming Boards category; First the complaint: You don't have to read this Look, I... am starting to get extremely ........ed off... It seems ...

  1. #1
    0x01
    Join Date
    Sep 2001
    Posts
    88

    Anyone? (MSVC++)help Plz.

    First the complaint: You don't have to read this
    Look, I... am starting to get extremely ........ed off... It seems like nobody understands this compiler(MSVC++), or they try to keep everything a ****ing secret. Most of the questions I have asked about useing the Win32 Console, and retrieveing data on the window size, color, cursor position, reading from the console, etc. I have had to figure it out myself; and if I can do it, I know there are way more experienced programmers that can too if they don't already know. Nobody seems to know how to do these things with MSVC++. Maybe its because the compilers .cpp or .h files are full acronyms that nobody understands besides the developers them selves... its like haveing to learn a whole other language, does anyone feel the same way??? I could just be an extremely uneducated idiot who is makeing himself look dumber by saying all this. (The compiler doesn't suck, its very convienent at times... its just damn! I am constantly hitting a brick wall when trying to use its functions.) (Btw- excuse the language)

    The question.
    How do I read from the console screen? Let me explain.
    Open the win32 console, type "edit" and press ENTER. A DOS like text editor comes up... now type something, anything and then click "File" at the top left (I wish I knew how to capture mouse events in the win32 console), ok now click off of "File" and back into the text editor, the "File" menu should close; do you see how the program still remembered what you had typed, and it looks as if the "File" menu that was drawn never overwrote what you typed? Ok, this is what I am trying to accomplish, and I "think" I need to know how to read whats on the screen, and the somehow get the text color for every character that I read from the console, so that I can replace what what written to the screen at x,x coord just incase a window or popup type thing overwrites it for the moment....

    TIA, and don't flame me because I ripped on MSVC++... I didn't say the compiler sucked, it is the best. However; it gets very frustrating when trying to use something that it has built in, especially with all the aconyms.

    Btw - I know there is a way to RGB colors in the console, I know this because if you open the console and "right-click" on the console Icon at the top left and select "properties" you can change the colors to anything you want from there... if you choose to save the properties, it write the data to the registry under whatever name the program was(A win32 console program of course.)

    *I didn't look over this to make sure there was any mis-spellings, wrong punctuation etc... so there may be lots.

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    For general console help, browse my tutorial here. It covers things like moving the cursor, changing the colours etc., and when I have converted all parts of it, will cover things like mouse usage.

    How are you "opening" this console and what are you wanting to read? It sounds to me as if you have gone to the command line interpreter and entered a text editing program.

    You're not using system() are you?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    0x01
    Join Date
    Sep 2001
    Posts
    88
    Adrianxw your tutorial is awesome, but I wish I would have looked at along time ago, because I have already figure out most of the things you covered. (I didn't know you could change the cursor size.)

    Though, this;
    Code:
    BOOL FillConsoleOutputCharacter(
      HANDLE hConsoleOutput,
      TCHAR cCharacter,
      DWORD nLength,
      COORD dwWriteCoord,
      LPDWORD lpNumberOfCharsWritten
    );
    was something I didn't know how to use but knew was there.

    I understand exactly what the console is, how the characters work, setting the cursor position, getting the cursor position, changeing the text color, clearing the screen, etc.

    How are you "opening" this console and what are you wanting to read? It sounds to me as if you have gone to the command line interpreter and entered a text editing program.
    I was just describeing how the "edit" program in DOS/Window32 Console is able to draw a menu which overwrites some of the text that was written to the console and then replaces the exact text that was there when ever the menu closes as if it hadn't overwrote what was there. (This is so hard to explain, but would be so easy to understand if I could show you.) (I was just useing the "edit" program as an example.)

    Ok, let me rephrase the question.
    How do I retrieve the text that is currently in the console window/my console program?

    For example; Let say the character "K" is at coord (40,10), and it is the default console color.

    Lets pretend I didn't know "K" was there, but I wanted to find out what was at coord (40,10) in the console window.

    Ok, if I draw an ascii window that may overwrite what was at (40,10)... I need to know what was at (40,10) to replace what was there before the ascii window overwrote that area after the ascii window closes.

    It would be better if I could retrieve what character is at a specific coord as well as the foreground&background color it had.
    Last edited by knave; 07-02-2003 at 10:56 AM.

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    When you open the menu, you draw on top of whatever is there. When you close it, you have to redraw whatever is underneath. You shouldn't need to find out whats there beforehand and save it, just redraw it.

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> find out what was at coord (40,10) in the console window.

    Have you tried the...
    Code:
    BOOL ReadConsoleOutputCharacter(
      HANDLE hConsoleOutput,
                          // handle to a console screen buffer
      LPTSTR lpCharacter, // address of buffer to receive characters
      DWORD nLength,      // number of character cells to read from
      COORD dwReadCoord,  // coordinates of first cell to read from
      LPDWORD lpNumberOfCharsRead 
                          // address of number of cells read from
    );
    ... and...
    Code:
    BOOL ReadConsoleOutputAttribute(
      HANDLE hConsoleOutput,
                          // handle to a console screen buffer
      LPWORD lpAttribute, // address of buffer to receive attributes
      DWORD nLength,      // number of character cells to read from
      COORD dwReadCoord,  // coordinates of first cell to read from
      LPDWORD lpNumberOfAttrsRead 
                          // address of number of cells read from
    );
    ... functions?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    0x01
    Join Date
    Sep 2001
    Posts
    88
    Speedy5, I am going to be honest; right now as I am typeing this I am trying to think of a way to tell you that, that isn't what I want to do. There is a reason for it, I just can't remember what it is.

    ...
    Hm. Its like a neanderthal that goes traveling for food, he's on the verge of dieing and he sees a drawing on a rock; its a drawing of a man slaying a deer... he knows there is something about it, but he can't figure it out. Its just too much for him, his primitive mind.

    All the drawing means is that people like him are close by... He could probably get help from them, but because he just couldn't figure out why a drawing was there he dies.

    --

    Right now I feel like the neanderthal when trying to think of why your reply is not what I want to do. Maybe this is a sign, that your right.

  7. #7
    0x01
    Join Date
    Sep 2001
    Posts
    88
    Adrianxw, perfect. That is what I have been looking for. I am going to try and use them (The functions you gave me,) and I might come back here if I have any problems with them.. cool?

    Right now, I don't understand:
    Code:
    LPTSTR lpCharacter and LPDWORD lpNumberOfCharsRead
    in the ReadConsoleOutputCharacter() and
    Code:
    LPWORD lpAttribute and LPDWORD lpNumberOfAttrsRead
    in the ReadConsoleOutputAttribute().

    I'll do my best to figure them out. BTW-Thanks.

  8. #8
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    If you are not interested in the values, just pass the address of a dummy int.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  9. #9
    0x01
    Join Date
    Sep 2001
    Posts
    88
    I am interested in the values, I just don't understand what they are or how to use them.
    Last edited by knave; 07-02-2003 at 12:16 PM.

  10. #10
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    If you start at (0,0) and ask it to read 5 characters, then the value returned there will be 5. No surprises there. However, if you ask it to return 1000000 characters, then it can not, because you have asked for more characters then there are in the screen buffer. This will not generate an error, the routine will return the number of characters actually read in the last parameter.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  11. #11
    0x01
    Join Date
    Sep 2001
    Posts
    88
    ReadConsoleOutputAttribute() is not returning a "useable" color, its returning some huge number that definitely isn't marked as a color in the console... any examples?

  12. #12
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    This program sets the FOREGROUND_RED and FOREGROUND_GREEN bits to give yellow text. Then calls ReadConsole OutputAttribute, which returns the value 6 as expected, FR is defined to be 0x0004 an FG as 0x0002, 2+4=6. You should always use the symbols rather than the number, MS may, (unlikely but a reserved right), change them at some later date.
    Code:
    #include <windows.h>
    #include <iostream.h>
    
    int main()
    {
        HANDLE hOut;
        unsigned short Attribute;
        COORD Where;
        unsigned long NumRead;
    
        hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
        SetConsoleTextAttribute(hOut,
                                FOREGROUND_RED | 
                                FOREGROUND_GREEN);
    
        cout << "This text is yellow." << endl;
    
        Where.X = 0;
        Where.Y = 0;
        ReadConsoleOutputAttribute(hOut,
                                   &Attribute,
                                   1,
                                   Where,
                                   &NumRead);
    
        cout << "Attribute is " << Attribute << endl;
    
        return 0;
    }
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 10:19 PM
  2. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  3. MSVC behaves strange
    By ripper079 in forum C++ Programming
    Replies: 4
    Last Post: 10-28-2003, 08:34 PM
  4. Blender3D, XML, and MSVC ???
    By Grumpy_Old_Man in forum Game Programming
    Replies: 0
    Last Post: 08-24-2003, 08:00 PM
  5. GCC (cygwin) much faster than MSVC, Borland?
    By Sargnagel in forum C Programming
    Replies: 15
    Last Post: 08-05-2003, 04:15 AM

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