Author: cwittich
Date: Tue Jan 27 11:14:00 2009
New Revision: 39140
URL:
http://svn.reactos.org/svn/reactos?rev=39140&view=rev
Log:
-don't load the image in WM_PAINT
-return the correct values when handling a window message
-free resources
-...
Modified:
trunk/reactos/dll/win32/shimgvw/shimgvw.c
Modified: trunk/reactos/dll/win32/shimgvw/shimgvw.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shimgvw/shimgvw.…
==============================================================================
--- trunk/reactos/dll/win32/shimgvw/shimgvw.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/shimgvw/shimgvw.c [iso-8859-1] Tue Jan 27 11:14:00 2009
@@ -24,7 +24,8 @@
HINSTANCE hInstance;
SHIMGVW_SETTINGS shiSettings;
-WCHAR szOpenFileName[MAX_PATH];
+GpImage *image;
+WNDPROC PrevProc = NULL;
HWND hDispWnd, hToolBar;
@@ -44,23 +45,31 @@
{TBICON_PRINT, IDC_PRINT, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0},
};
+static void pLoadImage(LPWSTR szOpenFileName)
+{
+ if (GetFileAttributesW(szOpenFileName) == 0xFFFFFFFF)
+ {
+ DPRINT1("File %s not found!\n", szOpenFileName);
+ return;
+ }
+
+ GdipLoadImageFromFile(szOpenFileName, &image);
+ if (!image)
+ {
+ DPRINT1("GdipLoadImageFromFile() failed\n");
+ }
+}
+
static VOID
ImageView_DrawImage(HWND hwnd)
{
GpGraphics *graphics;
- GpImage *image;
UINT uImgWidth, uImgHeight;
UINT height = 0, width = 0, x = 0, y = 0;
PAINTSTRUCT ps;
RECT rect;
HDC hdc;
- if (GetFileAttributesW(szOpenFileName) == 0xFFFFFFFF)
- {
- DPRINT1("File %s not found!\n", szOpenFileName);
- return;
- }
-
hdc = BeginPaint(hwnd, &ps);
if (!hdc)
{
@@ -74,20 +83,13 @@
DPRINT1("GdipCreateFromHDC() failed\n");
return;
}
-
- GdipLoadImageFromFile(szOpenFileName, &image);
- if (!image)
- {
- DPRINT1("GdipLoadImageFromFile() failed\n");
- return;
- }
-
+
GdipGetImageWidth(image, &uImgWidth);
GdipGetImageHeight(image, &uImgHeight);
if (GetClientRect(hwnd, &rect))
{
- FillRect(hdc, &rect, (HBRUSH)COLOR_WINDOW);
+ FillRect(hdc, &rect, (HBRUSH)GetStockObject(WHITE_BRUSH));
if ((rect.right == uImgWidth)&&(rect.bottom == uImgHeight))
{
@@ -152,7 +154,7 @@
DPRINT("x = %d\ny = %d\nWidth = %d\nHeight = %d\n\nrect.right =
%d\nrect.bottom = %d\n\nuImgWidth = %d\nuImgHeight = %d\n", x, y, width, height,
rect.right, rect.bottom, uImgWidth, uImgHeight);
GdipDrawImageRect(graphics, image, x, y, width, height);
}
-
+ GdipDeleteGraphics(graphics);
EndPaint(hwnd, &ps);
}
@@ -260,6 +262,20 @@
return FALSE;
}
+LRESULT CALLBACK
+ImageView_DispWndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
+{
+ switch (Message)
+ {
+ case WM_PAINT:
+ {
+ ImageView_DrawImage(hwnd);
+ return 0L;
+ }
+ }
+ return CallWindowProc(PrevProc, hwnd, Message, wParam, lParam);
+}
+
static VOID
ImageView_InitControls(HWND hwnd)
{
@@ -269,10 +285,13 @@
if (shiSettings.Maximized) ShowWindow(hwnd, SW_MAXIMIZE);
- hDispWnd = CreateWindowEx(WS_EX_TRANSPARENT, _T("STATIC"),
_T(""),
+ hDispWnd = CreateWindowEx(0, _T("STATIC"), _T(""),
WS_CHILD | WS_VISIBLE,
0, 0, 0, 0, hwnd, NULL, hInstance, NULL);
+ SetClassLong(hDispWnd, GCL_STYLE, CS_HREDRAW | CS_VREDRAW);
+ PrevProc = (WNDPROC) SetWindowLong(hDispWnd, GWL_WNDPROC, (LPARAM)
ImageView_DispWndProc);
+
ImageView_CreateToolBar(hwnd);
}
@@ -284,9 +303,8 @@
case WM_CREATE:
{
ImageView_InitControls(hwnd);
- }
- break;
-
+ return 0L;
+ }
case WM_COMMAND:
{
switch (wParam)
@@ -362,15 +380,8 @@
}
}
}
- }
- break;
-
- case WM_PAINT:
- {
- ImageView_DrawImage(hDispWnd);
- }
- break;
-
+ break;
+ }
case WM_SIZING:
{
LPRECT pRect = (LPRECT)lParam;
@@ -379,22 +390,21 @@
if (pRect->bottom-pRect->top < 290)
pRect->bottom = pRect->top + 290;
- }
- break;
-
+ return TRUE;
+ }
case WM_SIZE:
{
MoveWindow(hDispWnd, 1, 1, LOWORD(lParam)-1, HIWORD(lParam)-35, TRUE);
SendMessage(hToolBar, TB_AUTOSIZE, 0, 0);
- }
- break;
-
+ return 0L;
+ }
case WM_DESTROY:
{
ImageView_SaveSettings(hwnd);
+ SetWindowLong(hDispWnd, GWL_WNDPROC, (LPARAM) PrevProc);
PostQuitMessage(0);
- }
- break;
+ break;
+ }
}
return DefWindowProc(hwnd, Message, wParam, lParam);
@@ -410,8 +420,6 @@
HWND hMainWnd;
MSG msg;
- wcscpy(szOpenFileName, szFileName);
-
if (!ImageView_LoadSettings())
{
shiSettings.Maximized = FALSE;
@@ -428,6 +436,7 @@
gdiplusStartupInput.SuppressExternalCodecs = 0;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
+ pLoadImage(szFileName);
// Create the window
WndClass.lpszClassName = _T("shimgvw_window");
@@ -442,7 +451,7 @@
LoadString(hInstance, IDS_APPTITLE, szBuf, sizeof(szBuf) / sizeof(TCHAR));
hMainWnd = CreateWindow(_T("shimgvw_window"), szBuf,
- WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_VISIBLE |
WS_CAPTION,
+ WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CAPTION,
CW_USEDEFAULT, CW_USEDEFAULT,
0, 0, NULL, NULL, hInstance, NULL);
@@ -457,6 +466,8 @@
DispatchMessageW(&msg);
}
+ if (image)
+ GdipDisposeImage(image);
GdiplusShutdown(gdiplusToken);
return -1;
}