CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Jun 2003
    Posts
    58

    Need Help can't find the problem with my proc.

    what is wrong with this program can someone help me ?
    the terrain picture can't show up. it's Procedure for a child dialog.
    there is no message that the window can't stretch or hBmp not loaded.


    BOOL CALLBACK DlgCreateTerrainProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)
    {
    static _Terrain NewTerrain;
    static HBITMAP hBmp;
    HDC hDC;
    static DWORD a=0;
    static HDC hComDC;
    bool Initialized=false;
    char FileName[150];
    switch(msg)
    {
    case WM_COMMAND :
    {
    switch(LOWORD(wParam))
    {
    case IDC_OPENFILE :
    {
    MessageBox(hDlg,"Test","Info",MB_OK);
    OPENFILENAME Opfn;
    ZeroMemory(&Opfn,sizeof(OPENFILENAME));
    Opfn.Flags=OFN_FILEMUSTEXIST;
    Opfn.hwndOwner=hDlg;
    Opfn.hInstance=GetModuleHandle(NULL);
    Opfn.lpstrFilter="*.BMP";
    Opfn.nMaxFileTitle=50;
    Opfn.lStructSize=sizeof(OPENFILENAME);
    Opfn.lpstrFileTitle=NewTerrain.PicFileName;
    SetCurrentDirectory(Configuration.TerrainPicPath);
    if(GetOpenFileName(&Opfn)==0)return 0;
    SetDlgItemText(hDlg,IDC_EDIT_TERRAINFILE,NewTerrain.PicFileName);
    strcpy(FileName,Configuration.TerrainPicPath);strcat(FileName,NewTerrain.PicFileName);
    DeleteObject(hBmp);
    hBmp=(HBITMAP)LoadImage(GetModuleHandle(NULL),FileName,IMAGE_BITMAP,100,100,LR_LOADFROMFILE|LR_SHARED);
    if(hBmp==NULL)
    {wsprintf(MessageCenter.Message,"File is not in directory : %s",Configuration.TerrainPicPath);MessageBox(hDlg,MessageCenter.Message,"Error",MB_OK);return 0;
    }
    if(SelectObject(hComDC,hBmp)==NULL){MessageBox(hWnd,"Can't SelectObject","Error",MB_OK);}
    RedrawWindow(hDlg,NULL,NULL,RDW_NOCHILDREN|RDW_UPDATENOW|RDW_INTERNALPAINT);
    };break;
    case IDOK :
    {DestroyWindow(hDlg);
    };break;
    }
    };break;
    case WM_PAINT :
    {
    hDC=GetDC(hDlg);a++;
    wsprintf(MessageCenter.Message,"Drawing Terrain %u",a);
    SetWindowText(hMsgEdit,MessageCenter.Message);
    if(hDC==NULL){SetWindowText(hMsgEdit,"Can't Get DC");return 0;}
    if(!Initialized)
    {
    hComDC=CreateCompatibleDC(hDC);
    hBmp=(HBITMAP)LoadImage(GetModuleHandle(NULL),"C:\\Data\\Pic\\Terrain\\Grassland.BMP",IMAGE_BITMAP,100,100,LR_LOADFROMFILE|LR_SHARED);
    Initialized=true;
    }
    SelectObject(hComDC,hBmp);
    if(StretchBlt(hDC,10,10,90,90,hComDC,0,0,99,99,SRCCOPY)==0)SetWindowText(hMsgEdit,"Can't Stretch");
    ReleaseDC(hDlg,hDC);
    };break;
    case WM_DESTROY :
    {
    DeleteObject(hComDC);
    DeleteDC(hComDC);
    EndDialog(hDlg,0);
    };break;
    }
    return 0;
    }
    Last edited by SilentJackqh; August 4th, 2003 at 04:14 PM.

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