Thread: Conversion error on winclassex

  1. #1
    Registered User
    Join Date
    Mar 2006
    Location
    Ohio
    Posts
    37

    Conversion error on winclassex

    Code:
    winclass.hbrBackground = GetStockObject(BLACK_BRUSH);
    I'm using MSVC++6 to compile my windows program. This line of code is pointed out by the compiler as having a conversion error from void* to struct HBRUSH__*. I used this same exact line of code in a similar program that I wrote earlier and it worked properly but now it's not compiling. What is the problem here?? Posted below is the entire source code file.

    Code:
    // INCLUDES /////////////////////////////////////
    #define WIN32_LEAN_AND_MEAN
    
    #include <windows.h>
    #include <windowsx.h>
    #include <stdio.h>
    #include <math.h>
    
    // DEFINES //////////////////////////////////////
    #define WINDOW_CLASS_NAME "WINCLASS1"
    
    // GLOBALS //////////////////////////////////////
    
    // FUNCTIONS ////////////////////////////////////
    LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam){
        //this is the main message handler of the system
        PAINTSTRUCT ps;
        HDC hdc;
    
        //what is the message
        switch(msg){
        case WM_CREATE:{
            //do initialization stuff here
    
            //return success
            return(0);
                       }break;
        case WM_PAINT:{
            //validate the window
            hdc = BeginPaint(hwnd, &ps);
    
            //do all painting stuff here
            EndPaint(hwnd, &ps);
    
            //return success
            return(0);
                      }break;
        case WM_DESTROY:{
            //kill the application
            PostQuitMessage(0);
    
            //return success
            return(0);
                        }break;
        default:break;
        }
    
        //process any messages that weren't handled
        return(DefWindowProc(hwnd, msg, wparam, lparam));
    }
    
    // WINMAIN //////////////////////////////////////
    int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int nshowcmd){
        WNDCLASSEX winclass;
        HWND hwnd;
        MSG msg;
    
        //fill in the window clas structure
        winclass.cbSize = sizeof(WNDCLASSEX);
        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;
        winclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    
        //register the window class
        if(!RegisterClassEx(&winclass))
            return(0);
    
        //create the window
        if(!(hwnd = CreateWindowEx(NULL,
                        WINDOW_CLASS_NAME,
                        "Your Basic Window",
                        WS_OVERLAPPEDWINDOW | WS_VISIBLE,
                        0, 0,
                        400, 400,
                        NULL,
                        NULL,
                        hinstance,
                        NULL)))
            return(0);
    
        //enter main event loop
        while(GetMessage(&msg, NULL, 0, 0)){
            //translate
            TranslateMessage(&msg);
    
            //send the message to the window proc
            DispatchMessage(&msg);
        }
    
        //return to windows
        return(msg.wParam);
    }

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Are you compiling as C++? C++ requires a cast from void* so you would have:
    Code:
    winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    Edit: As a side note, you should get a newer IDE/compiler. Visual C++ 2005 Express is free, and I have seen Dev-C++ and Code::Blocks recommended as well (Dev uses the GCC compiler and Code::Blocks can use many different compilers IIRC)
    "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
    Registered User
    Join Date
    Mar 2006
    Location
    Ohio
    Posts
    37
    Okay I took your advice and changed to DevC++. ^_^
    Last edited by xmltorrent; 08-07-2006 at 05:20 PM.

  4. #4
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Don't use NULL, use 0.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Header File Question(s)
    By AQWst in forum C++ Programming
    Replies: 10
    Last Post: 12-23-2004, 11:31 PM
  4. Do I have a scanf problem?
    By AQWst in forum C Programming
    Replies: 2
    Last Post: 11-26-2004, 06:18 PM
  5. Creation of Menu problem
    By AQWst in forum C Programming
    Replies: 8
    Last Post: 11-24-2004, 09:44 PM