?
Solved

Help! MFC Active Control driving me bonkers!

Posted on 1998-05-14
2
Medium Priority
?
207 Views
Last Modified: 2013-11-25
It's a simple problem, but the answer eludes me. I have tried some methods but I've had NO success. So I'm BEGGING for someone to help me on this! :)
How do you find out the Width and Height of a bitmap object in an Active X control?? The only way it appears you can access the information it through the GetPictureDispatch function in CPictureHolder. This is what I've tried so far..

//Else draw it in Bitmap's Length and Width
LPPICTURE pPict = NULL;
LPPICTUREDISP pPictDisp = m_cPicHolder.GetPictureDispatch();

if ((pPictDisp != NULL) && 
SUCCEEDED(pPictDisp->QueryInterface(IID_IPicture, (LPVOID*)&pPict)))
{
ASSERT(pPict != NULL);

OLE_XSIZE_HIMETRIC hmWidth;
OLE_YSIZE_HIMETRIC hmHeight;

pPict->get_Width(&hmWidth);
pPict->get_Height(&hmHeight);
rect = rcBounds;
rect.right = rect.left + hmWidth;
rect.bottom = rect.top + hmHeight;
m_cPicHolder.Render(pdc, rect, rcBounds);
pPict->Release();
// Added in for DEBUG
char buffer[20];
_itoa( hmWidth, buffer, 10 );
CString debugStr(buffer);
pdc->ExtTextOut(rect.left, (rect.top + rect.bottom)/2, ETO_CLIPPED, rect, debugStr, debugStr.GetLength(), NULL);
// End DEBUG

and of course it FAILS miserably! Gives me some outrageous numbers for the width and height. Please, someone please explain to me what the story is here!
Thanks :)

RickMan
0
Comment
Question by:rickmanx
[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 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 400 total points
ID: 1311126
Try this
HBITMAP hBitmap;
pPict->get_Handle((OLE_HANDLE *)&hBitmap);

BITMAP bm;
::GetObject(hBitmap, sizeof(bm), &bm);

int nWidth = bm.bmWidth;
int nHeight = bm.bmHeight;
0
 

Author Comment

by:rickmanx
ID: 1311127
I couldn't rest easy till I found out! It works perfectly! Thanks a bunch!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

764 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