Jump to content

Loading a bitmap as background image for a dialog


Recommended Posts

Guest massimo
Posted

Hallo,

I'm new to SPV development. Im writting a little app where

I would like to display a bitmap as a background image in a

dialog. The image is saved in its own file (not in the resources)

I found a function called SHLoadImage(....);

I couldn't figure out what I've to do after the this method has load

the image. I think somehow the loaded bitmap should be attached

to the dialog but how?

cheers :?:

  • 1 month later...
Posted

Hi Massimo,

I'm looking at how to do this as we speak, the only difference is that my bitmap is already in the project resources (just means i call LoadBitmap to get my HBITMAP instead of the SHLoadImage function).

I'll let you know how i get on - this is where i am starting, it might be useful to you:

MSDN page on creating bitmaps in CE

cheers!

Posted

Hi again Massimo,

i think i have cracked it!!

this code comes with no warranty but it works for me. i am using the WM_PAINT message handler to do the painting and have pasted the entire dialog proc below:

// - splash window -------------------------------------------------------------






LRESULT	CALLBACK SplashDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)


{


    BOOL bRet = TRUE;


    


    switch (message)


        {




  case WM_INITDIALOG:


            bRet = OnSplashInitWindow(hDlg, IDM_DONECANCEL_MENU);


            break;




  case WM_PAINT:


 	 // paint the logo onto dialog


 	 HDC memDc;


 	 HDC myDc;


 	 HBITMAP hLogoBmp;


 	 HGDIOBJ hOldSel;


 	 RECT clientRect;


 	 PAINTSTRUCT ps;




 	 // indicate that painting has started


 	 myDc = BeginPaint(hDlg, &ps);




 	 // get the handle to the bitmap in the application resources


 	 // note g_hInst is the hInstance value passed to WinMain, kept in


 	 // a global variable. IDB_SPLASH is a bitmap file inserted into


 	 // the project resources.


 	 hLogoBmp = LoadBitmap(g_hInst,MAKEINTRESOURCE(IDB_SPLASH));




 	 // create a memory context for drawing the bitmap before display


 	 memDc = CreateCompatibleDC(myDc);




 	 // select the logo bmp into the memory device context for operations


 	 hOldSel = SelectObject (memDc, hLogoBmp);




 	 // get dialog width and height


 	 GetClientRect(hDlg, &clientRect);




 	 // copy the bitmap image from the memory DC to the screen DC


 	 BitBlt (myDc, 0, 0, clientRect.right, clientRect.bottom, memDc, 0, 0, SRCCOPY);




 	 // restore original selection and destroy the memory DC


 	 SelectObject(memDc, hOldSel);


 	 DeleteObject(hLogoBmp);


 	 DeleteDC (memDc);


 	 


 	 // indicate that painting is finished


 	 EndPaint(hDlg, &ps);


 	 break;


    






        case WM_COMMAND:


            {


            UINT idc;


            


            idc = LOWORD(wParam);


            switch(idc)


    {




    case IDM_CANCEL:


    case IDM_DONE:


                    EndDialog(hDlg, TRUE);


                    break;


    }


            }


            break;




        case WM_DESTROY:


            break;




        default:


            bRet = FALSE;


            break;


        }


    return bRet;


}

the only thing i would add is that i am sure that this won't work for all bitmap types in all formats since nothing in the code addresses potential palette issues. for the record my bitmap is a 256 colour (8-bit) format, probably device independent but i'm not quite sure - i used paint shop pro 6 to create it.

anyway, hope that helps, best of luck!

blumf/

  • 3 weeks later...
Guest orangewinger
Posted

You can use SHLoadDIBitmap() to load a bitmap from the device rather tan from the resources as well.

The API functions to load bitmaps only work with Windows Bitmap files, to use jpegs or gifs you need to get the VOImage library and use that (www.pocketpcdn.com).

Dave Lee

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.