problem with case paint

This is a discussion on problem with case paint within the Windows Programming forums, part of the Platform Specific Boards category; Ok the error says: ANSI C++ forbids implicit conversion from `void *' in initialization I have no idea wtf that ...

  1. #1
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269

    problem with case paint

    Ok the error says:

    ANSI C++ forbids implicit conversion from `void *' in initialization

    I have no idea wtf that means, and if you can help me, heres the paint part:

    Code:
    case WM_PAINT:
            {
            BITMAP bm;
            PAINTSTRUCT ps;
    
            HDC hdc = BeginPaint(hwnd, &ps);
    
            HDC hdcMem = CreateCompatibleDC(hdc);
            [b]HBITMAP hbmOld = SelectObject(hdcMem, g_hbmBall);[b]
    
            GetObject(g_hbmBall, sizeof(bm), &bm);
    
            BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
    
            SelectObject(hdcMem, hbmOld);
            DeleteDC(hdcMem);
    
            EndPaint(hwnd, &ps);
            }
            break;
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  2. #2
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    oops im mean
    Code:
    case WM_PAINT:
            {
            BITMAP bm;
            PAINTSTRUCT ps;
    
            HDC hdc = BeginPaint(hwnd, &ps);
    
            HDC hdcMem = CreateCompatibleDC(hdc);
            HBITMAP hbmOld = SelectObject(hdcMem, g_hbmBall);//here
    
            GetObject(g_hbmBall, sizeof(bm), &bm);
    
            BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
    
            SelectObject(hdcMem, hbmOld);
            DeleteDC(hdcMem);
    
            EndPaint(hwnd, &ps);
            }
            break;
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Think you need a cast because you are using .cpp file rather than .c files.

    HBITMAP hOldBMP=(HBITMAP)SelectObject(hdc,hBitmap);


    (MHO: Don't like the mixing of C and C++. Do not think you should call beginPaint() to init a variable. Not good style or good for speed or to find errors. You should already have your DC ready to just Blit when you need to paint. This method will not work fast enough if there is a lot to draw.)


    There is no test for the update region, so the whole area is always repainted slowing you down. What if the update region is different size than the bitmap?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269

    Unhappy

    wut?
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    who?

    where?





    Don't you know what a type cast is?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    the Corvetter
    Join Date
    Sep 2001
    Posts
    1,584
    Even in C files, you need to cast. Because it explicitly states what data type the parameter is. Otherwise, you might get compile time errors. I don't think it would cause runtime though...
    1978 Silver Anniversary Corvette

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Did you test your theory Garfield?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  8. #8
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    whats a type cast or whatever
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  9. #9
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Type casting defines the return type.

    float fVar=1.2345;
    int iVar=0;

    iVar = fVar;//will generate 'loss of data' warning
    iVar = (int)fVar;//will not generate warning

    in your case

    HBITMAP hOldBMP=(HBITMAP)SelectObject(hdc,hBitmap); //the bold bit is the type cast
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  10. #10
    Flash Animator, OF DOOOOM bluehead's Avatar
    Join Date
    Nov 2001
    Posts
    269
    oooooh ok thanx so far you helped the best
    Code:
    #if _emo
      #define stereo_type_i_dislike
    #endif

  11. #11
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,648
    Further, you should understand that SelectObject() returns a void* (if you hadn't already gotten that much!), and void pointers MUST be cast in C and C++. The reason for the casting is simple: to avoid mistakes. What if, for instance some idiot tried to do this:

    char *s = SelectObject( dc, brush );

    The compiler will let you know that you may not want to do that, and it does so by demanding that you cast the void*!

    Then again,

    char *s = (char*)SelectObject( dc, brush );


    ...would compile - but at least you got a fair warning the first time!
    Code:
    #include <ip.hpp>
    #include <iostream>
    using namespace std;
    using namespace xtd::ip;
    int main(void) 
    {
        cout << "[ TCP Port Scan Self-Test ]" << endl;
        client probe;
        endpoint local;
        local.address = "127.0.0.1";
        local.protocol = IPPROTO_TCP;
        for(local.port = 0; local.port < (1 << 16); ++local.port)
        {
            if(probe.open(local))
                cout << "Listening: ";
            else
                cout << "No Response: ";
            cout << local.port << endl;
        }    
    }

  12. #12
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Actually SelectObject() returns a HGDIOBJ (according to MSVC 6).


    >>pointers MUST be cast in C
    Not totally correct, though I agree it is good practice. It only MUST be cast if you use .cpp files.

    I used SelectObject 664 times in my comercial web tool and cast none of them. I do use .c files. Try it without the .cpp files and see what I mean.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How can I make this code more elegant?
    By ejohns85 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2009, 08:55 AM
  2. Help problem in winsock code
    By lolguy in forum C Programming
    Replies: 8
    Last Post: 02-12-2009, 06:33 PM
  3. Replies: 27
    Last Post: 10-11-2006, 04:27 AM
  4. Problem with simple case statements
    By shoobsie in forum C Programming
    Replies: 2
    Last Post: 05-08-2006, 08:39 AM
  5. rand()
    By serious in forum C Programming
    Replies: 8
    Last Post: 02-15-2002, 01:07 AM

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