?
Solved

OCX Control Draw Bitmap in OnDraw Function

Posted on 1998-03-03
3
Medium Priority
?
529 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

765 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