|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
||||
|
||||
|
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
}
|
|
#2
|
||||
|
||||
|
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). |
|
#3
|
||||
|
||||
|
I hate to be rude, unless that's really the problem then your comment is unwanted/rude/unappreciated.
|
|
#4
|
|||
|
|||
|
I also want to know.
|
|
#5
|
||||
|
||||
|
Quote:
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 |
|
#6
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Displaying Images in a Window + Win32 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|