|
-
August 4th, 2003, 04:08 PM
#1
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.
-
August 5th, 2003, 11:33 PM
#2
I can make it work with this one but I still don't understand what is wrong with the first one.
BOOL CALLBACK DlgCreateTerrainProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)
{
static _Terrain NewTerrain;
static HBITMAP hBmp,hRet;
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;
}
RECT Rect;
GetClientRect(hDlg,&Rect);
RedrawWindow(hDlg,&Rect,NULL,RDW_ALLCHILDREN|RDW_UPDATENOW|RDW_INVALIDATE);
hDC=GetDC(hDlg);
wsprintf(MessageCenter.Message,"Drawing Terrain %u",a);
SetWindowText(hMsgEdit,MessageCenter.Message);
if(hDC==NULL){SetWindowText(hMsgEdit,"Can't Get DC");return 0;}
hComDC=CreateCompatibleDC(hDC);
hRet=(HBITMAP)SelectObject(hComDC,hBmp);
if(StretchBlt(hDC,10,10,100,100,hComDC,0,0,100,100,SRCCOPY)==0)SetWindowText(hMsgEdit,"Can't Stretch");
DeleteDC(hComDC);
ReleaseDC(hDlg,hDC);
};break;
case IDOK :
{DestroyWindow(hDlg);
};break;
}
};break;
case WM_DESTROY :
{
DeleteDC(hComDC);
EndDialog(hDlg,0);
};break;
}
return 0;
}
-
August 6th, 2003, 12:33 AM
#3
whoa dude help us help you by cutting down and limiting the problem. sometimes people dont post enough code and want help this time i'd say you posted too much. it's a lot for someone to sit and pick through without really any idea of what your problem is.
-
August 6th, 2003, 11:55 AM
#4
Ok, this is the first one that the terrain Pictures didn't show,but no sign the function return error or something else.
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 :
{
strcpy(FileName,Configuration.TerrainPicPath);strcat(FileName,NewTerrain.PicFileName);
DeleteObject(hBmp);
hBmp=(HBITMAP)LoadImage(GetModuleHandle(NULL)
,FileName,IMAGE_BITMAP,100,100,LR_LOADFROMFILE|LR_
SHARED);
SelectObject(hComDC,hBmp);
RedrawWindow(hDlg,NULL,NULL,RDW_NOCHILDREN|RD
W_UPDATENOW|RDW_INTERNALPAINT);
};break;
case IDOK :
{DestroyWindow(hDlg);
};break;
}
};break;
case WM_PAINT :
{
hDC=GetDC(hDlg);
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);
StretchBlt(hDC,10,10,90,90,hComDC,0,0,99,99,
SRCCOPY);
ReleaseDC(hDlg,hDC);
};break;
case WM_DESTROY :
{
DeleteObject(hComDC);
DeleteDC(hComDC);
EndDialog(hDlg,0);
};break;
}
return 0;
}
this is the second one that is works fine
BOOL CALLBACK DlgCreateTerrainProc(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)
{
static _Terrain NewTerrain;
static HBITMAP hBmp,hRet;
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 :
{
strcpy(FileName,Configuration.TerrainPicPath);strcat(FileName,NewTerrain.PicFileName);
DeleteObject(hBmp);
hBmp=(HBITMAP)LoadImage(GetModuleHandle(NULL)
,FileName,IMAGE_BITMAP,100,100,LR_LOADFROMFILE|LR_
SHARED);
RECT Rect;
GetClientRect(hDlg,&Rect);
RedrawWindow(hDlg,& Rect,NULL,RDW_ALLCHILDREN|RDW_UPDATENOW|RDW_INVALI
DATE);
hDC=GetDC(hDlg);
hComDC=CreateCompatibleDC(hDC);
hRet=(HBITMAP)SelectObject(hComDC,hBmp);
StretchBlt(hDC,10,10,100,100,hComDC,0,0,10
0,100,SRCCOPY);
DeleteDC(hComDC);
ReleaseDC(hDlg,hDC);
};break;
case IDOK :
{DestroyWindow(hDlg);
};break;
}
};break;
case WM_DESTROY :
{
DeleteDC(hComDC);
EndDialog(hDlg,0);
};break;
}
return 0;
}
I still don't understand why the first one can't show the picture.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|