Solved

OCX Control Draw Bitmap in OnDraw Function

Posted on 1998-03-03
3
515 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 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.

735 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