Solved

Help! MFC Active Control driving me bonkers!

Posted on 1998-05-14
2
195 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
2 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 100 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hibernate methods 2 73
Explain Unit of Work pattern 2 63
Having a different time zone on your task bar 3 66
Need a complete list of ASP.NET page load events 3 47
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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…
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…

831 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