Including GDI

This is a discussion on Including GDI within the C++ Programming forums, part of the General Programming Boards category; How do I include GDI into a console program? None of these work: #include <gdi.h> #include <gdi32.h>...

  1. #1
    JMK
    JMK is offline
    Registered User
    Join Date
    May 2010
    Posts
    24

    Including GDI

    How do I include GDI into a console program? None of these work:

    #include <gdi.h>
    #include <gdi32.h>

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,639
    Quote Originally Posted by JMK View Post
    How do I include GDI into a console program? None of these work:

    #include <gdi.h>
    #include <gdi32.h>
    To be able to make use of the GDI, you'll need a window. CreateWindowEx does just that. And the header to include would be "windows.h".
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  3. #3
    JMK
    JMK is offline
    Registered User
    Join Date
    May 2010
    Posts
    24
    I did create a window using CreateWindowA. I need to include GDI for it to work. It gets automatically included in a Window program, but not a console program, so I need to know what to include.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,639
    Quote Originally Posted by JMK View Post
    I did create a window using CreateWindowA. I need to include GDI for it to work. It gets automatically included in a Window program, but not a console program, so I need to know what to include.
    Again, "windows.h" will include the necessary GDI functions. You may also need to pass the GDI DLL information to the linker, depending on how your compiler is set up.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  5. #5
    Registered User Swarvy's Avatar
    Join Date
    Apr 2008
    Location
    United Kingdom
    Posts
    195
    If you want to add GDI into a console application then once you have created the window using CreateWindow() you should be able use the GDI functions e.g. GetDC() etc, inputting the handle of the window you created as a parameter. Ofcourse, if you are adding the window to a console application you may need to add in a bit of coding if you want a message loop structure as is typical for most windows programs.

    Rats!!! Sebastiani you beat me to it :P lol

  6. #6
    JMK
    JMK is offline
    Registered User
    Join Date
    May 2010
    Posts
    24
    You may also need to pass the GDI DLL information to the linker, depending on how your compiler is set up.
    I don't know what that means.

    I get this error:
    Release Win32\Drivers\Window\Windows\WindowsWindowDriver.o :WindowsWindowDriver.cpp.text+0x194): undefined reference to `GetStockObject@4'
    On this line:
    Code:
    wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
    I am using Code::Blocks with the GCC compiler.
    Last edited by JMK; 09-01-2010 at 01:50 PM.

  7. #7
    JMK
    JMK is offline
    Registered User
    Join Date
    May 2010
    Posts
    24
    I opened BUild Options, and in Link Libraries I just added this line:
    libgdi32.a

    And it worked!

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,639
    Quote Originally Posted by JMK View Post
    I opened BUild Options, and in Link Libraries I just added this line:
    libgdi32.a

    And it worked!
    Yep, as I said: "You may also need to pass the GDI DLL information to the linker, depending on how your compiler is set up".
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  2. Windows GDI vs. Java Graphics
    By Perspective in forum Windows Programming
    Replies: 7
    Last Post: 05-07-2007, 10:05 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. GDI object lifetime and C++ object lifetime
    By VirtualAce in forum Windows Programming
    Replies: 4
    Last Post: 06-16-2006, 05:26 AM
  5. Whats Peoples Problem With the GDI?
    By MicroFiend in forum Game Programming
    Replies: 6
    Last Post: 07-28-2003, 07:52 PM

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