CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2003
    Posts
    58

    Help, I don't know what is wrong with this code,

    Help, I don't know what is wrong with this code,
    but when I Display it in a Window, it's nothing happen, the pictures doesn't come up.
    WM_PAINT seems find I try with single pictures it's works.
    Many things I cut in here the original code is more complex, but I think noone will see it if too long.
    do I miss something in here ?

    HBITMAP DrawCityMap(int Width,int Height)
    {
    int a;
    char TerrainFile[150]="C:\\Data\\Pic\\Terrain\\Grassland.Bmp";
    char FacilityFile[5][150]={"C:\\Data\\Pic\\Terrain\\Jungle.Bmp","C:\\Data\\Pic\\Terrain\\Craters.Bmp"
    ,"C:\\Data\\Pic\\Terrain\\Desert.Bmp","C:\\Data\\Pic\\Terrain\\Ice.Bmp","C:\\Data\\Pic\\Terrain\\Volcanic.Bmp"};
    HDC hDC=CreateDC("DISPLAY", NULL, NULL, NULL);
    HBITMAP hBmp,hBmp2;
    HDC hComDC1,hComDC2;
    hBmp=(HBITMAP)LoadImage(hInst,TerrainFile,IMAGE_BITMAP,Width,Height,LR_LOADFROMFILE);
    hComDC1=CreateCompatibleDC(hDC);
    SelectObject(hComDC1,hBmp);
    for(a=0;a<5;a++)
    {
    hBmp2=(HBITMAP)LoadImage(hInst,FacilityFile[a],IMAGE_BITMAP,Width,Height,LR_LOADFROMFILE);
    hComDC2=CreateCompatibleDC(hDC);
    SelectObject(hComDC2,hBmp2);
    StretchBlt(hComDC1,a*Width/5,0,Width/5,Height,hComDC2,0,0,Width,Height,SRCCOPY);
    DeleteDC(hComDC2);
    DeleteObject(hBmp2);

    }
    hBmp2=(HBITMAP)GetCurrentObject(hComDC1,OBJ_BITMAP);
    DeleteDC(hComDC1);DeleteDC(hComDC2);DeleteObject(hBmp);
    DeleteDC(hDC);
    return hBmp2;
    }

    here is the window Procedures call that function :

    case WM_PAINT :
    {
    HDC hDC=GetDC(hDlg);
    hCity=DrawCityMap(400,400);
    hComDC=CreateCompatibleDC(hDC);
    SelectObject(hComDC,hCity);
    StretchBlt(hDC,10,10,400,400,hComDC,0,0,400,400,SRCCOPY);
    DeleteObject(hCity);
    DeleteDC(hComDC);
    ReleaseDC(hDlg,hDC);
    };break;

  2. #2
    I see plenty of things wrong with it. The function DrawCityMap must load six bitmaps every single time the program receives a WM_PAINT message, which can occur quite often. Why not load the bitmaps when the program starts, and cache them to lighten the load? Better yet, see if you can remove the DrawCityMap call.

    Also, you're using hard-coded fully qualified paths. That's a no-no if you want to distribute your applications.

    These may not be strict solutions to your problem, but if you take my advice, you'll make your program much faster.

  3. #3
    Join Date
    Jun 2003
    Posts
    58
    Actually, all the Pictures file changes when I call WM_PAINT.
    I found my problem it's seems not in the function.
    when I call it, it deleted by SetWindowRgn, when I refresh it, it back.

    thanx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured