Click here to Skip to main content
15,913,325 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: AfxGetMainWnd while creating CMainFrame Pin
PJ Arends1-Aug-02 7:07
professionalPJ Arends1-Aug-02 7:07 
GeneralRe: AfxGetMainWnd while creating CMainFrame Pin
Miguel Lopes1-Aug-02 8:48
Miguel Lopes1-Aug-02 8:48 
GeneralRe: AfxGetMainWnd while creating CMainFrame Pin
PJ Arends1-Aug-02 9:14
professionalPJ Arends1-Aug-02 9:14 
GeneralRe: AfxGetMainWnd while creating CMainFrame Pin
Miguel Lopes2-Aug-02 0:57
Miguel Lopes2-Aug-02 0:57 
Question'Notify'-> WS_NOTIFY?!? Pin
Selevercin31-Jul-02 14:03
Selevercin31-Jul-02 14:03 
AnswerRe: 'Notify'-> WS_NOTIFY?!? Pin
Marc Clifton31-Jul-02 14:29
mvaMarc Clifton31-Jul-02 14:29 
GeneralRe: 'Notify'-> WS_NOTIFY?!? Pin
Selevercin31-Jul-02 14:44
Selevercin31-Jul-02 14:44 
GeneralRe: 'Notify'-> WS_NOTIFY?!? Pin
Marc Clifton31-Jul-02 16:29
mvaMarc Clifton31-Jul-02 16:29 
I usually display bitmaps that have been loaded from a file, not a resource. Here's a code snippet:
<br />
BitmapControl::BitmapControl(CWnd* parent) : CWnd(), hInternalImage(0)<br />
{<br />
}<br />
<br />
void BitmapControl::Create(const CWnd* v, const CRect& r, const int id)<br />
{<br />
	HCURSOR cursor=AfxGetApp()->LoadCursor(IDC_ARROW);<br />
	const char* className=AfxRegisterWndClass(0, cursor, (HBRUSH) GetStockObject(WHITE_BRUSH));<br />
	CWnd::CreateEx(0, className, "", WS_CHILD | WS_VISIBLE, r, (CWnd*)v, id);<br />
}<br />
<br />
void BitmapControl::LoadImage(const AutoString& imageFile)<br />
{<br />
	if (hInternalImage)<br />
	{<br />
		DeleteObject(hInternalImage);<br />
	}<br />
	hInternalImage=::LoadImage(0, imageFile, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT);<br />
	InvalidateRect(NULL);<br />
}<br />
<br />
void BitmapControl::OnLButtonDown(UINT nFlags, CPoint point)<br />
{<br />
	int x=point.x;<br />
	int y=point.y;<br />
	// ... do something about the click<br />
	CWnd::OnLButtonDown(nFlags, point);<br />
}<br />
<br />
void BitmapControl::OnPaint(void)<br />
{<br />
	HANDLE h=hInternalImage;<br />
<br />
	CRect r=GetClientRect();<br />
	PAINTSTRUCT ps;<br />
	CDC* dc=BeginPaint(&ps);<br />
	if (h)<br />
	{<br />
		CDC src;<br />
		src.CreateCompatibleDC(NULL);<br />
		CBitmap* bitmap=CBitmap().FromHandle((HBITMAP)h);<br />
		BITMAP bm;<br />
		bitmap->GetBitmap(&bm);<br />
		src.SelectObject(bitmap);<br />
		int destW=r.right-r.left;<br />
		int destH=r.bottom-r.top;<br />
		int srcW=bm.bmWidth;<br />
		int srcH=bm.bmHeight;<br />
		dc->FillSolidRect(0, 0, destW, destH, COLORREF(0x00FFFFFF));<br />
		dc->BitBlt((destW-srcW)/2, (destH-srcH)/2, r.right-r.left, r.bottom-r.top, &src, 0, 0, SRCCOPY);<br />
		EndPaint(&ps);<br />
	}<br />
	else<br />
	{<br />
		int destW=r.right-r.left;<br />
		int destH=r.bottom-r.top;<br />
		dc->FillSolidRect(0, 0, destW, destH, COLORREF(0x00FFFFFF));<br />
		EndPaint(&ps);<br />
	}<br />
	CWnd::OnPaint();<br />
}<br />
<br />


---
Marc
AnswerRe: 'Notify'-> WS_NOTIFY?!? Pin
PJ Arends31-Jul-02 14:44
professionalPJ Arends31-Jul-02 14:44 
GeneralRe: 'Notify'-> WS_NOTIFY?!? Pin
Selevercin31-Jul-02 14:54
Selevercin31-Jul-02 14:54 
GeneralRe: 'Notify'-> WS_NOTIFY?!? Pin
PJ Arends31-Jul-02 15:09
professionalPJ Arends31-Jul-02 15:09 
GeneralBeginner's one: Minimizing wnd message... Pin
BlackSmith31-Jul-02 13:48
BlackSmith31-Jul-02 13:48 
GeneralRe: Beginner's one: Minimizing wnd message... Pin
PJ Arends31-Jul-02 14:39
professionalPJ Arends31-Jul-02 14:39 
GeneralRe: Beginner's one: Minimizing wnd message... Pin
JohnnyG31-Jul-02 15:16
JohnnyG31-Jul-02 15:16 
Questionmfc70.dll bug? Pin
Marc Clifton31-Jul-02 13:18
mvaMarc Clifton31-Jul-02 13:18 
General102 compiling errors in commdlg.h Pin
redeemer31-Jul-02 13:00
redeemer31-Jul-02 13:00 
GeneralRe: 102 compiling errors in commdlg.h Pin
Chris Losinger31-Jul-02 13:02
professionalChris Losinger31-Jul-02 13:02 
GeneralCalling AfxMessageBox from within CDocument Class Pin
adamUK31-Jul-02 12:34
adamUK31-Jul-02 12:34 
GeneralRe: Calling AfxMessageBox from within CDocument Class Pin
adamUK23-Aug-02 5:18
adamUK23-Aug-02 5:18 
GeneralProblem with InsertMenu with respect to Release vs. Debug compulation Pin
Eldon Zacek31-Jul-02 11:56
Eldon Zacek31-Jul-02 11:56 
GeneralRe: Problem with InsertMenu with respect to Release vs. Debug compulation Pin
Chris Losinger31-Jul-02 13:03
professionalChris Losinger31-Jul-02 13:03 
GeneralRe: Problem with InsertMenu with respect to Release vs. Debug compulation Pin
Eldon Zacek31-Jul-02 13:16
Eldon Zacek31-Jul-02 13:16 
GeneralRe: Problem with InsertMenu with respect to Release vs. Debug compulation Pin
Eldon Zacek31-Jul-02 17:09
Eldon Zacek31-Jul-02 17:09 
GeneralCTreeCtrl checkboxes, oleaut.dll, and MSDN Pin
dazinith31-Jul-02 11:41
dazinith31-Jul-02 11:41 
GeneralRe: CTreeCtrl checkboxes, oleaut.dll, and MSDN Pin
dazinith1-Aug-02 4:34
dazinith1-Aug-02 4:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.