Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have done all the things till the browse button. the path of file is given by browse button, so on clicking the ok button it should display the image that is given by browse button. so i write code for OK button as
C++
void CFileOpenDlg::OnBnClickedButton2()
{
    CRect r;
    CBitmap* m_bitmap;
    CDC dc, *pDC;
    BITMAP bmp;

    m_bitmap = new CBitmap();
    m_bitmap->LoadBitmapW(IDB_BITMAP1);
    m_bitmap->GetBitmap(&bmp);
    pDC = this->GetDC();
    dc.CreateCompatibleDC(pDC);
    dc.SelectObject(m_bitmap);
    pDC->BitBlt(200, 200, bmp.bmWidth, bmp.bmHeight, &dc,0 , 0, SRCCOPY);
    m_bitmap->DeleteObject();
    m_bitmap->Detach()
}

I am getting this error.
error C2065:'IDB_BITMAP' : undeclared identifier

Wwhat's my mistake in it? :doh:
waiting for ur reply...........
Posted
Updated 10-Jun-10 7:25am
v3
Comments
Sweety Khan 10-Jun-10 13:06pm    
sorry the error is error C2065: 'IDB_BITMAP1' : undeclared identifier
Moak 10-Jun-10 13:10pm    
Could you be so nice and format your source code (see your last questions)?
Sandeep Mewara 10-Jun-10 13:26pm    
Pre tags are your friend. Please use it from next time to format code part.
Sweety Khan 10-Jun-10 13:32pm    
means? why are u saying like that? did i write something wrong? do u mean that i should delete this question or code from here??????????
Sweety Khan 10-Jun-10 13:35pm    
i made this comment for moak

I think you've not included the resource file that includes a reference to this (poorly named) bitmap.
 
Share this answer
 
Comments
Sweety Khan 10-Jun-10 14:10pm    
no i have added it
Sweety Khan 10-Jun-10 14:38pm    
oh i got my mistake. i should use image name in place of 'IDB_BITMAP1' which is returned by browse button. browse button code is

void CFileOpenDlg::OnBnClickedButton1()
{
	CFileDialog dlg(TRUE);
	int result=dlg.DoModal();
	if(result==IDOK)
	{
		path=dlg.GetPathName();
		UpdateData(FALSE);
	}
}

so i replace 'IDB_BITMAP1' by path. program build successfully but i dont get image on clicking ok button :( 
Sweety Khan 10-Jun-10 14:40pm    
and i use pre tag in the above comment
hi,
please make sure you have understanded the usage of LoadBitmap() function: The LoadBitmap function loads the specified bitmap resource from a module's executable file.
it CAN NOT load a bitmap from files.
u can use LoadImage() instead of LoadBitmap() to loading a bitmap resource from a external file(Only support from WinNT). Or, open a file and read it with CreateDIBitmap().
the best way i think is use the Image class(GDI+) to load a image file, the only thing need you to do is allocate a Image object in stack( call the ctor(path) of the object ).

any way, the reference document is the best friend of u, please understand any thing you want to use before you use it.
 
Share this answer
 
Comments
Sweety Khan 12-Jun-10 12:41pm    
where is the reference document?
Sweety Khan 12-Jun-10 14:47pm    
plz see whats missing in it?

void CFileOpenDlg::OnBnClickedButton2()

{
	// TODO: Add your control notification handler code here
   HANDLE hBitMap = ::LoadImage(0, path,IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

  CBitmap bmp;
  bmp.Attach((HBITMAP)hBitMap); // handle you got from LoadBitmap
  BITMAP bitmap;
  bmp.GetBitmap(&bitmap);
  int size = bitmap.bmHeight*bitmap.bmWidth*bitmap.bmBitsPixel/8;
  BYTE *lpBits = new BYTE[ size ];
  ::GetBitmapBits((HBITMAP)hBitMap,size,lpBits );
}
0817H 13-Jun-10 0:42am    
void CFileOpenDlg::OnBnClickedButton2()
{
// TODO: Add your control notification handler code here
HANDLE hBitMap = ::LoadImage(0, path,IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
// we need a member pointer to hold an object, when we quit the application we must destroy it
m_pBmp = CBitmap::FromHandle(hBitMap); // CBitmap* m_pBmp
somepanel.Invalidate(); // somepanel is your panel you which you want to draw
}

In your CFileOpenDlg::OnEraseBkgnd() return a TRUE value to tell the system you wanna no default erase action, else you window may flicker.
In your CFileOpenDlg::OnPaint() Draw the bitmap, code as following:
dc.CreateCompatibleDC(pDC);
dc.SelectObject(m_bitmap);
pDC->BitBlt(200, 200, bmp.bmWidth, bmp.bmHeight, &dc,0 , 0, SRCCOPY); // you should assign the width or height by yourself, pDC is a DC object, the parameter of the OnPaint()
Sweety Khan 16-Jun-10 4:09am    
i got these errors

error C2664: 'CBitmap::FromHandle' : cannot convert parameter 1 from 'HANDLE' to 'HBITMAP'
error C2065: 'somepanel' : undeclared identifier
error C2228: left of '.Invalidate' must have class/struct/union
0817H 17-Jun-10 21:55pm    
o m g, orz,
HBITMAP hBitMap = (HBITMAP)::LoadImage(0, path,IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
// somepanel is your panel which you want to draw
left of '.Invalidate' is the somepanel i want you to create by yourself...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900