Click here to Skip to main content
16,006,001 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: string question Pin
Anonymous10-Oct-02 9:19
Anonymous10-Oct-02 9:19 
GeneralRe: string question Pin
Shog910-Oct-02 9:08
sitebuilderShog910-Oct-02 9:08 
GeneralRe: string question Pin
valikac10-Oct-02 13:12
valikac10-Oct-02 13:12 
QuestionSetup works fine as admin, but no one else? Pin
paulccc10-Oct-02 8:24
paulccc10-Oct-02 8:24 
AnswerRe: Setup works fine as admin, but no one else? Pin
Anonymous10-Oct-02 8:59
Anonymous10-Oct-02 8:59 
GeneralBitmap Problems Pin
Mike Savoie10-Oct-02 8:26
Mike Savoie10-Oct-02 8:26 
GeneralRe: Bitmap Problems Pin
Joe Woodbury10-Oct-02 8:58
professionalJoe Woodbury10-Oct-02 8:58 
GeneralRe: Bitmap Problems Pin
Paul M Watt10-Oct-02 9:22
mentorPaul M Watt10-Oct-02 9:22 
What you need to do is use a MemoryDC. A memory DC is simply located in memory. You will need to use a DC because that is how you manipulate bitmaps in windows.

First load the image into a CBitmap object with ::LoadImage(...).

Then you will need to create a MemoryDC, however in order to create a memory DC, you first need to have a DC to a window in order to properly set the color bits. If you are going to display this to a particular window, then use GetDC(hwnd) for the window that you will use, or you can use GetDC(NULL) to get the Desktop DC.

if you have a handle to your window hwnd, this is how you would create your memory DC and associate the bitmap with your DC.

<br />
CWindowDC dc(hwnd);<br />
CDC memDC;<br />
memDC.CreateCompatibleDC(dc);<br />
<br />
CBitmap bmp;<br />
bmp.LoadBitmap("C:\\winnt\\bubbles.bmp");<br />
<br />
memDC.SelectObject(bmp);<br />


At this point you will have your bitmap selected into a memory DC and you can start manipulating it. If you want to paste all or just a portion of this bitmap to a window then you can use the BitBlt function of the CDC class.

If you want to create another bitmap that is a cropped portion of your original image, you will first need to create a second Memory DC ans select a bitmap into it that is the size that you desire.

<br />
CDC memCropDC;<br />
memCropDC.CreateCompatibleDC(memDC);<br />
// get the size and color settings of the original bitmap.<br />
BITMAP bm;<br />
bmp.GetBitmap(&bm);<br />
//reset the dimensions (width and height) of hte bitmap.  Lets make it 50% smaller in width.<br />
bm.bmWidth = bm.bmWidth / 2;<br />
<br />
CBitmap bmpCrop;<br />
bmpCrop.CreateBitmapIndirect(&bm);<br />
//C: Select your cropped bitmap into the cropped memDC.<br />
memCropDC.SelectObject(bmpCrop);<br />


Now you can use bit blt to copy a small portion of the original bitmap into the new smaller cropped image. Here are three examples of how you can copy the bitmap.

<br />
// this code will copy the left half of the image into your cropped image.<br />
memCropDC.BitBlt(0, 0, bm.bmWidth, bm.bmheight, &memDC, 0, 0, SRCCOPY);<br />
// this code will copy the right half of the image into your cropped image.<br />
memCropDC.BitBlt(0, 0, bm.bmWidth, bm.bmheight, &memDC, bm.bmWidth, 0, SRCCOPY);<br />
// this code will copy the middle half of the image into your cropped image.<br />
memCropDC.BitBlt(0, 0, bm.bmWidth, bm.bmheight, &memDC, bm.bmWidth / 2, 0, SRCCOPY);<br />



If you look on code project there should be a few examples of how to manipulate bitmaps with memory DCs.

Good Luck


Build a man a fire, and he will be warm for a day
Light a man on fire, and he will be warm for the rest of his life!

GeneralRe: Bitmap Problems Pin
Mike Savoie11-Oct-02 1:50
Mike Savoie11-Oct-02 1:50 
GeneralRe: Bitmap Problems Pin
Atlantys21-Oct-02 7:56
Atlantys21-Oct-02 7:56 
GeneralI'm Confused... Pin
JohnnyG10-Oct-02 7:48
JohnnyG10-Oct-02 7:48 
GeneralRe: I'm Confused... Pin
Carlos Antollini10-Oct-02 8:02
Carlos Antollini10-Oct-02 8:02 
GeneralRe: I'm Confused... Pin
JohnnyG10-Oct-02 8:32
JohnnyG10-Oct-02 8:32 
GeneralRe: I'm Confused... Pin
Stephane Rodriguez.10-Oct-02 8:06
Stephane Rodriguez.10-Oct-02 8:06 
GeneralRe: I'm Confused... Pin
JohnnyG10-Oct-02 9:15
JohnnyG10-Oct-02 9:15 
GeneralRe: I'm Confused... Pin
Ranjan Banerji10-Oct-02 8:10
Ranjan Banerji10-Oct-02 8:10 
GeneralRe: I'm Confused... Pin
JohnnyG10-Oct-02 8:35
JohnnyG10-Oct-02 8:35 
GeneralRe: I'm Confused... Pin
Stephane Rodriguez.10-Oct-02 9:07
Stephane Rodriguez.10-Oct-02 9:07 
GeneralRe: I'm Confused... Pin
JohnnyG10-Oct-02 9:52
JohnnyG10-Oct-02 9:52 
GeneralRe: I'm Confused... Pin
Gary R. Wheeler10-Oct-02 14:56
Gary R. Wheeler10-Oct-02 14:56 
Generalsplash screen Pin
ns10-Oct-02 7:41
ns10-Oct-02 7:41 
GeneralRe: splash screen Pin
jmkhael10-Oct-02 7:48
jmkhael10-Oct-02 7:48 
GeneralRe: splash screen Pin
ns10-Oct-02 8:05
ns10-Oct-02 8:05 
GeneralRe: splash screen Pin
Stephane Rodriguez.10-Oct-02 8:07
Stephane Rodriguez.10-Oct-02 8:07 
Generalthanks for the link Pin
ns10-Oct-02 8:17
ns10-Oct-02 8:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.