Re: GDI Bitmap Prob.
From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 07/16/04
- Next message: Joseph M. Newcomer: "Re: Problem executing"
- Previous message: Joseph M. Newcomer: "Re: Why CMainFrame can't accept the message WM_COPYDATA?"
- In reply to: Vishnukanth: "Re: GDI Bitmap Prob."
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 16 Jul 2004 12:42:24 -0400
The "required resource not found" is a message which should be findable in the MFC source
(you may have to locate it in a string resource); you can set a breakpoint there and
figure out what is not being found. I didn't see anything in your code that should produce
that, unless there is a serious resource leak somewhere.
joe
On Fri, 16 Jul 2004 10:04:17 +0530, "Vishnukanth" <vishnu@solveminds.com> wrote:
>Hai Frd,
>
>Thank you for reply,
>Actually at present I didnot call OnDraw() 0r OnPaint() on
>OnInitialUpdate(), Iam setting only bool variable m_enableBitmap= false in
>constructor
>So when the view is instated it call OnPaint() itself, and here it goes to
>the OnDraw() and Draw the data needed.
>Considered my previous mail only, The first mail & second mail codes are lot
>changed here.
>
>If you had any idea that can help me please mail immediately. urgent.
>
>Thankx for your help and expecting further solution.
>
>Regards,
>Vishnukanth.
>
>
>"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
>news:c8hdf0tcm3lf7h2sjkbh6jv4sp7fde293l@4ax.com...
>> OK, this was informative. Essentially, you are doing your zooming by
>stretching the bitmap
>> which is rendered in OnDraw. Clever. In particular, because the path if
>the bitmap isn't
>> rendered does not declare a CPaintDC, you first render the bitmap and then
>get immediately
>> called again. However, while it makes sense (although I'm not sure I
>really believe this
>> is a good technique for a variety of reasons) it still makes no sense to
>ever call OnDraw
>> or OnPaint from the OnInitialUpdate. Simply call Invalidate(), and this
>code will then
>> execute correctly, and you don't need the special additional call.
>>
>> I would have been more inclined to have actually put all of this code in
>the OnDraw
>> handler, and just test to see if I was rendering to the screen or to the
>printer. If
>> rendering to the screen, I would either use the cached bitmap, or compute
>a new bitmap. I
>> think the code would have been cleaner that way.
>> joe
>>
>>
>> On Thu, 15 Jul 2004 18:41:46 +0530, "Vishnukanth" <vishnu@solveminds.com>
>wrote:
>>
>> >Hai frd,
>> >
>> >Inside Onpaint I had code for displaying data in bitmap form so that I
>can
>> >have smooth scrooling & Zooming
>> >
>> >Inside OnDraw Iam having the Drawing codes with manipulation for the
>view.
>> >
>> >I want the view to be updated ie, whenever I draw on the view using the
>> >mouse event the data has to manipulated & stored.
>> >Since Iam having drawing and manipulation code in OnDraw I had to call
>> >OnDraw only.
>> >
>> >When I called Invalidate() it calls only OnPaint(), So I had forcefully
>> >called OnDraw().
>> >
>> >But as per your advice now I had changed my codes, Iam not calling the
>> >OnDraw() forefully function anywhere.
>> >Iam calling Invalidate() now every where needed.
>> >
>> >But still I had to call OnDraw(), to solve this problem, I setted one
>bool
>> >variable called "m_enableBitmap" that will determine whether my data is
>> >updated or not.
>> >If it is updated, "m_enableBitmap" is set false and it calls the
>Invalidate
>> >and Iam calling the OnDraw inside OnPaint().
>> >Here I think as per your say Iam calling OnDraw only after calling
>> >Invalidate() that will initialize all needed GUI.
>> >
>> >So I think I did not override your words.
>> >Inside OnDraw() "m_enableBitmap" is set true, So that any further zoom or
>> >scrooling will not activate the Ondraw() instead it will use OnPaint
>where
>> >it use
>> >Bitmap StretchBlt().
>> >
>> >Iam now using CreateDIBSection() so that I can overcome bitmap size.
>> >
>> >But this does not solve my problems. Still Iam suffering from the problem
>as
>> >I mentioned befor.
>> >
>> >Here is the code:
>> >
>> >void CNAllBay::OnPaint()
>> >{
>> >CSize size;
>> >size = GetTotalSize();
>> >
>> > if (m_enableBitmap)
>> > {
>> > CPaintDC dc(this); // device context for painting
>> > CBitmap *pOldBitmap;
>> >
>> > OnPrepareDC(&dc);
>> > pOldBitmap = MemDC.SelectObject(&m_bitmap);
>> > dc.StretchBlt(0, 0, size.cx+2500, size.cy+2500, &MemDC, 0, 0,
>> >size.cx+2500, size.cy+2500, SRCCOPY );
>> > // Clean up
>> > MemDC.SelectObject(pOldBitmap);
>> ****
>> So where is MemDC declared? Why is it not a local variable?
>> ****
>> > }
>> > else // call OnDraw()
>> > {
>> > if (m_bitmap.m_hObject != NULL)
>> > {
>> > m_bitmap.DeleteObject();
>> > MemDC.DeleteDC();
>> > }
>> > if (MemDC != NULL)
>> > {
>> > MemDC.SelectObject(pOldBitmap);
>> > delete MemDC;
>> > pOldBitmap = NULL;
>> > }
>> > pDC = GetDC();
>> > OnPrepareDC(pDC);
>> >
>> > LPBITMAPINFO lpbi;
>> > // Fill in the BITMAPINFOHEADER
>> > lpbi = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + (256 *
>> >sizeof(RGBQUAD))];
>> > lpbi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
>> > lpbi->bmiHeader.biWidth = size.cx;
>> > lpbi->bmiHeader.biHeight = size.cy;
>> > lpbi->bmiHeader.biPlanes = 1;
>> > lpbi->bmiHeader.biBitCount = 16;
>> > lpbi->bmiHeader.biCompression = BI_RGB;
>> > lpbi->bmiHeader.biSizeImage = WIDTHBYTES((DWORD)size.cx * 8) * size.cy;
>> > lpbi->bmiHeader.biXPelsPerMeter = 0;
>> > lpbi->bmiHeader.biYPelsPerMeter = 0;
>> > lpbi->bmiHeader.biClrUsed = 0;
>> > lpbi->bmiHeader.biClrImportant = 0;
>> > // Fill in the color table
>> > UINT uUsage = DIB_RGB_COLORS;
>> >
>> > BYTE* m_pBits;
>> > HBITMAP hBitmap = CreateDIBSection(pDC->m_hDC, lpbi, uUsage, (void
>> >**)&m_pBits, NULL, 0 );
>>
>> > delete [] (BYTE *)lpbi;
>> > ASSERT(hBitmap != NULL);
>> > m_bitmap.Attach( hBitmap );
>> >
>> > // And a memory DC, set Map Mode
>> > VERIFY( MemDC.CreateCompatibleDC(pDC));
>> >
>> > // Select the bitmap into the memory DC
>> > pOldBitmap = MemDC.SelectObject(&m_bitmap);
>> >
>> > // draw our nifty pattern on it using default OnDraw()
>> > OnDraw(&MemDC);
>> ****
>> No reason to retain MemDC after you have used it to render the bitmap, so
>it could have
>> been a local variable. It doesn't serve any purpose to retain it
>> ****
>> >
>> > // Select the original bitmap back in
>> > MemDC.SelectObject(pOldBitmap);
>> >
>> > // Clean up
>> > ReleaseDC(pDC);
>> >
>> > }
>> >
>> >}
>> >
>> >But this does not solve my problems. Still Iam suffering from the problem
>as
>> >I mentioned before
>> >
>> >If you had any idea that can help me please mail immediately. urgent.
>> >
>> >Thankx for your help and expecting further solution.
>> >
>> >Regards,
>> >Viahnukanth.
>> >
>> >"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
>> >news:4vuaf0l591eji1p3s359q1ssap9v09g11e@4ax.com...
>> >> Doing any drawing in OnInitialUpdate is completely wrong. Totally and
>> >absolutely. You do
>> >> the drawing in your OnDraw handler, and ONLY there. And you never,
>ever,
>> >under any
>> >> circumstances do you call these functions yourself. They are called
>> >implicitly when the
>> >> window needs to be redrawn. All of this code is wrong where it appears.
>> >>
>> >> It is also completely inappropriate to call OnPaint yourself. Always.
>> >Without exception.
>> >> If you want to redraw something, use Invalidate() or InvalidateRect()
>to
>> >force the
>> >> redrawing. And do all the drawing logic in your OnDraw handler. All of
>it.
>> >>
>> >> Until you fix all these problems, there is no point in worrying about
>why
>> >you get an
>> >> access fault.
>> >> joe
>> >>
>> >>
>> >> On Wed, 14 Jul 2004 14:19:37 +0530, "Vishnukanth"
><vishnu@solveminds.com>
>> >wrote:
>> >>
>> >> >
>> >> >
>> >> >//Having in "MyView.h file"
>> >> >CDC MemDC;
>> >> >CDC *pdc;
>> >> >CBitmap m_bitmap;
>> >> >
>> >> >Iam using OnInitialUpdate() to Show the drawing Pattern at the first
>> >Show.
>> >> >//Inside OnInitialUpdate()
>> >> >
>> >> >void CMyView::OnInitialUpdate()
>> >> >{
>> >> >CSize size;
>> >> >size.cx=1900;
>> >> >size.cy=11330;
>> >> >
>> >> > SetScrollSizes(MM_ANISOTROPIC, size);
>> >> >
>> >> >//To store original bitmap
>> >> > CBitmap * pOldBitmap;
>> >> >
>> >> > // Need a DC
>> >> > pdc = GetDC()
>> >> >;
>> >> > // Need a memory DC, that is compatible with my CPaintDC
>> >> > MemDC.CreateCompatibleDC(&pdc);
>> >> >
>> >> > // Create a bitmap big enough to hold the window's image
>> >> > m_bitmap.CreateCompatibleBitmap(pdc, size.cx, size.cy);
>> >> >
>> >> > // Select the bitmap into the memory DC
>> >> > pOldBitmap = MemDC.SelectObject(&m_bitmap);
>> >> >
>> >> >// draw our nifty pattern on it using default OnDraw()
>> >> >OnDraw(&MemDC);
>> >> >
>> >> >// Select the original bitmap back in
>> >> > MemDC.SelectObject(pOldBitmap);
>> >> >
>> >> > // Clean up
>> >> > ReleaseDC(pDC);
>> >> >}
>> >> >
>> >> >When Iam drawing later on My view using mouse, and OnMyLButtonUp it
>will
>> >> >invoke the OnPaint()
>> >> >
>> >> >//Inside OnPaint() fuction,
>> >> >
>> >> >void CMyView::OnPaint()
>> >> >{
>> >> >
>> >> > CPaintDC dc(this); // device context for painting
>> >> > CBitmap *pOldBitmap;
>> >> > CSize size;
>> >> >
>> >> > OnPrepareDC(&dc);
>> >> >
>> >> >
>> >> > size = GetTotalSize();
>> >> >
>> >> > // Need a memory DC
>> >> > MemDC.CreateCompatibleDC(&dc);
>> >> >
>> >> > //Set MapMode
>> >> > MemDC.SetMapMode(m_nMapMode);
>> >> >
>> >> > // Select in the bitmap
>> >> > pOldBitmap = MemDC.SelectObject(&m_bitmap);
>> >> >
>> >> > // StretchBlt it so that it will adjust the dim. according to the
>> >source
>> >> > dc.StretchBlt(0, 0, size.cx, size.cy, &MemDC, 0, 0, size.cx,
>size.cy,
>> >> >SRCCOPY );
>> >> >
>> >> > // Clean up
>> >> > MemDC.SelectObject(pOldBitmap);
>> >> >}
>> >> >
>> >> >This works for fine when the drawing is not complicated, when we are
>> >drawing
>> >> >on and on at one stage
>> >> >we get an dialogBox "Required resource Was"
>> >> >and aslo
>> >> >
>> >> >Application Error Message Box : "The Instruction at "0x004b2085"
>> >referenced
>> >> >memory at "0x00000000". The memory could not be read.
>> >> >
>> >> >I think this will make easy to understand my problem,
>> >> >Thank you for your reply and expecting a good solution.
>> >> >
>> >> >
>> >> >Regards,
>> >> >Vishnukanth.
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >
>> >> >"Joseph M. Newcomer" <newcomer@flounder.com> wrote in message
>> >> >news:48l9f0hsl8k3g0fb0so6nk6lhqmvdc991r@4ax.com...
>> >> >> We could probably propose a solution to the problem, if we had any
>idea
>> >> >what the problem
>> >> >> is. Nothing in your message explains anything about the problem. It
>> >only
>> >> >shows some code
>> >> >> without any explanation.
>> >> >> joe
>> >> >> On Wed, 14 Jul 2004 11:16:31 +0530, "Vishnukanth"
>> ><vishnu@solveminds.com>
>> >> >wrote:
>> >> >>
>> >> >> >Hai All,
>> >> >> >
>> >> >> >Iam facing a serious problem with the resource when Iam using the
>> >bitmap
>> >> >> >that is larger than the screen.
>> >> >> >I think that the problem is due to the memory consumption of the
>> >source
>> >> >> >rectangle exceeds consumption of the screen
>> >> >> >
>> >> >> >The code Iam following is:
>> >> >> >///////////////////////////////////////
>> >> >> > pDC = GetDC();
>> >> >> >
>> >> >> > OnPrepareDC(pDC);
>> >> >> >
>> >> >> > size = GetTotalSize();
>> >> >> >
>> >> >> > // Need a memory DC
>> >> >> > MemDC.CreateCompatibleDC(&dc);
>> >> >> >
>> >> >> > // Create a bitmap big enough to hold the window's image
>> >> >> > m_bitmap.CreateDiscardableBitmap(pDC, size.cx+1000,
>size.cy+1000);
>> >> >> >
>> >> >> > // Select in the bitmap
>> >> >> > pOldBitmap = MemDC.SelectObject(&m_bitmap);
>> >> >> >
>> >> >> > // Blt it
>> >> >> > dc.BitBlt( 0, 0, size.cx, size.cy, &MemDC, 0, 0, SRCCOPY );
>> >> >> >
>> >> >> > // Clean up
>> >> >> > MemDC.SelectObject(pOldBitmap);
>> >> >> >////////////////////////////////
>> >> >> >
>> >> >> >Urgent! If any body know the solution to this problem.
>> >> >> >Please reply.
>> >> >> >If there is any fault in my code, help me to rectify it.
>> >> >> >
>> >> >> >Thanking in advance.
>> >> >> >
>> >> >> >Regards,
>> >> >> >Vishukanth
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >>
>> >> >> Joseph M. Newcomer [MVP]
>> >> >> email: newcomer@flounder.com
>> >> >> Web: http://www.flounder.com
>> >> >> MVP Tips: http://www.flounder.com/mvp_tips.htm
>> >> >
>> >>
>> >> Joseph M. Newcomer [MVP]
>> >> email: newcomer@flounder.com
>> >> Web: http://www.flounder.com
>> >> MVP Tips: http://www.flounder.com/mvp_tips.htm
>> >
>>
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
- Next message: Joseph M. Newcomer: "Re: Problem executing"
- Previous message: Joseph M. Newcomer: "Re: Why CMainFrame can't accept the message WM_COPYDATA?"
- In reply to: Vishnukanth: "Re: GDI Bitmap Prob."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|