Solved

OCX Control Draw Bitmap in OnDraw Function

Posted on 1998-03-03
3
508 Views
Last Modified: 2010-05-18
I am having trouble getting the bitmap to size to the borders of the selection rectangle in the container program when it is dropped on a form. I need it to remain a constant size even when the rcbounds sizes change?  Here is the code I currently have in the OnDraw Function of the Control.

CBitmap bitmap;
CDC dcDisplayMemory;

bitmap.LoadBitmap(IDB_BITMAP);
dcDisplayMemory.CreateCompatibleDC(pdc);
dcDisplayMemory.SelectObject(&bitmap);
pdc->BitBlt(rcBounds.left, rcBounds.top, rcBounds.left + 54, rcBounds.top + 96, &dcDisplayMemory, 0, 0, SRCCOPY);
      
0
Comment
Question by:wkroy
  • 2
3 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 20 total points
ID: 1182998
Use the following code.

BITMAP bm;
bitmap.GetBitmap(&bm);
pdc->BitBlt(rcBounds.left, rcBounds.top, bm.bmWidth, bm.bmHeight, &dcDisplayMemory, 0, 0, SRCCOPY);

Or, if you want it to be centered, you can calculate the upper-left corner.
0
 

Author Comment

by:wkroy
ID: 1182999
This is not really what I was looking for.  I was wanting to snap the objects height and width properties to the size of the bitmap
when it is dropped into the comtainer or the control is resized within the container. For example if you drop the Microsoft stock timer
control onto a VB form the control width and height properties size to the clock bitmap size and if it is strectched from the control points
larger than the size of the bitmap it snaps back to the bitmap's size.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1183000
I see.

You can call COleControl::SetInitialSize() in your control's constructor. In addition, you can override COleControl::OnSetExtent() and call COleControl::SetControlSize().
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now