Problem Bitmap sur CStatic
Bonjour
je ne comprend pas trop ce qui se passe. Je cherche � apposer une bItmap sur une ressource CStatic. Je cr�e ma ressoruce de cette mani�re:
Code:
1 2 3 4 5 6 7 8 9 10 11
|
CWnd *wndObject = new CCtrlStaticVis();
((CCtrlStaticVis*)wndObject)->Create( GetLabel(),
WS_CHILD|WS_VISIBLE|SS_BITMAP|SS_CENTERIMAGE|SS_NOTIFY,
GetPlacement(),
parent,
GetTag());
SetCtrlObject(wndObject); |
Quand on clique sur mon CStatic, une boite de Dialogue s'ouvre. Je cherche � charger l'image que je choisis via CFileDialog
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
void CCtrlStaticVis::OnStnClicked()
{
CString OpenFilter;
HBITMAP hBitmap;
OpenFilter = "(*.bmp)|*.bmp|";
OpenFilter += "(*.png)|*.png||";
CFileDialog fileOpenDialog(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
OpenFilter, this);
bool iRet = fileOpenDialog.DoModal();
if(iRet==IDOK)
{
CFile File;
VERIFY(File.Open(fileOpenDialog.GetPathName(),CFile::modeRead));
//m_fileToLoad = fileOpenDialog.GetPathName();
m_fileToLoad = fileOpenDialog.GetPathName();
SetBitmap(m_fileToLoad);
}
RedrawWindow();
} |
L'image � charger �crite en dur "C:\\image2.bmp" s'affiche.(avec hBitmap1 mies en comentaire)
La m�me image r�cup�r�e via un CFileDialog provoque un crash, hBitmap mal initialis� (0x00000000)(avec hBitmap mise en comentaire)
Et le truc aussi, c'est que lorsque je charge l'image "C:\\image2.bmp", hBitmap et hBitmap1 sont mal instanci�s (0x00000000). Par contre, lorsque je charge une image autre que "C:\\image2.bmp", elle apprait bien dans le CStatic!!
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
void CCtrlStaticVis::SetBitmap(CString strBitmap)
{
m_sBitmap = strBitmap;
//
CString bSlash = "\\";
CString dbSlash = "\\\\";
m_sBitmap.Replace(bSlash,dbSlash);
HBITMAP hBitmap = (HBITMAP) ::LoadImage(NULL,//AfxGetInstanceHandle(),
(LPCTSTR)"C:\\image2.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);
HBITMAP hBitmap1 = (HBITMAP) ::LoadImage(NULL,//AfxGetInstanceHandle(),
m_sBitmap, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE);
// Do we have a valid handle for the loaded image?
if (hBitmap)
{
// Delete the current bitmap
if (m_bmpBitmap.DeleteObject())
m_bmpBitmap.Detach(); // If there was a bitmap, detach it
// Attach the currently loaded bitmap to the bitmap object
m_bmpBitmap.Attach(hBitmap);
}
m_bmpBitmap.GetBitmap(&bm); //Get Bitmap Structure
Invalidate();
} |
Je ne comprend pas ce qui se passe.
Merci