[SHIMGVW] Some minor refactoring (#6139)

Improve human readability. Reduce code amount.
CORE-19358
This commit is contained in:
Katayama Hirofumi MZ 2023-12-10 08:20:17 +09:00 committed by GitHub
parent 8be912147b
commit 5a2c451696
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -11,8 +11,6 @@
#define COM_NO_WINDOWS_H #define COM_NO_WINDOWS_H
#define INITGUID #define INITGUID
#include <stdarg.h>
#include <windef.h> #include <windef.h>
#include <winbase.h> #include <winbase.h>
#include <winnls.h> #include <winnls.h>
@ -24,7 +22,6 @@
#include <commctrl.h> #include <commctrl.h>
#include <commdlg.h> #include <commdlg.h>
#include <gdiplus.h> #include <gdiplus.h>
#include <tchar.h>
#include <shlobj.h> #include <shlobj.h>
#include <strsafe.h> #include <strsafe.h>
#include <shlwapi.h> #include <shlwapi.h>
@ -66,7 +63,7 @@ typedef struct {
{ TBICON_##_name, IDC_##_name, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 } { TBICON_##_name, IDC_##_name, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0 }
#define DEFINE_BTN_SEPARATOR \ #define DEFINE_BTN_SEPARATOR \
{ 15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0 } { -1, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0 }
/* ToolBar Buttons */ /* ToolBar Buttons */
static const TBBUTTON s_Buttons[] = static const TBBUTTON s_Buttons[] =
@ -136,11 +133,9 @@ static void Anime_FreeInfo(void)
static BOOL Anime_LoadInfo(void) static BOOL Anime_LoadInfo(void)
{ {
GUID *dims;
UINT nDimCount = 0; UINT nDimCount = 0;
UINT cbItem; UINT cbItem;
UINT result; UINT result;
PropertyItem *pItem;
Anime_FreeInfo(); Anime_FreeInfo();
KillTimer(g_hDispWnd, ANIME_TIMER_ID); KillTimer(g_hDispWnd, ANIME_TIMER_ID);
@ -151,7 +146,7 @@ static BOOL Anime_LoadInfo(void)
GdipImageGetFrameDimensionsCount(g_pImage, &nDimCount); GdipImageGetFrameDimensionsCount(g_pImage, &nDimCount);
if (nDimCount) if (nDimCount)
{ {
dims = (GUID *)calloc(nDimCount, sizeof(GUID)); GUID *dims = (GUID *)calloc(nDimCount, sizeof(GUID));
if (dims) if (dims)
{ {
GdipImageGetFrameDimensionsList(g_pImage, dims, nDimCount); GdipImageGetFrameDimensionsList(g_pImage, dims, nDimCount);
@ -175,7 +170,7 @@ static BOOL Anime_LoadInfo(void)
cbItem = result; cbItem = result;
if (cbItem) if (cbItem)
{ {
pItem = (PropertyItem *)malloc(cbItem); PropertyItem *pItem = (PropertyItem *)malloc(cbItem);
if (pItem) if (pItem)
{ {
if (GdipGetPropertyItem(g_pImage, PropertyTagLoopCount, cbItem, pItem) == Ok) if (GdipGetPropertyItem(g_pImage, PropertyTagLoopCount, cbItem, pItem) == Ok)
@ -254,27 +249,17 @@ static void UpdateZoom(UINT NewZoom, BOOL bEnableBestFit, BOOL bEnableRealSize)
s_nZoomPercents = NewZoom; s_nZoomPercents = NewZoom;
/* Check if a zoom button of the toolbar must be grayed */ /* Check if a zoom button of the toolbar must be grayed */
bEnableZoomIn = bEnableZoomOut = TRUE; bEnableZoomIn = (NewZoom < MAX_ZOOM);
bEnableZoomOut = (NewZoom > MIN_ZOOM);
if (NewZoom >= MAX_ZOOM) /* Update toolbar buttons */
{
bEnableZoomIn = FALSE;
}
else if (NewZoom <= MIN_ZOOM)
{
bEnableZoomOut = FALSE;
}
/* Update the state of the zoom buttons */
SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_ZOOM_OUT, bEnableZoomOut); SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_ZOOM_OUT, bEnableZoomOut);
SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_ZOOM_IN, bEnableZoomIn); SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_ZOOM_IN, bEnableZoomIn);
SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_BEST_FIT, bEnableBestFit);
SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_REAL_SIZE, bEnableRealSize);
/* Redraw the display window */ /* Redraw the display window */
InvalidateRect(g_hDispWnd, NULL, FALSE); InvalidateRect(g_hDispWnd, NULL, FALSE);
/* Update toolbar buttons */
SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_BEST_FIT, bEnableBestFit);
SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_REAL_SIZE, bEnableRealSize);
} }
static void ZoomInOrOut(BOOL bZoomIn) static void ZoomInOrOut(BOOL bZoomIn)
@ -292,10 +277,7 @@ static void ZoomInOrOut(BOOL bZoomIn)
if (s_nZoomPercents < s_ZoomSteps[i]) if (s_nZoomPercents < s_ZoomSteps[i])
break; break;
} }
if (i == _countof(s_ZoomSteps)) NewZoom = ((i >= _countof(s_ZoomSteps)) ? MAX_ZOOM : s_ZoomSteps[i]);
NewZoom = MAX_ZOOM;
else
NewZoom = s_ZoomSteps[i];
} }
else /* zoom out */ else /* zoom out */
{ {
@ -306,10 +288,7 @@ static void ZoomInOrOut(BOOL bZoomIn)
if (s_ZoomSteps[i] < s_nZoomPercents) if (s_ZoomSteps[i] < s_nZoomPercents)
break; break;
} }
if (i < 0) NewZoom = ((i < 0) ? MIN_ZOOM : s_ZoomSteps[i]);
NewZoom = MIN_ZOOM;
else
NewZoom = s_ZoomSteps[i];
} }
/* Update toolbar and refresh screen */ /* Update toolbar and refresh screen */
@ -534,8 +513,7 @@ pLoadImageFromNode(SHIMGVW_FILENODE *node, HWND hwnd)
pchFileTitle = PathFindFileNameW(node->FileName); pchFileTitle = PathFindFileNameW(node->FileName);
if (pchFileTitle && *pchFileTitle) if (pchFileTitle && *pchFileTitle)
{ {
StringCbPrintfW(szTitleBuf, sizeof(szTitleBuf), StringCbPrintfW(szTitleBuf, sizeof(szTitleBuf), L"%ls - %ls", szResStr, pchFileTitle);
L"%ls%ls%ls", szResStr, L" - ", pchFileTitle);
SetWindowTextW(hwnd, szTitleBuf); SetWindowTextW(hwnd, szTitleBuf);
} }
else else
@ -607,7 +585,7 @@ pBuildFileList(LPWSTR szFirstFile)
// compare the name of the requested file with the one currently found. // compare the name of the requested file with the one currently found.
// if the name matches, the current node is returned by the function. // if the name matches, the current node is returned by the function.
if (wcscmp(szFirstFile, conductor->FileName) == 0) if (_wcsicmp(szFirstFile, conductor->FileName) == 0)
{ {
currentNode = conductor; currentNode = conductor;
} }
@ -681,13 +659,6 @@ pFreeFileList(SHIMGVW_FILENODE *root)
} }
} }
static VOID
ImageView_UpdateWindow(HWND hwnd)
{
InvalidateRect(hwnd, NULL, FALSE);
UpdateWindow(hwnd);
}
static HBRUSH CreateCheckerBoardBrush(HDC hdc) static HBRUSH CreateCheckerBoardBrush(HDC hdc)
{ {
static const CHAR pattern[] = static const CHAR pattern[] =
@ -823,28 +794,41 @@ ImageView_DrawImage(HWND hwnd)
EndPaint(hwnd, &ps); EndPaint(hwnd, &ps);
} }
static BOOL static VOID
ImageView_LoadSettings(VOID) ImageView_ResetSettings(VOID)
{ {
HKEY hKey;
DWORD dwSize;
LONG nError;
g_Settings.Maximized = FALSE; g_Settings.Maximized = FALSE;
g_Settings.X = CW_USEDEFAULT; g_Settings.X = CW_USEDEFAULT;
g_Settings.Y = CW_USEDEFAULT; g_Settings.Y = CW_USEDEFAULT;
g_Settings.Width = 520; g_Settings.Width = 520;
g_Settings.Height = 400; g_Settings.Height = 400;
}
static BOOL
ImageView_LoadSettings(VOID)
{
HKEY hKey;
DWORD dwSize;
LSTATUS nError;
nError = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\ReactOS\\shimgvw", 0, KEY_READ, &hKey); nError = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\ReactOS\\shimgvw", 0, KEY_READ, &hKey);
if (nError) if (nError != ERROR_SUCCESS)
{
ImageView_ResetSettings();
return FALSE; return FALSE;
}
dwSize = sizeof(g_Settings); dwSize = sizeof(g_Settings);
nError = RegQueryValueExW(hKey, L"Settings", NULL, NULL, (LPBYTE)&g_Settings, &dwSize); nError = RegQueryValueExW(hKey, L"Settings", NULL, NULL, (LPBYTE)&g_Settings, &dwSize);
RegCloseKey(hKey); RegCloseKey(hKey);
return !nError; if (nError != ERROR_SUCCESS || dwSize != sizeof(g_Settings))
{
ImageView_ResetSettings();
return FALSE;
}
return TRUE;
} }
static VOID static VOID
@ -853,6 +837,7 @@ ImageView_SaveSettings(HWND hwnd)
WINDOWPLACEMENT wp; WINDOWPLACEMENT wp;
HKEY hKey; HKEY hKey;
RECT *prc; RECT *prc;
LSTATUS nError;
wp.length = sizeof(WINDOWPLACEMENT); wp.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(hwnd, &wp); GetWindowPlacement(hwnd, &wp);
@ -864,12 +849,13 @@ ImageView_SaveSettings(HWND hwnd)
g_Settings.Height = prc->bottom - prc->top; g_Settings.Height = prc->bottom - prc->top;
g_Settings.Maximized = IsZoomed(hwnd); g_Settings.Maximized = IsZoomed(hwnd);
if (RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\ReactOS\\shimgvw"), 0, NULL, nError = RegCreateKeyExW(HKEY_CURRENT_USER, L"Software\\ReactOS\\shimgvw",
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL);
{ if (nError != ERROR_SUCCESS)
RegSetValueEx(hKey, _T("Settings"), 0, REG_BINARY, (LPBYTE)&g_Settings, sizeof(SHIMGVW_SETTINGS)); return;
RegCloseKey(hKey);
} RegSetValueExW(hKey, L"Settings", 0, REG_BINARY, (LPBYTE)&g_Settings, sizeof(g_Settings));
RegCloseKey(hKey);
} }
static BOOL static BOOL
@ -883,14 +869,13 @@ ImageView_CreateToolBar(HWND hwnd)
{ {
HIMAGELIST hImageList; HIMAGELIST hImageList;
SendMessageW(g_hToolBar, TB_SETEXTENDEDSTYLE, SendMessageW(g_hToolBar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS);
0, TBSTYLE_EX_HIDECLIPPEDBUTTONS);
SendMessageW(g_hToolBar, TB_BUTTONSTRUCTSIZE, SendMessageW(g_hToolBar, TB_BUTTONSTRUCTSIZE, sizeof(s_Buttons[0]), 0);
sizeof(s_Buttons[0]), 0);
hImageList = ImageList_Create(TB_IMAGE_WIDTH, TB_IMAGE_HEIGHT, ILC_MASK | ILC_COLOR24, 1, 1); hImageList = ImageList_Create(TB_IMAGE_WIDTH, TB_IMAGE_HEIGHT, ILC_MASK | ILC_COLOR24, 1, 1);
if (hImageList == NULL) return FALSE; if (hImageList == NULL)
return FALSE;
for (UINT n = 0; n < _countof(s_ButtonConfig); n++) for (UINT n = 0; n < _countof(s_ButtonConfig); n++)
{ {
@ -923,9 +908,9 @@ static void ImageView_OnTimer(HWND hwnd)
} }
LRESULT CALLBACK LRESULT CALLBACK
ImageView_DispWndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) ImageView_DispWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
switch (Message) switch (uMsg)
{ {
case WM_PAINT: case WM_PAINT:
{ {
@ -942,7 +927,7 @@ ImageView_DispWndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
break; break;
} }
} }
return CallWindowProcW(g_fnPrevProc, hwnd, Message, wParam, lParam); return CallWindowProcW(g_fnPrevProc, hwnd, uMsg, wParam, lParam);
} }
static VOID static VOID
@ -979,25 +964,15 @@ ImageView_OnSize(HWND hwnd, UINT state, INT cx, INT cy)
MoveWindow(g_hDispWnd, 0, 0, cx, cy - (rc.bottom - rc.top), TRUE); MoveWindow(g_hDispWnd, 0, 0, cx, cy - (rc.bottom - rc.top), TRUE);
/* is it maximized or restored? */ if (!IsIconic(hwnd)) /* Is it not minimized? */
if (state == SIZE_MAXIMIZED || state == SIZE_RESTORED)
{
/* reset zoom */
ResetZoom(); ResetZoom();
}
} }
static LRESULT static VOID
ImageView_Delete(HWND hwnd) ImageView_Delete(HWND hwnd)
{ {
WCHAR szCurFile[MAX_PATH + 1], szNextFile[MAX_PATH]; WCHAR szCurFile[MAX_PATH + 1], szNextFile[MAX_PATH];
SHFILEOPSTRUCT FileOp = { hwnd, FO_DELETE }; SHFILEOPSTRUCTW FileOp = { hwnd, FO_DELETE };
if (g_pImage)
{
GdipDisposeImage(g_pImage);
g_pImage = NULL;
}
/* FileOp.pFrom must be double-null-terminated */ /* FileOp.pFrom must be double-null-terminated */
GetFullPathNameW(g_pCurrentFile->FileName, _countof(szCurFile) - 1, szCurFile, NULL); GetFullPathNameW(g_pCurrentFile->FileName, _countof(szCurFile) - 1, szCurFile, NULL);
@ -1007,71 +982,59 @@ ImageView_Delete(HWND hwnd)
GetFullPathNameW(g_pCurrentFile->Next->FileName, _countof(szNextFile), szNextFile, NULL); GetFullPathNameW(g_pCurrentFile->Next->FileName, _countof(szNextFile), szNextFile, NULL);
szNextFile[_countof(szNextFile) - 1] = UNICODE_NULL; /* Avoid buffer overrun */ szNextFile[_countof(szNextFile) - 1] = UNICODE_NULL; /* Avoid buffer overrun */
/* FIXME: Our GdipLoadImageFromFile locks the image file */
if (g_pImage)
{
GdipDisposeImage(g_pImage);
g_pImage = NULL;
}
/* Confirm file deletion and delete if allowed */
FileOp.pFrom = szCurFile; FileOp.pFrom = szCurFile;
FileOp.fFlags = FOF_ALLOWUNDO; FileOp.fFlags = FOF_ALLOWUNDO;
if (SHFileOperation(&FileOp) != 0) if (SHFileOperationW(&FileOp) != 0)
return 0; {
DPRINT("ImageView_Delete: SHFileOperationW() failed or canceled\n");
pLoadImage(szCurFile);
return;
}
/* Reload the file list and go next file */
pFreeFileList(g_pCurrentFile); pFreeFileList(g_pCurrentFile);
g_pCurrentFile = NULL;
g_pCurrentFile = pBuildFileList(szNextFile); g_pCurrentFile = pBuildFileList(szNextFile);
pLoadImageFromNode(g_pCurrentFile, hwnd); pLoadImageFromNode(g_pCurrentFile, hwnd);
return 1;
} }
static LRESULT static VOID
ImageView_Modify(HWND hwnd) ImageView_Modify(HWND hwnd)
{ {
int nChars = GetFullPathNameW(g_pCurrentFile->FileName, 0, NULL, NULL); WCHAR szPathName[MAX_PATH];
LPWSTR pszPathName;
SHELLEXECUTEINFOW sei; SHELLEXECUTEINFOW sei;
if (!nChars) GetFullPathNameW(g_pCurrentFile->FileName, _countof(szPathName), szPathName, NULL);
{ szPathName[_countof(szPathName) - 1] = UNICODE_NULL; /* Avoid buffer overrun */
DPRINT1("ImageView_Modify: failed to get full path name.\n");
return 1;
}
pszPathName = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, nChars * sizeof(WCHAR));
if (pszPathName == NULL)
{
DPRINT1("HeapAlloc() failed in ImageView_Modify()\n");
return 1;
}
GetFullPathNameW(g_pCurrentFile->FileName, nChars, pszPathName, NULL);
ZeroMemory(&sei, sizeof(sei));
sei.cbSize = sizeof(sei); sei.cbSize = sizeof(sei);
sei.fMask = 0;
sei.hwnd = NULL;
sei.lpVerb = L"edit"; sei.lpVerb = L"edit";
sei.lpFile = pszPathName; sei.lpFile = szPathName;
sei.lpParameters = NULL;
sei.lpDirectory = NULL;
sei.nShow = SW_SHOWNORMAL; sei.nShow = SW_SHOWNORMAL;
sei.hInstApp = NULL;
if (!ShellExecuteExW(&sei)) if (!ShellExecuteExW(&sei))
{ {
DPRINT1("ImageView_Modify: ShellExecuteExW() failed with code %08X\n", (int)GetLastError()); DPRINT1("ImageView_Modify: ShellExecuteExW() failed with code %ld\n", GetLastError());
} }
HeapFree(GetProcessHeap(), 0, pszPathName);
return 0;
} }
LRESULT CALLBACK LRESULT CALLBACK
ImageView_WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) ImageView_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
switch (Message) switch (uMsg)
{ {
case WM_CREATE: case WM_CREATE:
{ {
ImageView_InitControls(hwnd); ImageView_InitControls(hwnd);
return 0L; break;
} }
case WM_COMMAND: case WM_COMMAND:
@ -1094,7 +1057,7 @@ ImageView_WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
case IDC_REAL_SIZE: case IDC_REAL_SIZE:
UpdateZoom(100, TRUE, FALSE); UpdateZoom(100, TRUE, FALSE);
return 0; break;
case IDC_SLIDE_SHOW: case IDC_SLIDE_SHOW:
DPRINT1("IDC_SLIDE_SHOW unimplemented\n"); DPRINT1("IDC_SLIDE_SHOW unimplemented\n");
@ -1120,7 +1083,7 @@ ImageView_WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
if (g_pImage) if (g_pImage)
{ {
GdipImageRotateFlip(g_pImage, Rotate270FlipNone); GdipImageRotateFlip(g_pImage, Rotate270FlipNone);
ImageView_UpdateWindow(hwnd); InvalidateRect(hwnd, NULL, FALSE);
} }
break; break;
@ -1128,23 +1091,24 @@ ImageView_WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
if (g_pImage) if (g_pImage)
{ {
GdipImageRotateFlip(g_pImage, Rotate90FlipNone); GdipImageRotateFlip(g_pImage, Rotate90FlipNone);
ImageView_UpdateWindow(hwnd); InvalidateRect(hwnd, NULL, FALSE);
} }
break; break;
case IDC_DELETE: case IDC_DELETE:
return ImageView_Delete(hwnd); ImageView_Delete(hwnd);
break;
case IDC_MODIFY: case IDC_MODIFY:
return ImageView_Modify(hwnd); ImageView_Modify(hwnd);
break;
} }
} }
break; break;
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
ImageView_OnMouseWheel(hwnd, ImageView_OnMouseWheel(hwnd, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), (SHORT)HIWORD(wParam), (UINT)LOWORD(wParam));
(SHORT)HIWORD(wParam), (UINT)LOWORD(wParam));
break; break;
case WM_NOTIFY: case WM_NOTIFY:
@ -1153,15 +1117,12 @@ ImageView_WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
switch (pnmhdr->code) switch (pnmhdr->code)
{ {
case TTN_GETDISPINFO: case TTN_GETDISPINFOW:
{ {
LPTOOLTIPTEXTW lpttt; LPTOOLTIPTEXTW lpttt = (LPTOOLTIPTEXTW)lParam;
lpttt = (LPTOOLTIPTEXTW)lParam;
lpttt->hinst = g_hInstance; lpttt->hinst = g_hInstance;
lpttt->lpszText = MAKEINTRESOURCEW(s_ButtonConfig[lpttt->hdr.idFrom - IDC_TOOL_BASE].ids); lpttt->lpszText = MAKEINTRESOURCEW(s_ButtonConfig[lpttt->hdr.idFrom - IDC_TOOL_BASE].ids);
return 0; break;
} }
} }
break; break;
@ -1171,12 +1132,12 @@ ImageView_WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
MINMAXINFO *pMMI = (MINMAXINFO*)lParam; MINMAXINFO *pMMI = (MINMAXINFO*)lParam;
pMMI->ptMinTrackSize.x = 350; pMMI->ptMinTrackSize.x = 350;
pMMI->ptMinTrackSize.y = 290; pMMI->ptMinTrackSize.y = 290;
return 0; break;
} }
case WM_SIZE: case WM_SIZE:
{ {
ImageView_OnSize(hwnd, (UINT)wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); ImageView_OnSize(hwnd, (UINT)wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
return 0; break;
} }
case WM_DESTROY: case WM_DESTROY:
{ {
@ -1185,9 +1146,13 @@ ImageView_WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
PostQuitMessage(0); PostQuitMessage(0);
break; break;
} }
default:
{
return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
} }
return DefWindowProcW(hwnd, Message, wParam, lParam); return 0;
} }
LONG WINAPI LONG WINAPI
@ -1196,34 +1161,30 @@ ImageView_CreateWindow(HWND hwnd, LPCWSTR szFileName)
struct GdiplusStartupInput gdiplusStartupInput; struct GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken; ULONG_PTR gdiplusToken;
WNDCLASSW WndClass = {0}; WNDCLASSW WndClass = {0};
WCHAR szBuf[512]; WCHAR szBuf[256];
WCHAR szInitialFile[MAX_PATH]; WCHAR szInitialFile[MAX_PATH];
HWND hMainWnd; HWND hMainWnd;
MSG msg; MSG msg;
HACCEL hKbdAccel; HACCEL hAccel;
HRESULT hComRes; HRESULT hrCoInit;
INITCOMMONCONTROLSEX Icc = { .dwSize = sizeof(Icc), .dwICC = ICC_WIN95_CLASSES }; INITCOMMONCONTROLSEX Icc = { .dwSize = sizeof(Icc), .dwICC = ICC_WIN95_CLASSES };
InitCommonControlsEx(&Icc); InitCommonControlsEx(&Icc);
hComRes = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); /* Initialize COM */
if (hComRes != S_OK && hComRes != S_FALSE) hrCoInit = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
{ if (FAILED(hrCoInit))
DPRINT1("Warning, CoInitializeEx failed with code=%08X\n", (int)hComRes); DPRINT1("Warning, CoInitializeEx failed with code=%08X\n", (int)hrCoInit);
}
ImageView_LoadSettings(); ImageView_LoadSettings();
// Initialize GDI+ /* Initialize GDI+ */
gdiplusStartupInput.GdiplusVersion = 1; ZeroMemory(&gdiplusStartupInput, sizeof(gdiplusStartupInput));
gdiplusStartupInput.DebugEventCallback = NULL; gdiplusStartupInput.GdiplusVersion = 1;
gdiplusStartupInput.SuppressBackgroundThread = FALSE;
gdiplusStartupInput.SuppressExternalCodecs = FALSE;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
pLoadImage(szFileName); pLoadImage(szFileName);
// Create the window /* Register window classes */
WndClass.lpszClassName = WC_SHIMGVW; WndClass.lpszClassName = WC_SHIMGVW;
WndClass.lpfnWndProc = ImageView_WndProc; WndClass.lpfnWndProc = ImageView_WndProc;
WndClass.hInstance = g_hInstance; WndClass.hInstance = g_hInstance;
@ -1231,17 +1192,15 @@ ImageView_CreateWindow(HWND hwnd, LPCWSTR szFileName)
WndClass.hIcon = LoadIconW(g_hInstance, MAKEINTRESOURCEW(IDI_APP_ICON)); WndClass.hIcon = LoadIconW(g_hInstance, MAKEINTRESOURCEW(IDI_APP_ICON));
WndClass.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW); WndClass.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
WndClass.hbrBackground = NULL; /* less flicker */ WndClass.hbrBackground = NULL; /* less flicker */
if (!RegisterClassW(&WndClass))
return -1;
if (!RegisterClassW(&WndClass)) return -1; /* Create the main window */
LoadStringW(g_hInstance, IDS_APPTITLE, szBuf, _countof(szBuf)); LoadStringW(g_hInstance, IDS_APPTITLE, szBuf, _countof(szBuf));
hMainWnd = CreateWindowExW(WS_EX_WINDOWEDGE, WC_SHIMGVW, szBuf, hMainWnd = CreateWindowExW(WS_EX_WINDOWEDGE, WC_SHIMGVW, szBuf,
WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPSIBLINGS, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS,
g_Settings.X, g_Settings.Y, g_Settings.X, g_Settings.Y, g_Settings.Width, g_Settings.Height,
g_Settings.Width, g_Settings.Height,
NULL, NULL, g_hInstance, NULL); NULL, NULL, g_hInstance, NULL);
if (g_Settings.Maximized)
ShowWindow(hMainWnd, SW_MAXIMIZE);
// make sure the path has no quotes on it // make sure the path has no quotes on it
StringCbCopyW(szInitialFile, sizeof(szInitialFile), szFileName); StringCbCopyW(szInitialFile, sizeof(szInitialFile), szFileName);
@ -1254,27 +1213,28 @@ ImageView_CreateWindow(HWND hwnd, LPCWSTR szFileName)
} }
/* Create accelerator table for keystrokes */ /* Create accelerator table for keystrokes */
hKbdAccel = LoadAcceleratorsW(g_hInstance, MAKEINTRESOURCEW(IDR_ACCELERATOR)); hAccel = LoadAcceleratorsW(g_hInstance, MAKEINTRESOURCEW(IDR_ACCELERATOR));
/* Show the main window now */
if (g_Settings.Maximized)
ShowWindow(hMainWnd, SW_SHOWMAXIMIZED);
else
ShowWindow(hMainWnd, SW_SHOWNORMAL);
// Show it
ShowWindow(hMainWnd, SW_SHOW);
UpdateWindow(hMainWnd); UpdateWindow(hMainWnd);
// Message Loop /* Message Loop */
for (;;) while (GetMessageW(&msg, NULL, 0, 0) > 0)
{ {
if (GetMessageW(&msg, NULL, 0, 0) <= 0) if (TranslateAcceleratorW(hMainWnd, hAccel, &msg))
break; continue;
if (!TranslateAcceleratorW(hMainWnd, hKbdAccel, &msg)) TranslateMessage(&msg);
{ DispatchMessageW(&msg);
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
} }
/* Destroy accelerator table */ /* Destroy accelerator table */
DestroyAcceleratorTable(hKbdAccel); DestroyAcceleratorTable(hAccel);
pFreeFileList(g_pCurrentFile); pFreeFileList(g_pCurrentFile);
@ -1289,10 +1249,10 @@ ImageView_CreateWindow(HWND hwnd, LPCWSTR szFileName)
GdiplusShutdown(gdiplusToken); GdiplusShutdown(gdiplusToken);
/* Release COM resources */ /* Release COM resources */
if (SUCCEEDED(hComRes)) if (SUCCEEDED(hrCoInit))
CoUninitialize(); CoUninitialize();
return -1; return 0;
} }
VOID WINAPI VOID WINAPI