Jump to content
  • Advertisement
Sign in to follow this  
GetWindowRect

Question regarding images on windows.

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to display an image on a window to be more or less a background image. Currently in the WM_PAINT message, I am using stretchblt to show the image on the window as the whole background. The problem I am having is when I create controls on the window, the image is on top. I can still click the controls, but they do not display on the image unless clicked. How could I go about making the image stay in back, and all the controls can show in the foreground of the window. If code is required let me know and I can post it.

Share this post


Link to post
Share on other sites
Advertisement
If you just want to set a custom background you should be able to do it by processing the EM_ERASEBKGND message instead of WM_PAINT.

Share this post


Link to post
Share on other sites
I put my code into the WM_ERASEBKGND message, and now the window does not display at all. Could this be because of the value I set for the WNDCLASS' hbrBackground member?

The code I am using is

void OnEraseBackground()
{
PAINTSTRUCT ps;
HDC hdc, hdc2;
BITMAP bmp;

RECT rect;
GetClientRect(Handle(), &rect);
int height = rect.bottom - rect.top;
int width = rect.right - rect.left;

bmpImage = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BITMAP1), IMAGE_BITMAP, 0, 0,LR_COPYFROMRESOURCE);

hdc = GetDC(Handle());//BeginPaint(Handle(), &ps);
hdc2 = CreateCompatibleDC(hdc);

GetObject(bmpImage, sizeof(bmp), &bmp);
SelectObject(hdc2, bmpImage);

StretchBlt(hdc, 0, 0, width, height, hdc2, 0, 0, 48, 48, SRCCOPY);

ReleaseDC(Handle(), hdc);
DeleteDC(hdc2);
DeleteObject(bmpImage);
}



I am just learning how to display images, so code is probably not perfect. But with this message handler the image never displays.

Share this post


Link to post
Share on other sites
Any ideas on what I could be doing wrong? I have a window class, in my window class I call the OnEraseBackground function in the WM_ERASEBKGND message. Handle() returns the windows HWND, everything else should be pretty self explanitory. If I call the same method in OnPaint() it works with the exception stated in my first post.

Thanks in advance

Share this post


Link to post
Share on other sites
I appear to have found a solution for the problem. In my code I have a funcion that colors the window with the color specified with my BackColor function.

The code to color my window is as follows:

HDC hdc;
RECT rect;
HBRUSH brush;

GetClientRect(Handle(), &rect);

hdc = GetDC(Handle());
brush = CreateSolidBrush(RGB(m_Red, m_Green, m_Blue));
FillRect(hdc, &rect, brush);
DeleteObject(brush);
ReleaseDC(Handle(), hdc);

RedrawWindow(Handle(), NULL, NULL, RDW_UPDATENOW);



m_Red, m_Green and m_Blue are member variables that hold the color code for each color.

My new problem is, the image drawing only displays correctly when that is called, and I have no idea how I could go about changing the color of a window without the function I used. I had a guess that I could change the hbrBackground in the WNDCLASSEX, but from what I have read, changing that only helps on new windows that get created, not on windows that are currently created.

Is there a way I could go about changing the color of a window already created in another way than what I am currently using?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!