i'm trying building a BITMAP from memory, but isn't easy :(

            //create the button
            HandleButton=CreateWindowEx (0,"button", "hello\t\tHI",
            WS_CHILD | WS_VISIBLE |  BS_TEXT | BS_BOTTOM |BS_BITMAP,
            100, 100,500, 200,hwnd, (HMENU)4000,hInstance, 0) ;

            //create a dc and bitmap in memory
            HDC memoryDC =CreateCompatibleDC(GetDC(hwnd));
            HBITMAP bitmap=CreateCompatibleBitmap(GetDC(hwnd),500,200);
            SelectObject(memoryDC, bitmap);

            //get the icon
            HandleIcon=(HICON)LoadImage(hInstance,"C:\\acrobat.ico",IMAGE_ICON,SM_CXICON,SM_CYICON,LR_LOADFROMFILE | LR_DEFAULTCOLOR);
            DrawIcon(memoryDC,0,0,HandleIcon);
            TextOut(memoryDC,0,0,"hello world",11);

            //send the bitmap to button
            SendMessage(HandleButton, BM_SETIMAGE, IMAGE_BITMAP,(LPARAM)bitmap );
            return 0;

my problem is when i create the HDC and HBITMAP... i'm getting several errors:

error: "jump to case label [-fpermissive]"
error: "crosses initialization of 'HBITMAP__* bitmap'"
error: "crosses initialization of 'HDC__* memoryDC'"
error: "jump to case label [-fpermissive]"
error: "crosses initialization of 'HBITMAP__* bitmap'"
error: "crosses initialization of 'HDC__* memoryDC'"

what i'm doing wrong?

Recommended Answers

All 8 Replies

sorry... i continues witht several errors :(
please tell what i'm doing wrong... please

or did i forget add something to the project?
for test, i did a copy-paste of that code... but i continue with same errors.
maybe i need add 1 library or something... or select any option... i use the CodeBlocks IDE.

now i know why these type of error: "crosses initialization of 'objecname'"
because i can't do something like these:

HDC memdc=GetDC(hwnd);

but i must do:

HDC memdc;
memdc=GetDC(hwnd);

(i did with HDC and GetDC(), but it's valid for very objects and functions)
now i must see why i can't show the bitmap :(

case WM_SHOWWINDOW:

            //create the button
            HandleButton=CreateWindowEx (0,"button", "hello\t\tHI",
            WS_CHILD | WS_VISIBLE |  BS_TEXT | BS_BOTTOM |BS_BITMAP,
            100, 100,500, 200,hwnd, (HMENU)4000,hInstance, 0) ;

            //create a dc and bitmap in memory
            BITMAP bm;
            HBITMAP g_hbmBall;
            g_hbmBall =(HBITMAP) LoadImage(hInstance, "C:\\coeurs-03.bmp",IMAGE_BITMAP,LR_DEFAULTSIZE,LR_DEFAULTSIZE,LR_LOADFROMFILE);
            HDC hdc;
            hdc=GetDC(hwnd);
            HDC hdcMem;
            hdcMem=CreateCompatibleDC(hdc);
            HBITMAP hbmOld;
            hbmOld =(HBITMAP) SelectObject(hdcMem, g_hbmBall);

            SendMessage(HandleButton, BM_SETIMAGE, IMAGE_BITMAP,(LPARAM)g_hbmBall );
            return 0;

Create the button in WM_CREATE with button style BS_OWNERDRAW only.
Handle the drawing in WM_DRAWITEM

i never use that message with a button, but i don't want lose the button face :(

but goind back to the question:
what i'm doing wrong for create the Bitmap, in memory?

You should be able to do this using the default Win32 classes (such as CreateCompatibleBitmap function). But if you are not familiar with these classes, you might run into problems that are hard to resolve.
I am currently using a programming toolkit (leadtools) that provides good functions to create a bitmap in memory, load data into it, and then save it with many file formats. You can find more information here:
http://support.leadtools.com/CS/forums/2692/ShowPost.aspx
http://support.leadtools.com/CS/forums/20633/ShowPost.aspx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.