Thread: Including GDI

  1. #1
    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,708
    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:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    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,708
    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:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  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
    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
    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,708
    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:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

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, 05: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