Microsoft KB Archive/88555

= How To Obtain Width and Height of a CBitmap Object =

Article ID: 88555

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft C/C++ Professional Development System 7.0

 Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 1.5 Professional Edition

 Microsoft Visual C++ 1.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 4.0 Standard Edition</li></ul>

 Microsoft Windows XP Home Edition</li></ul>

 Microsoft Windows XP Professional</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q88555

<div class="notice_section">

<div class="notice_section">

NOTE: Microsoft Visual C++ NET (2002) supported both the managed code model that is provided by the .NET Framework and the unmanaged native Windows code model. The information in this article applies to unmanaged Visual C++ code only.

<div class="summary_section">

SUMMARY
The CBitmap class provided by Microsoft Foundation Classes (MFC), does not contain member functions that return the width and height of a bitmap.

<div class="moreinformation_section">

MORE INFORMATION
The width and height of a CBitmap may be obtained by using the member function GetObject. GetObject can return a BITMAP structure that contains both the height and the width of the bitmap, along with some additional information.

The sample code below illustrates two functions that accept a CBitmap reference and return the width and height contained in the BITMAP structure returned by GetObject.

Sample Code
int GetCBitmapWidth(const CBitmap & cbm) {     BITMAP bm; cbm.GetObject(sizeof(BITMAP),&bm); return bm.bmWidth; }

int GetCBitmapHeight(const CBitmap & cbm) {     BITMAP bm; cbm.GetObject(sizeof(BITMAP),&bm); return bm.bmHeight; }

Additional query words: kbMFC

Keywords: kbhowto kbbitmap kbgdi KB88555

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.