Thread: casting HBRUSH

  1. #1
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625

    casting HBRUSH

    Hi, I'm trying to get this to compile correctly, but I'm having an error. I'm basically just creating a window, registering it, and displaying it to the screen :

    Code:
    WNDCLASS winclass;	// this will hold the class created
    HWND	 hwnd;		// generic window handle
    MSG		 msg;		// generic message
    
    // window class stucture
    winclass.style			= CS_DBLCLKS | CS_OWNDC | 
                              CS_HREDRAW | CS_VREDRAW;
    winclass.lpfnWndProc	= WindowProc;
    winclass.cbClsExtra		= 0;
    winclass.cbWndExtra		= 0;
    winclass.hInstance		= hinstance;
    winclass.hIcon			= LoadIcon(NULL, IDI_APPLICATION);
    winclass.hCursor		= LoadCursor(NULL, IDC_ARROW);
    winclass.hbrBackground	= GetStockObject(BLACK_BRUSH);
    winclass.lpszMenuName	= NULL;
    winclass.lpszClassName	= WINDOW_CLASS_NAME;
    The italicized line is where the compiler is indicating a problem. It says I'm doing an "invalid conversion from void* to HBRUSH__*". Now I've tried casting the so-called line with HBRUSH,HBRUSH*, HBRUSH__* and so on, but no dice. Any ideas ?

    I'm using Dev-C++. I don't know whether or not that's an issue.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I'm not using dev-c++ but this code works fine for me:
    Code:
    winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Tried it, no dice...

    Same error.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  4. #4
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Ok, forget it, I guess when you open a file from some other source it doesn't assume by default that it's a windows application. I created a new win application, copy-pasted my code, and it's working now....Don't quite know why, though...
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    69
    Alternately:
    #include <windowsx.h>
    ...
    wincl.hbrBackground = GetStockBrush(BLACK_BRUSH);

    In this case windowsx.h helps take care of some things like that for you, brush, pen, font

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. x.h header file
    By Ducky in forum Windows Programming
    Replies: 11
    Last Post: 11-01-2008, 11:12 AM
  2. Wm_timer
    By Ducky in forum Windows Programming
    Replies: 21
    Last Post: 09-26-2008, 05:36 AM
  3. question about casting pointers/other types also??
    By newbie02 in forum C++ Programming
    Replies: 3
    Last Post: 08-07-2003, 05:01 AM
  4. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM
  5. '=' : cannot convert from 'void *' to 'struct HBRUSH__ *'
    By Bajanine in forum Windows Programming
    Replies: 9
    Last Post: 10-14-2002, 07:54 PM