C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old May 2nd, 2008, 05:33 PM
bobber205's Avatar
bobber205 bobber205 is offline
Career Newbie
Dev Shed Novice (500 - 999 posts)
 
Join Date: Dec 2005
Location: Klamath Falls, Oregon
Posts: 628 bobber205 User rank is Corporal (100 - 500 Reputation Level)bobber205 User rank is Corporal (100 - 500 Reputation Level)bobber205 User rank is Corporal (100 - 500 Reputation Level)bobber205 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 5 Days 9 h 7 m 40 sec
Reputation Power: 5
Send a message via AIM to bobber205 Send a message via Yahoo to bobber205
Displaying Images in a Window + Win32

Code is at end of post. I have a picture box control with type Bitmap on my control as position 0,0. I basically want a window where it just displays an image.
However with the current code below, I am unable to get the image to not "be covered up". If I take another window and cover up MY window and then move away, I can then see the image as I desire.

However this is not desired behavior. I have a function commented out called RepaintWindow. It's one of my custom functions. It gets the client rect of the window and calls invalidaterect for that section. A shortcut.

When that is not commented out, I get to see my image (again when moving another window onto MY window) for a brief second then it gets covered by up by gray again.

I am missing a small detail here and by god if I can't see what that is! Thanks for the help.

Code:
	case WM_PAINT:
		{

				if(firstTime)
				{
					
					
					if(status == Gdiplus::Ok)
					{
						HWND staticwindow = GetDlgItem(hwnd,IDC_STATIC);
						HDC dc = GetDC(staticwindow);
						
						const int size = ad.message.size();
						char* placeholder = new char[size+1];
						strcpy(placeholder,ad.message.c_str());

						placeholder[size+1] = '\0';
						
						WCHAR temp[100];
						mbstowcs(temp, placeholder, size+1);
						
						Gdiplus::Bitmap srcBitmap(temp, FALSE);
						Gdiplus::Graphics wndGraphics(dc);

						Gdiplus::SizeF SIZE;
						srcBitmap.GetPhysicalDimension(&SIZE);

						int height = SIZE.Height;
						int width = SIZE.Width;

						wndGraphics.DrawImage(&srcBitmap, 0, 0);
						
						SetWindowPos(hwnd,HWND_BOTTOM,0,0,width,height,SWP_NOMOVE |SWP_NOZORDER );
						SetWindowPos(staticwindow,HWND_BOTTOM,0,0,width,height,SWP_NOMOVE );

						//SetWindowPos(hwnd,GetParent(hwnd),0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
					

						
						//RepaintWindow(hwnd);
					
						
						
						firstTime = true;
						
						//Gdiplus::GdiplusShutdown(dwToken);
						
					}//C:\\Documents and Settings\\Alex\\My Documents\\My Pictures\alex.jpg

				}

Reply With Quote
  #2  
Old May 2nd, 2008, 05:55 PM
sizablegrin's Avatar
sizablegrin sizablegrin is offline
Stubborn ol' L'User
Click here for more information.
 
Join Date: Jun 2005
Posts: 3,070 sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 16 h 10 m 4 sec
Reputation Power: 1446
Your tabs are too large. That makes the repaint take place in the next room.
__________________
C/C++ pointers (Original in the "Commonly Asked Questions" thread).

Reply With Quote
  #3  
Old May 2nd, 2008, 06:41 PM
bobber205's Avatar
bobber205 bobber205 is offline
Career Newbie
Dev Shed Novice (500 - 999 posts)
 
Join Date: Dec 2005
Location: Klamath Falls, Oregon
Posts: 628 bobber205 User rank is Corporal (100 - 500 Reputation Level)bobber205 User rank is Corporal (100 - 500 Reputation Level)bobber205 User rank is Corporal (100 - 500 Reputation Level)bobber205 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 5 Days 9 h 7 m 40 sec
Reputation Power: 5
Send a message via AIM to bobber205 Send a message via Yahoo to bobber205
I hate to be rude, unless that's really the problem then your comment is unwanted/rude/unappreciated.
Comments on this post
sizablegrin disagrees: We're even. Your presentation is unappreciated. Code tags are great, but their benefits can be
overridden my unintelligent usage.

Reply With Quote
  #4  
Old May 5th, 2008, 05:27 AM
Peter_APIIT Peter_APIIT is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 22 Peter_APIIT Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 40 m 10 sec
Reputation Power: 0
I also want to know.

Reply With Quote
  #5  
Old May 5th, 2008, 06:13 AM
clifford's Avatar
clifford clifford is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: UK
Posts: 2,413 clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 6 h 28 m 42 sec
Reputation Power: 320
Quote:
Originally Posted by bobber205
I hate to be rude, unless that's really the problem then your comment is unwanted/rude/unappreciated.
Yes it really is a problem. If you want people to take the time to study your code, you have to make it easy - that way it gets more eyes on it. I see code like that and think; "move on, I cannot be bothered". The problem is the use of hard tabs - you have no control over how they are rendered and the browser renders them as it sees fit (generally eight spaces wide). Most editors have an option to use spaces instead of hard tabs, then you have control direct over how the code looks to readers.

It could be worse. Often code is posted as a mixed spaces and hard tabs, and then the indentation gets really messed up.

Moving a window over yours causes the area to be invalidated, which causes a WM_PAINT message. Presumably is you force a WM_PAINT message by invalidating the area, you will get teh bitmap drawn?

Clifford

Reply With Quote
  #6  
Old May 6th, 2008, 05:37 AM
SimonB2 SimonB2 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 7 SimonB2 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 3 h 47 m 58 sec
Reputation Power: 0
The first thing that comes to mind, is that I can't see a return value from this function. WM_PAINT messages handled by the user should result in 0 being returned.

Further to that, I noticed you say that if you invalidate the rect to get the bitmap drawn, it works fine for a brief second, then again the grey background is shown. So, have you tried Painting the bitmap, invalidating the rect to ensure it is shown, before validating the rect to prevent windows from redrawing the window's background?

Also, I can't tell where/what firstTime is initialized to, nor where it's changed to false. I assume you're calling wndGraphics.DrawImage(&srcBitmap, 0, 0) each and every time you receive the WM_PAINT message.

I also notice, that you appear to be loading the bitmap in your WM_PAINT function - this is generally not the way it's done, most commonly, the bitmap loaded when the WM_CREATE message is received by your window - or when the WM_INITDIALOG message is received if the bitmap window exists as a static control on a dialog. A pointer is kept to the bitmap, which is then released from memory when the WM_CLOSE message is received.


As for the hard/soft tabs issue - try heading over to w_w.CodeProject.com (over 5 million members, ~15,000 online at any one time) Post a link then see what happens to what you pasted in - much the same as the link filtering that happens here - adding the ability to filter and convert hard-tabs to spaces is easy (if indeed the aim is ease of use, as opposed to finding punching-bags)


[EDIT]: Another approach would be to use the automatic redrawing of windows to your advantage. How? Well, if you create your own windows class, you can specify a HBRUSH that will be used for the background.
So, if you load the bitmap and then create a brush from it, you can then tell your window that this bitmap brush is to be used to paint it's background.
Here's a great example I found a while ago:

Code:
#include <windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
    static TCHAR szAppName [] = TEXT ("myAppName") ;
    HBITMAP hBitmap ;
    HBRUSH hBrush ;
    HWND hwnd ;
    MSG msg ;
    WNDCLASS wndclass ;
    hBitmap = LoadBitmap (hInstance, TEXT ("ResourceName")) ;
    hBrush = CreatePatternBrush (hBitmap) ;
    DeleteObject (hBitmap) ;
    wndclass.style = CS_HREDRAW | CS_VREDRAW ;
    wndclass.lpfnWndProc = WndProc ;
    wndclass.cbClsExtra = 0 ;
    wndclass.cbWndExtra = 0 ;
    wndclass.hInstance = hInstance ;
    wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
    wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
    wndclass.hbrBackground = hBrush ;
    wndclass.lpszMenuName = NULL ;
    wndclass.lpszClassName = szAppName ;
    if (!RegisterClass (&wndclass))
    {
        MessageBox (NULL, TEXT ("Window Class registration failed!"),
        szAppName, MB_ICONERROR) ;
        return 0 ;
    }
    hwnd = CreateWindow (szAppName, TEXT ("using Bitmap as background demo"),
    WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT,
    CW_USEDEFAULT, CW_USEDEFAULT,
    NULL, NULL, hInstance, NULL) ;
    ShowWindow (hwnd, iCmdShow) ;
    UpdateWindow (hwnd) ;
    while (GetMessage (&msg, NULL, 0, 0))
    {
        TranslateMessage (&msg) ;
        DispatchMessage (&msg) ;
    }
    DeleteObject (hBrush) ;
    return msg.wParam ;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch (msg)
    {
        case WM_DESTROY:
            PostQuitMessage (0) ;
            return 0 ;
    }
    return DefWindowProc (hwnd, msg, wParam, lParam) ;
}

----------myAppName.rc (excerpts)----------------------
//Microsoft Developer Studio generated resource script.
#include "resource.h"
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
// Bitmap
ResourceName BITMAP DISCARDABLE "fileName.bmp"

Last edited by SimonB2 : May 6th, 2008 at 11:52 AM. Reason: remembered a workable solution

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Displaying Images in a Window + Win32


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway