Problem drawing Rectangles and Text

This is a discussion on Problem drawing Rectangles and Text within the Windows Programming forums, part of the Platform Specific Boards category; Hi, Im programming in C++ and looking to draw a rectangle with no color fill and text in the left ...

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    21

    Problem drawing Rectangles and Text

    Hi,

    Im programming in C++ and looking to draw a rectangle with no color fill and text in the left top hand corner. So far my code looks like this:
    Code:
    #include <windows.h>
    #pragma once
    
    void main(){
    dc->FillRect(screen_area,&CBrush(HS_BDIAGONAL,RGB(0,255,0)));
    dc->TextOut(screen_area.left+2,screen_area.top+5,"HD");
    }
    however i get a bunch of errors most of which are undeclared identifiers. Help would be much appreciated.

    Thanks

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    ........You're not serious are you?

    durr....

    anyways

    Code:
    #include <windows.h>
    #pragma once
    
    void main(){
    dc->FillRect(screen_area,&CBrush(HS_BDIAGONAL,RGB(0,255,0)));
    dc->TextOut(screen_area.left+2,screen_area.top+5,"HD");
    }
    First off....you don't need a #pragma once directive in there...no purpose.

    Second off, dc and screen_area are probably undeclared (I'm guessing that without even compiling the code)

    So, my suggestion to you would be to define those variables: figure out how to define them and get them to work, I'm guessing you got this code from *somewhere*, and then come back once you've made an effort at that, k?

  3. #3
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Code:
    #include <windows.h>
    #pragma once
    
    void main(){
    dc->FillRect(screen_area,&CBrush(HS_BDIAGONAL,RGB(0,255,0)));
    dc->TextOut(screen_area.left+2,screen_area.top+5,"HD");
    }
    1. You don't need #pragma once
    2. 'void' main is evil.
    3. You're using at least 2 variables, neither of which you've declared.
    3. You're trying to use MFC stuff in a console application.

    Based on point #2 and #3, I very frankly don't think you know enough C++ to be messing with graphics and MFC just yet. Go through the tutorials on this site (or your book), and do some more basic stuff first; once you've learned enough of the language, you can then move on to learn more advanced API's.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX | Drawing text
    By gavra in forum Game Programming
    Replies: 4
    Last Post: 06-08-2009, 01:23 AM
  2. Any reason for Edit Controls to flicker?
    By csonx_p in forum Windows Programming
    Replies: 21
    Last Post: 06-06-2008, 03:27 AM
  3. Drawing two or more rectangles on client area.. HELP!
    By csonx_p in forum Windows Programming
    Replies: 2
    Last Post: 05-12-2008, 02:43 AM
  4. Drawing Rectangles and Text
    By cram in forum Windows Programming
    Replies: 7
    Last Post: 10-13-2004, 04:45 PM
  5. Black Rectangles in Text Files
    By sean in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 12-07-2003, 06:14 PM

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