Solved

OCX Control Draw Bitmap in OnDraw Function

Posted on 1998-03-03
3
503 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

762 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

13 Experts available now in Live!

Get 1:1 Help Now