Bitmap resize on same DC

I am a little be confused!

I have a custom control with a bitmap inside
I create the bitmap with this code
CClientDC dc(this) ;
if (m_dcGrid.GetSafeHdc() == NULL)
    m_dcGrid.CreateCompatibleDC(&dc) ;
m_nClientWidth,m_nClientHeight) ;
    m_pbitmapOldGrid = m_dcGrid.SelectObject(&m_bitmapGrid) ;

and in OnPaint i have:
CPaintDC dc(this) ;  // device context for painting
CDC memDC ;
CBitmap memBitmap ;
CBitmap* oldBitmap ; // bitmap originally found in CMemDC

memDC.CreateCompatibleDC(&dc) ;
memBitmap.CreateCompatibleBitmap(&dc, m_nClientWidth, m_nClientHeight)
oldBitmap = (CBitmap *)memDC.SelectObject(&memBitmap) ;

if (memDC.GetSafeHdc() != NULL)
memDC.BitBlt(0, 0, m_nClientWidth, m_nClientHeight,  &m_dcGrid, 0, 0,
dc.BitBlt(0, 0, m_nClientWidth, m_nClientHeight, &memDC, 0, 0, SRCCOPY)

memDC.SelectObject(oldBitmap) ;

Now, my goal is to change the bitmap size when the user click on a
How can i proceed?
I have tried with
MyObject->MoveWindow(0,0,300,200) but the result is that the object is
resize, but the bitmap remain of the same size.
Can someone help me?


3/29/2006 9:14:29 AM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies

Similar Articles

[PageSpeed] 31

Dont you need to stretch/compress it rather than move it? How about


ajaykalra (6841)
3/29/2006 3:00:37 PM
I have tried it but with non success!
First i always do a MyObject->MoveWindow(0,0,300,200) to resize the
control where the bitmap is stored.
And then i call a function where:

   m_dcGrid.StretchBlt(0, 0, m_nClientWidth, m_nClientHeight,
&m_dcGrid, 0, 0, m_nOriginalWidth, m_nOriginalHeight,  SRCCOPY) ;

Where the "Original" are the for example 500 and 100 and the "Client"
(the new one) are 800, 200.
The OnPaint remain the same.

In this way the control is resized and i see the bitmap resized, but i
still see ONLY the original portion of the Bitmap.

I will try to explain
At start i have a bitmap that fit a control 500x100.
Then a call MoveWindow and the control resize to 800x200. Now i see
only the 500x100 portion of my bitmap, the rest is black.
If i call the StretchBlt i ALWAYS see 500x100 with rest of image black,
but in the rectangle (500x100) i can see that the bitmap has been
enlarged, but i only see a portion of that.

I hope this is clear. Unfortunately is difficult to explain it even in
my language and is more difficult in english!
Help is appreciate.

3/29/2006 3:29:02 PM
I am not sure if I understand it. Try calling StretchBlt without moving
the control. Just see if you can stretch it. Once you have that
working, move the control. 


ajaykalra (6841)
3/29/2006 3:32:12 PM
The StretchBlt return 1, so it seems it works, but on the window i
cannot see any changes

3/29/2006 3:39:08 PM
I have tried another way (but i don't know if is correct)
Create a second bitmap and assign it to the same CDC


    SelectObject(m_dcGrid, BitmapGrid2);

In this way the bitmap is all visible, but this is a new bitmap. I need
to copy the first one into these.
How can i do that?

3/29/2006 3:49:48 PM

Similar Artilces:

Resizing the dialog bar
Hi, I am trying to resize the dialog bar programatically to fit exactly to its parent window's width. I have problem with this dialogbar when working on different monitors. Can any one please help me? Thanks Show your code. joe On Wed, 16 Dec 2009 09:08:01 -0800, Ram <> wrote: >Hi, > >I am trying to resize the dialog bar programatically to fit exactly to its >parent window's width. > >I have problem with this dialogbar when working on different monitors. > >Can any one please help me? > &g...

hi, I display a bitmap on my sdi client area and I want to draw on the bitmap in transparent mode so the area I draw above the bitmap only will change the bitmap pixel color so I can still see the bitmap ant the line I draw above it, How can I do that??? Thanks Not sure if I understand your question, but if you are trying to draw on top of your image simply do the following. In OnDraw(...) //First Draw your bitmap pDC->Bltbit(..) //Then Draw your line code or other GDI functions pDC->MoveTo(...) pDC->LineTo(...) Every time OnDraw(...) gets called it will refresh your image an...

hi, i actually want to display the bitmap image in picture box and does not wants its scope to be destroyed.i want to do this only in vc++6 and does not want to do with any third party can i do it? thanks a lot to Ajay kalra for a very great support given to this group. thanks in advance susi. CString szFilename ("D:\\abc2.bmp"); HBITMAP hBmp = (HBITMAP)::LoadImage( NULL, szFilename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION ); //pointer to a static...

Toolbar button without bitmap only text
Hello All I want to display only text in the tool bar buttons without bitmap how shall i do that Thanks in advace Faisal Try the following to your toolbar object: SendMessage(TB_SETIMAGELIST, 0, NULL); -- Ajay Kalra [MVP - VC++] "Faisal Masoor" <> wrote in message news:uOstAT7TEHA.2464@TK2MSFTNGP10.phx.gbl... > Hello All > > I want to display only text in the tool bar buttons without bitmap how shall > i do that > > Thanks in advace > Faisal > > Thanks Ajay But it didn't worked any more ideas Fa...

should i copy the bitmap header info when i wanna copy the bitmap data to global memory
now what i can get is the CBitmap, i wanna save it to global memory block ,so i can resuse it elsewhere, how could i achieve this? should i copy the bitmapheadinfo,and how??i can only get width, height info from CBitmap class Do you need the information in the bitmap header? joe On 6 Sep 2006 01:34:56 -0700, "thinktwice" <> wrote: >now what i can get is the CBitmap, i wanna save it to global memory >block ,so i can resuse it elsewhere, how could i achieve this? should i >copy the bitmapheadinfo,and how??i can only get width, height info fro...

Resize Photo Attachments in Outlook 2003
When I first installed Outlook 2003 whenever I sent photos as attachments it would give me the option to resize them to fit on a screen. Somehow this option has been turned off. How do I turn it back on as it is great when sending batches of photos. Cheers, Richard Do you have the image resizer PowerToy for Windows XP installed? --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the Swen virus, all e-mails sent to my actual account will be deleted w/out reading. After searching and finding no answer Blackshadow <ma...

bitmap caret
hi does anybody have an experience working with bitmapped window caret? there is a little problem. take a look at this code please. void CcntrlDlg::OnEnSetfocusEdit1() { CBitmap mbmp; mbmp.LoadBitmap(IDB_BITMAP1); mEdit.CreateCaret(&mbmp); mEdit.ShowCaret(); } the problem is it doesn't work!. system actually draws the bitmapped caret in a right position, but it isn't flashing. it works quite different from what we have when using solid or grey caret(created by CreateSolidCaret and CreateGrayCaret functions ). these two look just how they have to look with happy flashing and...

Resizing bitmap without losing quality (or a method to redraw the bitmap)
I have a 2d real time oscilloscope (a bitmap created with CDC CreateCompatibleDc and so on...). I need to resize to a bigger image and back to original size when the user click one of two button (like a zoom). I have tried with StretchBlt, but the image is very poor in quality. I can create a new bitmap of the desired size for perfect quality, but in this way a lose the graph that is displayed on first bitmap. Is it possible to resize the bitmap wihout losing too much or do something that allow me not to lose the 2d graph drawed on it? wrote: > I have a 2d real tim...

how do i put a transparent bitmap, such as a sprite, on the screen If the bitmap has a palette then you can use LoadMappedBitmap to replace any palette colour with any colour of your choosing but loading the bitmap frequently to re-map would be painfully expensive and, besides it would only work for a single, solid background colour. While that works well for putting transparency on bitmaps for a dialog box I think you'll have to do the logic yourself for a transparent bitmap on a background with multiple colours. If you think about doing it is quite easy. Create a monochrome mask of ...

I HAVE TWO EMPLOYEES SIGNATURE SCANNED AS A BITMAP IMAGE I WOULD LIKE TO FORMAT A SECTION OF A SPREAD SHEET SO THAT THEY CAN ENTER A CODE AND THE SPREAD SHEET WILL PLACE THIER SIGNATURE IN A CERTAIN LOCATION IS THAT POSSIBLE AND IF SO COULD YOU TELL WHAT TYPES OF COMMANDS I NEED TO USE Eli, Your Caps Lock key is stuck, and your period key doesn't seem to work. A macro will be required, I think, to accomplish this. Earl Kiosterud mvpearl omitthisword at verizon period net ------------------------------------------- "ELI WAGONER" <ELIWAGONER@ZANDE.COM> wrote in messa...

Pen created using ExtCreatePen fails to get selected into a metafile DC
Hello, In the OnDraw() function of my ActiveX control, I select a Pen as shown below. The constructor of CPen passes the parameters to create EMR_EXTCREATEPEN structure. ( ExtCreatePen also creates a similar structure) LOGBRUSH tmpLB; tmpLB.lbColor = COLORREF(RGB(0,0,0)); tmpLB.lbStyle = BS_SOLID; CPen tempPen(PS_GEOMETRIC|PS_DOT, 5, &tmpLB,0,NULL); pOldPen = (CPen*)pdc->SelectObject(&tempPen); VERIFY(pOldPen); pdc->Ellipse(rc); On Screen, the ellipse draws correctly with dots of width 5. But, On printing or drawing to a metafile DC , the ellipse is...

Resizing Picture
I am trying to resize a picture and it seems that nothing happens. I am using pixel dimension. Even though I change to 150 pixels and save it. The saved picture is 350 pixels. I have upgraded to sp3 what else can I do? Have you tried to resize the photo in something like Picture Manager first? -- JoAnn Paules MVP Microsoft [Publisher] Tech Editor for "Microsoft Publisher 2007 For Dummies" "Dale Gibble" <> wrote in message news:eszIc2i2IHA.2292@TK2MSFTNGP03.phx.gbl... >I am trying to resize a picture and it seems that nothing happens...

loading bitmap in dialog box
hello, I want to load a bitmap in dialog box.I inserted a picture control in the dialog box and and changed its id from IDC_STATIC to IDC_PICTURE.Actually i have created a led bitmap.I want to place it in the dialog box and then blink it to red and green clours using windows SetTimer function and OnTimer message handler.But i am not able to load bitmap itself ..I thnk i am not properly using the LoadBitmap function.Do we need to create some device context?what are other functions to be used and what are its steps? See the MSDN documentation for CStatic::SetBitmap -- Regar...

Converting a 24-bit bitmap (with 256 unique colors) to an 8-bit bitmap without changing the colors???
I carefully constructed a 24-bit bitmap to have exactly 256 unique colors. I converted this bitmap to use an optimized 8-bit palette retaining the exact same 256 colors using an image editor. I compared all of these images to the original using the BeyondCompare diff tool, they all has identical pixels. CImage image; image.Load("256colors.bmp"); // 24-bit image.Save("test.gif"); The colors now have been changed by several shades. To fix this I have to create my own color index table precisely defining the colors that I want to use, and then copy the ...

Save as bitmap
All: Need assistance on macro code to do the following: From a command button - copy a range from a worksheet (A1:D9), then save selection as a bitmap (picture) on the desktop. Thank you in advance. Hi, Try this : Modify sheet name and range address at your convenient. '-------------------------------------------- Sub Save_Range_On_Desktop() Application.ScreenUpdating = False With Sheets("Sheet1") .Activate Workbooks.Add .Range("A2:H31").CopyPicture End With With ActiveSheet .Paste With .ChartObjects.Add(0, 0, _ ...

Resizing dialog and controls #2
Hi, I have a dialog with a list control in it. I need to make the dialog resizable along with its contents. Appreciate if anyone points me to any samples on this. TIA, SD No sample needed. Change dialog’s style to resizable (properties, styles, border). If you want to move/resize all controls you would have to think about algorithm specific to a dialog layout and for the best effect (no flickering) use BeginDeferWindowPos, DeferWindowPos and EndDeferWindowPos. You can find information and samples in MSDN. -- RainMan "SD" wrote: > Hi, > > I have a dialog with...

Bitmap Not Displayed
A bitmap that appears in the MFC dialog editor does not display when the application runs. The property settings and ID are the same in the VS 2003 version and the VS 6 version. The VS 6 version works fine. It appears the update from VC++ 6 to VC++ 2003 has changed the mapping to the runtime bitmap file, but why does the bitmap picture appear (as it should) in the dialog editor, but not in the running version? The bitmap is labeled as a "system" bitmap, but this is a custom developed bitmap (lots of colors). Any clues to why the bitmap will not display and how to fix it? ...

Insert and resize Excel Object
When I insert an Excel spreadsheet object into Publisher 2007, the entire width of the spreadsheet as it appears in Excel does not appear in Publisher. When I double-click on the object and try to widen the borders in Excel to show all of the spreadhsheet's width, then go back to Publisher, the width hasn't changed in Publisher. It's as if the dimensions of the Publisher page (letter - portrait) constrain the size of the Excel object. What I would like to do is insert the entire Excel spreadsheet (which may be a tad wider than the letter sized page), then use the resize handl...

Rotating bitmaps, flicker free painting, SetWorldTransform function?
can i use the SetWorldTransform function to rotate a bitmap for flicker free painting? i want to rotate a bitmap for "real time" painting. thx. Hi, yes, you can use SetWorldTransform (NB: supported only for NT family platforms!) to draw bitmap with rotation. Just don't forget to call SetGraphicsMode(hDC, GM_ADVANCED) before applying world transformations. But flicker-free drawing is not concerned with geometric coordinates transformations. For performing flicker-free animation you should draw each frame on a memory DC, and then blit the ready picture on your window DC. -- WB...

Why doesn't show bitmap, when button is disable?
Hi, I set bitmap in default button. When button enable, button is display with bitmap. But when button disable then bitmap doesn't show in button and button is shown with another color. Here is my code: HBITMAP hbmp =::LoadBitmap(AfxGetInstanceHandle), MAKEINTRESOURCE(IDB_BITMAP_OK)); ::SendMessage(GetDlgItem(IDC_OK)->GetSafeHwnd(), BM_SETIMAGE, (WPARAM)IMAGE_BITMAP,(LPARAM) hbmp); hbmp = NULL; I also checked Bitmap option from button properties. My problem is that, I want to show button with bitmap when it is disable (same as when button is enable). Anybody can tall me, ho...

How to output bitmaps to a printer
Hello, How can I output graphics info like bitmap or jpg files (i.e. logos) on a printer device? I intended to use to CDC::BitBlt() function like the following code: void MyView::OnDraw(CDC* pDC) { CDC* dc = pDC; CBitmap myBitmap; myBitmap.LoadBitmap(IDB_BITMAP1); BITMAP bm; myBitmap.GetBitmap(&bm); // get information (size) of bitmap myBitmap.SetBitmapDimension(bm.bmWidth, bm.bmHeight); CBitmap* pbmOld = NULL; CDC dcMem; dcMem.CreateCompatibleDC(dc); int devCaps = pDC->GetDeviceCaps(RASTERCAPS); if (devCaps & RC_BITBLT) // check if device is capable of ra...

Triangular Bitmap
Hi, I want to draw a triagular bitmap into an MFC application. Is it possible to add non-rectangular bitmaps? Everything in windows is rectangular. But you can treat the area you don't want to paint as transparent (like the way an Icon is drawn). Take a look at TransparentBlt AliR. "hamishd" <> wrote in message > Hi, I want to draw a triagular bitmap into an MFC application. Is it > possible to add non-rectangular bitmaps? > There is also PlgBlt, although I'd think Tra...

Resize rows in a protected sheet
Hi there. I'm sending out a protected worksheet with some cells that the users can enter variable amounts of text. I've set the size so they can comfortably fit in about 50 words but I'd like them to have the flexibility to resize the row height when they're editing the worksheet. But because it's protected, they can't. Is there anyway I can allow them to change the row height dynamically? A button or something?? Andrew A workaround. Format the alignment in the cell to Wrap text. Users can Keep entering text or returns (ALT+ENTER) in the cell and it will aut...

Drawing a bitmap
Hello, I know this shouldn't be too difficult but it's causing me a lot of problems still. Basically I have a bitmap being drawn within a static frame (on a dialog), okay it draws fine. Now, I have a OnTimer function (which is firing every 1/2 second) and it calls the MyDialog::OnPaint() function. Problem is that even though this function is being called (I've checked using breakpoints) the screen does not update. However when I click onto another program (it totally looses focus) then click back onto the dialog it will finally update (redraw my bitamp and the point at the corre...

Is Resizing an Entourage window scriptable
I was just wondering if resizing an Entourage window is scriptable. I'd like to change it from one size on my sccreen to another. On 3/15/10 12:38 PM, Kerry wrote: > I was just wondering if resizing an Entourage window is scriptable. > I'd like to change it from one size on my sccreen to another. We discussed this a while back. One option is to use Keyboard Maestro to resize. See this screenshot: See this page for using Keyboard Maestro with Entourage: