Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

OCX Control Draw Bitmap in OnDraw Function

Posted on 1998-03-03
3
Medium Priority
?
536 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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 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.
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.
Suggested Courses

636 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