Solved

altering bitmap before display

Posted on 2002-04-10
7
337 Views
Last Modified: 2013-12-03
I load a bitmap resource
   hBitmap = LoadBitmap(hInst,MAKEINTRESOURCE(MY_BITMAP));
and would like to edit it before displaying it in a dialog box static picture control
     SendDlgItemMessage(hDlg,MY_PICTURE_CONTROL,STM_SETIMAGE,(WPARAM)IMAGE_BITMAP,(LPARAM)hBitmap);

I have tried creating a DC, selecting the bitmap into it, and doing some drawing, but the unchanged bitmap is always displayed in the control.
Thank You
0
Comment
Question by:Ignatz
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 22

Expert Comment

by:cookre
ID: 6932641
Doesn't painting to the DC effect only the image as displayed on that device and not the original bitmap selected into it?  And if you want to save the changes you have to create a new bitmap from the DC?
0
 
LVL 23

Expert Comment

by:chensu
ID: 6932726
It should work. Show your code please.
0
 

Author Comment

by:Ignatz
ID: 6933725
hBitmap = LoadBitmap(hInst,MAKEINTRESOURCE(MY_BITMAP));
GetObject(hBitmap,sizeof(BITMAP),&bmp);
hdcMem = CreateDC("DISPLAY","DISPLAY",NULL,NULL);
hOldBitmap = (HBITMAP)SelectObject(hdcMem,hBitmap);
rect.left = rect.top = 0;
rect.right = bmp.bmWidth;
rect.bottom = bmp.bmHeight;
hBrush = (HBRUSH)GetStockObject(BLACK_BRUSH);
FillRect(hdcMem,&rect,hBrush);
SendDlgItemMessage(hDlg,COLOR_EXAMPLE,STM_SETIMAGE,(WPARAM)IMAGE_BITMAP,(LPARAM)hBitmap);
SelectObject(hdcMem,hOldBitmap);
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 1

Accepted Solution

by:
Marsc earned 200 total points
ID: 6934259
Try hMemDC = CreateCompatibleDC (NULL);
I´ve allways used this function.
0
 

Author Comment

by:Ignatz
ID: 6934334
did the trick.
Thanks
0
 
LVL 1

Expert Comment

by:Marsc
ID: 6936819
Well... I am glad to having been helpfull....
Just to complete the answer a little.

NULL Should be another existing HDC
When you use NULL as a parameter, windows assumes the screen as DC.

I guess you was failing at the "SelectObject" line because there was No DC created.....
0
 
LVL 23

Expert Comment

by:chensu
ID: 6937468
Marsc> there was No DC created.....

CreateDC("DISPLAY","DISPLAY",NULL,NULL) creates a DC associated with the actual display device while CreateCompatibleDC(NULL) creates a memory DC, which is what you need.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wordpress limitations 4 136
Problem to packaging 1 112
GUI: DIalog Stacking and Popping in MS C++ 4 88
Windows ICD FFU Issue 4 90
This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

733 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