Console pixels drawing

This is a discussion on Console pixels drawing within the C Programming forums, part of the General Programming Boards category; How do I draw a certain pixel on the console? Thanks (:...

  1. #1
    Registered User gavra's Avatar
    Join Date
    Jun 2008
    Posts
    265

    Console pixels drawing

    How do I draw a certain pixel on the console?

    Thanks (:
    gavra.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by gavra View Post
    How do I draw a certain pixel on the console?

    Thanks (:
    Without changing the mode (which is only available in DOS) to graphics mode, you can't (or at least, you ain't supposed to do that - I'm sure there is some sneaky way of getting the handle of the window and using PutPixel or some such - but that's the same as asking "How do I add my own drawing in Internet Explorer - you aren't supposed to do that".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User gavra's Avatar
    Join Date
    Jun 2008
    Posts
    265
    I don know what you are talking about but it doesn't matter right now - I got it. (SetPixel)
    thanks anyway [:
    gavra.

  4. #4
    Registered User gavra's Avatar
    Join Date
    Jun 2008
    Posts
    265
    Wait something is wierd with this function.. it seems to putpixel into my screen not into my console O_o
    Help XD
    gavra.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by gavra View Post
    Wait something is wierd with this function.. it seems to putpixel into my screen not into my console O_o
    Help XD
    Well, you need a Window Handle for that - you can get the Desktop handle (GetDesktopHandle) I think - whether it allows you to write to it is a different matter.


    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    GetDesktopWindow() you mean... and I don't think there is a concept of security when it comes to writing to another window's DC (or various other things). There is usually just, 1. you can write to another processes' window (attribute wise) with this function or 2. you can't

    You need a handle to the console window, ie the window in which the command prompt appears... which should be easy to get (try FindWindow()). And then you can get the child-window area -- if that's what it's called, haven't done windows programming for a while.

    The only downside is, you have to have a good understanding of how Win32 all ties together. And note that the window will probably redraw itself, thus you'd have to re-draw your pixels -- double buffering can help here.

  7. #7
    Registered User
    Join Date
    Aug 2008
    Posts
    67

  8. #8
    Registered User gavra's Avatar
    Join Date
    Jun 2008
    Posts
    265
    O:
    I used SetPixel, GetConsoleWindow, GetDC, RGB.
    but after I draw the pixel if I press another apllication or window the pixel will be "removed" from from the screen - why?!
    gavra.

  9. #9
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by gavra View Post
    O:
    I used SetPixel, GetConsoleWindow, GetDC, RGB.
    but after I draw the pixel if I press another apllication or window the pixel will be "removed" from from the screen - why?!
    Because the redrawing of the window is done by a process that isn't aware that you have drawn on top of what it knows about - that is exactly the point I was trying to make earlier - you can draw in another window, but you won't be able to make the application know that the drawing is there and make the other application maintain it. So, now you also need to intercept the "WM_PAINT" messages for that process, and we get into a really big hairy mess of "hooking" things.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #10
    Registered User gavra's Avatar
    Join Date
    Jun 2008
    Posts
    265
    Ohh so what is the solution? (if there is..)
    humm and one more thing - what is the difference between the coordinates of gotoxy (the struct CROOD) and the coordinates of SetPixel? - it seems that SetPixel related somehow with my screen resolution and gotoxy (normally) related to the console pixels only..
    thank you (:
    gavra.

  11. #11
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What are you actually trying to do? I'm sure there is some solution, but perhaps it's not along the lines of what you are currently doing... You can't really draw within another applications windows and expect those applications to maintain the content - that's like putting your pot-plants in your neighbours garden, and when you come back from holiday, expect them to still be there, without asking your neighbour to look after them - except that if your neighbour is kind, it's likely to work to do this. Applications are NEVER kind in this sense.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #12
    Registered User gavra's Avatar
    Join Date
    Jun 2008
    Posts
    265
    XD
    All I'm trying to do is to create functions for the console for drawing lines, rectangles, circles and so on..
    and as I said it's actually works but not as I expected.

    now, any solution\alternative way for doing this?
    gavra.

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by gavra View Post
    XD
    All I'm trying to do is to create functions for the console for drawing lines, rectangles, circles and so on..
    and as I said it's actually works but not as I expected.

    now, any solution\alternative way for doing this?
    Yes, use the proper Windows API in a GUI application - that's the RIGHT way to solve this type of problem.

    Of course, that already has primitives to draw lines, rectangles, etc. But if you want to just practice, then you can always use the SetPixel to draw a pixel at a time.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  14. #14
    Registered User
    Join Date
    Jun 2008
    Posts
    266
    You could use FindWindow() and use the console window name, but its really not worth it. Just learn Win32 basics if you wan't to get into graphics.

  15. #15
    Registered User gavra's Avatar
    Join Date
    Jun 2008
    Posts
    265
    Well ok.. (any links?)
    and talking about primitives - I tried to think how to draw a circle but I have nothing helpefull \:
    any ideas?
    thank you again (:
    gavra.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing pixels on a window?
    By Devils Child in forum Windows Programming
    Replies: 12
    Last Post: 03-05-2009, 08:13 AM
  2. drawing circle to console
    By golom in forum C Programming
    Replies: 2
    Last Post: 12-20-2006, 09:57 AM
  3. Full Screen Console
    By St0rmTroop3er in forum C++ Programming
    Replies: 1
    Last Post: 09-26-2005, 09:59 PM
  4. Console Functions Help
    By Artist_of_dream in forum C++ Programming
    Replies: 9
    Last Post: 12-04-2004, 02:44 AM
  5. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 09:19 AM

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