[SHIMGVW] Add g_ or s_ prefix to global variables (#6134)

Renaming global variables:
- s/hInstance/g_hInstance/
- s/shiSettings/g_Settings/
- s/currentFile/g_pCurrentFile/
- s/image/g_pImage/
- s/PrevProc/g_fnPrevProc/
- s/hDispWnd/g_hDispWnd/
- s/hToolBar/g_hToolBar/
- s/ZoomPercents/s_nZoomPercents/
- s/ZoomSteps/s_ZoomSteps/
- s/Buttons/s_Buttons/
- s/BtnConfig/s_ButtonConfig/
CORE-19358
This commit is contained in:
Katayama Hirofumi MZ 2023-12-08 21:35:43 +09:00 committed by GitHub
parent e7f6b473e6
commit 57e7f0b321
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -35,24 +35,25 @@
#include "shimgvw.h" #include "shimgvw.h"
HINSTANCE hInstance; HINSTANCE g_hInstance;
SHIMGVW_SETTINGS shiSettings; SHIMGVW_SETTINGS g_Settings;
SHIMGVW_FILENODE *currentFile; SHIMGVW_FILENODE *g_pCurrentFile;
GpImage *image = NULL; GpImage *g_pImage = NULL;
WNDPROC PrevProc = NULL; WNDPROC g_fnPrevProc = NULL;
HWND hDispWnd, hToolBar; HWND g_hDispWnd = NULL;
HWND g_hToolBar = NULL;
/* zooming */ /* zooming */
UINT ZoomPercents = 100; static UINT s_nZoomPercents = 100;
static const UINT ZoomSteps[] = static const UINT s_ZoomSteps[] =
{ {
10, 25, 50, 100, 200, 400, 800, 1600 10, 25, 50, 100, 200, 400, 800, 1600
}; };
#define MIN_ZOOM ZoomSteps[0] #define MIN_ZOOM s_ZoomSteps[0]
#define MAX_ZOOM ZoomSteps[_countof(ZoomSteps)-1] #define MAX_ZOOM s_ZoomSteps[_countof(s_ZoomSteps) - 1]
/* ToolBar Buttons */ /* ToolBar Buttons */
typedef struct { typedef struct {
@ -68,7 +69,7 @@ typedef struct {
{ 15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0 } { 15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0 }
/* ToolBar Buttons */ /* ToolBar Buttons */
static const TBBUTTON Buttons[] = static const TBBUTTON s_Buttons[] =
{ {
DEFINE_BTN_INFO(PREV_PIC), DEFINE_BTN_INFO(PREV_PIC),
DEFINE_BTN_INFO(NEXT_PIC), DEFINE_BTN_INFO(NEXT_PIC),
@ -93,7 +94,7 @@ static const TBBUTTON Buttons[] =
#define DEFINE_BTN_CONFIG(_name) { IDB_##_name, IDS_TOOLTIP_##_name } #define DEFINE_BTN_CONFIG(_name) { IDB_##_name, IDS_TOOLTIP_##_name }
static const TB_BUTTON_CONFIG BtnConfig[] = static const TB_BUTTON_CONFIG s_ButtonConfig[] =
{ {
DEFINE_BTN_CONFIG(PREV_PIC), DEFINE_BTN_CONFIG(PREV_PIC),
DEFINE_BTN_CONFIG(NEXT_PIC), DEFINE_BTN_CONFIG(NEXT_PIC),
@ -142,42 +143,42 @@ static BOOL Anime_LoadInfo(void)
PropertyItem *pItem; PropertyItem *pItem;
Anime_FreeInfo(); Anime_FreeInfo();
KillTimer(hDispWnd, ANIME_TIMER_ID); KillTimer(g_hDispWnd, ANIME_TIMER_ID);
if (!image) if (!g_pImage)
return FALSE; return FALSE;
GdipImageGetFrameDimensionsCount(image, &nDimCount); GdipImageGetFrameDimensionsCount(g_pImage, &nDimCount);
if (nDimCount) if (nDimCount)
{ {
dims = (GUID *)calloc(nDimCount, sizeof(GUID)); dims = (GUID *)calloc(nDimCount, sizeof(GUID));
if (dims) if (dims)
{ {
GdipImageGetFrameDimensionsList(image, dims, nDimCount); GdipImageGetFrameDimensionsList(g_pImage, dims, nDimCount);
GdipImageGetFrameCount(image, dims, &result); GdipImageGetFrameCount(g_pImage, dims, &result);
m_nFrameCount = result; m_nFrameCount = result;
free(dims); free(dims);
} }
} }
result = 0; result = 0;
GdipGetPropertyItemSize(image, PropertyTagFrameDelay, &result); GdipGetPropertyItemSize(g_pImage, PropertyTagFrameDelay, &result);
cbItem = result; cbItem = result;
if (cbItem) if (cbItem)
{ {
m_pDelayItem = (PropertyItem *)malloc(cbItem); m_pDelayItem = (PropertyItem *)malloc(cbItem);
GdipGetPropertyItem(image, PropertyTagFrameDelay, cbItem, m_pDelayItem); GdipGetPropertyItem(g_pImage, PropertyTagFrameDelay, cbItem, m_pDelayItem);
} }
result = 0; result = 0;
GdipGetPropertyItemSize(image, PropertyTagLoopCount, &result); GdipGetPropertyItemSize(g_pImage, PropertyTagLoopCount, &result);
cbItem = result; cbItem = result;
if (cbItem) if (cbItem)
{ {
pItem = (PropertyItem *)malloc(cbItem); pItem = (PropertyItem *)malloc(cbItem);
if (pItem) if (pItem)
{ {
if (GdipGetPropertyItem(image, PropertyTagLoopCount, cbItem, pItem) == Ok) if (GdipGetPropertyItem(g_pImage, PropertyTagLoopCount, cbItem, pItem) == Ok)
{ {
m_nLoopCount = *(WORD *)pItem->value; m_nLoopCount = *(WORD *)pItem->value;
} }
@ -187,7 +188,7 @@ static BOOL Anime_LoadInfo(void)
if (m_pDelayItem) if (m_pDelayItem)
{ {
SetTimer(hDispWnd, ANIME_TIMER_ID, 0, NULL); SetTimer(g_hDispWnd, ANIME_TIMER_ID, 0, NULL);
} }
return m_pDelayItem != NULL; return m_pDelayItem != NULL;
@ -198,10 +199,10 @@ static void Anime_SetFrameIndex(UINT nFrameIndex)
if (nFrameIndex < m_nFrameCount) if (nFrameIndex < m_nFrameCount)
{ {
GUID guid = FrameDimensionTime; GUID guid = FrameDimensionTime;
if (Ok != GdipImageSelectActiveFrame(image, &guid, nFrameIndex)) if (Ok != GdipImageSelectActiveFrame(g_pImage, &guid, nFrameIndex))
{ {
guid = FrameDimensionPage; guid = FrameDimensionPage;
GdipImageSelectActiveFrame(image, &guid, nFrameIndex); GdipImageSelectActiveFrame(g_pImage, &guid, nFrameIndex);
} }
} }
m_nFrameIndex = nFrameIndex; m_nFrameIndex = nFrameIndex;
@ -247,10 +248,10 @@ static void UpdateZoom(UINT NewZoom, BOOL bEnableBestFit, BOOL bEnableRealSize)
BOOL bEnableZoomIn, bEnableZoomOut; BOOL bEnableZoomIn, bEnableZoomOut;
/* If zoom has not been changed, ignore it */ /* If zoom has not been changed, ignore it */
if (ZoomPercents == NewZoom) if (s_nZoomPercents == NewZoom)
return; return;
ZoomPercents = 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 = bEnableZoomOut = TRUE;
@ -265,50 +266,50 @@ static void UpdateZoom(UINT NewZoom, BOOL bEnableBestFit, BOOL bEnableRealSize)
} }
/* Update the state of the zoom buttons */ /* Update the state of the zoom buttons */
SendMessageW(hToolBar, TB_ENABLEBUTTON, IDC_ZOOM_OUT, bEnableZoomOut); SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_ZOOM_OUT, bEnableZoomOut);
SendMessageW(hToolBar, TB_ENABLEBUTTON, IDC_ZOOM_IN, bEnableZoomIn); SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_ZOOM_IN, bEnableZoomIn);
/* Redraw the display window */ /* Redraw the display window */
InvalidateRect(hDispWnd, NULL, FALSE); InvalidateRect(g_hDispWnd, NULL, FALSE);
/* Update toolbar buttons */ /* Update toolbar buttons */
SendMessageW(hToolBar, TB_ENABLEBUTTON, IDC_BEST_FIT, bEnableBestFit); SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_BEST_FIT, bEnableBestFit);
SendMessageW(hToolBar, TB_ENABLEBUTTON, IDC_REAL_SIZE, bEnableRealSize); SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_REAL_SIZE, bEnableRealSize);
} }
static void ZoomInOrOut(BOOL bZoomIn) static void ZoomInOrOut(BOOL bZoomIn)
{ {
UINT i, NewZoom; UINT i, NewZoom;
if (image == NULL) if (g_pImage == NULL)
return; return;
if (bZoomIn) /* zoom in */ if (bZoomIn) /* zoom in */
{ {
/* find next step */ /* find next step */
for (i = 0; i < _countof(ZoomSteps); ++i) for (i = 0; i < _countof(s_ZoomSteps); ++i)
{ {
if (ZoomPercents < ZoomSteps[i]) if (s_nZoomPercents < s_ZoomSteps[i])
break; break;
} }
if (i == _countof(ZoomSteps)) if (i == _countof(s_ZoomSteps))
NewZoom = MAX_ZOOM; NewZoom = MAX_ZOOM;
else else
NewZoom = ZoomSteps[i]; NewZoom = s_ZoomSteps[i];
} }
else /* zoom out */ else /* zoom out */
{ {
/* find previous step */ /* find previous step */
for (i = _countof(ZoomSteps); i > 0; ) for (i = _countof(s_ZoomSteps); i > 0; )
{ {
--i; --i;
if (ZoomSteps[i] < ZoomPercents) if (s_ZoomSteps[i] < s_nZoomPercents)
break; break;
} }
if (i < 0) if (i < 0)
NewZoom = MIN_ZOOM; NewZoom = MIN_ZOOM;
else else
NewZoom = ZoomSteps[i]; NewZoom = s_ZoomSteps[i];
} }
/* Update toolbar and refresh screen */ /* Update toolbar and refresh screen */
@ -320,13 +321,13 @@ static void ResetZoom(void)
RECT Rect; RECT Rect;
UINT ImageWidth, ImageHeight, NewZoom; UINT ImageWidth, ImageHeight, NewZoom;
if (image == NULL) if (g_pImage == NULL)
return; return;
/* get disp window size and image size */ /* get disp window size and image size */
GetClientRect(hDispWnd, &Rect); GetClientRect(g_hDispWnd, &Rect);
GdipGetImageWidth(image, &ImageWidth); GdipGetImageWidth(g_pImage, &ImageWidth);
GdipGetImageHeight(image, &ImageHeight); GdipGetImageHeight(g_pImage, &ImageHeight);
/* compare two aspect rates. same as /* compare two aspect rates. same as
(ImageHeight / ImageWidth < Rect.bottom / Rect.right) in real */ (ImageHeight / ImageWidth < Rect.bottom / Rect.right) in real */
@ -370,8 +371,8 @@ static void pLoadImage(LPCWSTR szOpenFileName)
} }
/* load now */ /* load now */
GdipLoadImageFromFile(szOpenFileName, &image); GdipLoadImageFromFile(szOpenFileName, &g_pImage);
if (!image) if (!g_pImage)
{ {
DPRINT1("GdipLoadImageFromFile() failed\n"); DPRINT1("GdipLoadImageFromFile() failed\n");
return; return;
@ -398,7 +399,7 @@ static void pSaveImageAs(HWND hwnd)
UINT j; UINT j;
WCHAR *c; WCHAR *c;
if (image == NULL) if (g_pImage == NULL)
return; return;
GdipGetImageEncodersSize(&num, &size); GdipGetImageEncodersSize(&num, &size);
@ -410,7 +411,7 @@ static void pSaveImageAs(HWND hwnd)
} }
GdipGetImageEncoders(num, size, codecInfo); GdipGetImageEncoders(num, size, codecInfo);
GdipGetImageRawFormat(image, &rawFormat); GdipGetImageRawFormat(g_pImage, &rawFormat);
sizeRemain = 0; sizeRemain = 0;
@ -436,7 +437,7 @@ static void pSaveImageAs(HWND hwnd)
ZeroMemory(&sfn, sizeof(sfn)); ZeroMemory(&sfn, sizeof(sfn));
sfn.lStructSize = sizeof(sfn); sfn.lStructSize = sizeof(sfn);
sfn.hwndOwner = hwnd; sfn.hwndOwner = hwnd;
sfn.hInstance = hInstance; sfn.hInstance = g_hInstance;
sfn.lpstrFile = szSaveFileName; sfn.lpstrFile = szSaveFileName;
sfn.lpstrFilter = szFilterMask; sfn.lpstrFilter = szFilterMask;
sfn.nMaxFile = _countof(szSaveFileName); sfn.nMaxFile = _countof(szSaveFileName);
@ -470,20 +471,20 @@ static void pSaveImageAs(HWND hwnd)
if (m_pDelayItem) if (m_pDelayItem)
{ {
/* save animation */ /* save animation */
KillTimer(hDispWnd, ANIME_TIMER_ID); KillTimer(g_hDispWnd, ANIME_TIMER_ID);
DPRINT1("FIXME: save animation\n"); DPRINT1("FIXME: save animation\n");
if (GdipSaveImageToFile(image, szSaveFileName, &codecInfo[sfn.nFilterIndex - 1].Clsid, NULL) != Ok) if (GdipSaveImageToFile(g_pImage, szSaveFileName, &codecInfo[sfn.nFilterIndex - 1].Clsid, NULL) != Ok)
{ {
DPRINT1("GdipSaveImageToFile() failed\n"); DPRINT1("GdipSaveImageToFile() failed\n");
} }
SetTimer(hDispWnd, ANIME_TIMER_ID, 0, NULL); SetTimer(g_hDispWnd, ANIME_TIMER_ID, 0, NULL);
} }
else else
{ {
/* save non-animation */ /* save non-animation */
if (GdipSaveImageToFile(image, szSaveFileName, &codecInfo[sfn.nFilterIndex - 1].Clsid, NULL) != Ok) if (GdipSaveImageToFile(g_pImage, szSaveFileName, &codecInfo[sfn.nFilterIndex - 1].Clsid, NULL) != Ok)
{ {
DPRINT1("GdipSaveImageToFile() failed\n"); DPRINT1("GdipSaveImageToFile() failed\n");
} }
@ -503,8 +504,8 @@ pPrintImage(HWND hwnd)
static VOID static VOID
EnableToolBarButtons(BOOL bEnable) EnableToolBarButtons(BOOL bEnable)
{ {
SendMessageW(hToolBar, TB_ENABLEBUTTON, IDC_SAVEAS, bEnable); SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_SAVEAS, bEnable);
SendMessageW(hToolBar, TB_ENABLEBUTTON, IDC_PRINT, bEnable); SendMessageW(g_hToolBar, TB_ENABLEBUTTON, IDC_PRINT, bEnable);
} }
static VOID static VOID
@ -514,10 +515,10 @@ pLoadImageFromNode(SHIMGVW_FILENODE *node, HWND hwnd)
WCHAR szResStr[512]; WCHAR szResStr[512];
LPWSTR pchFileTitle; LPWSTR pchFileTitle;
if (image) if (g_pImage)
{ {
GdipDisposeImage(image); GdipDisposeImage(g_pImage);
image = NULL; g_pImage = NULL;
} }
if (node == NULL) if (node == NULL)
@ -528,7 +529,7 @@ pLoadImageFromNode(SHIMGVW_FILENODE *node, HWND hwnd)
pLoadImage(node->FileName); pLoadImage(node->FileName);
LoadStringW(hInstance, IDS_APPTITLE, szResStr, _countof(szResStr)); LoadStringW(g_hInstance, IDS_APPTITLE, szResStr, _countof(szResStr));
pchFileTitle = PathFindFileNameW(node->FileName); pchFileTitle = PathFindFileNameW(node->FileName);
if (pchFileTitle && *pchFileTitle) if (pchFileTitle && *pchFileTitle)
@ -542,7 +543,7 @@ pLoadImageFromNode(SHIMGVW_FILENODE *node, HWND hwnd)
SetWindowTextW(hwnd, szResStr); SetWindowTextW(hwnd, szResStr);
} }
EnableToolBarButtons(image != NULL); EnableToolBarButtons(g_pImage != NULL);
/* Redraw the display window */ /* Redraw the display window */
InvalidateRect(hwnd, NULL, FALSE); InvalidateRect(hwnd, NULL, FALSE);
@ -739,11 +740,11 @@ ImageView_DrawImage(HWND hwnd)
GetClientRect(hwnd, &rect); GetClientRect(hwnd, &rect);
white = GetStockObject(WHITE_BRUSH); white = GetStockObject(WHITE_BRUSH);
if (image == NULL) if (g_pImage == NULL)
{ {
FillRect(hdc, &rect, white); FillRect(hdc, &rect, white);
LoadStringW(hInstance, IDS_NOPREVIEW, szText, _countof(szText)); LoadStringW(g_hInstance, IDS_NOPREVIEW, szText, _countof(szText));
SetTextColor(hdc, RGB(0, 0, 0)); SetTextColor(hdc, RGB(0, 0, 0));
SetBkMode(hdc, TRANSPARENT); SetBkMode(hdc, TRANSPARENT);
@ -755,11 +756,11 @@ ImageView_DrawImage(HWND hwnd)
} }
else else
{ {
GdipGetImageWidth(image, &ImageWidth); GdipGetImageWidth(g_pImage, &ImageWidth);
GdipGetImageHeight(image, &ImageHeight); GdipGetImageHeight(g_pImage, &ImageHeight);
ZoomedWidth = (ImageWidth * ZoomPercents) / 100; ZoomedWidth = (ImageWidth * s_nZoomPercents) / 100;
ZoomedHeight = (ImageHeight * ZoomPercents) / 100; ZoomedHeight = (ImageHeight * s_nZoomPercents) / 100;
x = (rect.right - ZoomedWidth) / 2; x = (rect.right - ZoomedWidth) / 2;
y = (rect.bottom - ZoomedHeight) / 2; y = (rect.bottom - ZoomedHeight) / 2;
@ -784,10 +785,10 @@ ImageView_DrawImage(HWND hwnd)
DPRINT("x = %d, y = %d, ImageWidth = %u, ImageHeight = %u\n"); DPRINT("x = %d, y = %d, ImageWidth = %u, ImageHeight = %u\n");
DPRINT("rect.right = %ld, rect.bottom = %ld\n", rect.right, rect.bottom); DPRINT("rect.right = %ld, rect.bottom = %ld\n", rect.right, rect.bottom);
DPRINT("ZoomPercents = %d, ZoomedWidth = %d, ZoomedHeight = %d\n", DPRINT("s_nZoomPercents = %d, ZoomedWidth = %d, ZoomedHeight = %d\n",
ZoomPercents, ZoomedWidth, ZoomedWidth); s_nZoomPercents, ZoomedWidth, ZoomedWidth);
if (ZoomPercents % 100 == 0) if (s_nZoomPercents % 100 == 0)
{ {
GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor); GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
GdipSetSmoothingMode(graphics, SmoothingModeNone); GdipSetSmoothingMode(graphics, SmoothingModeNone);
@ -799,7 +800,7 @@ ImageView_DrawImage(HWND hwnd)
} }
uFlags = 0; uFlags = 0;
GdipGetImageFlags(image, &uFlags); GdipGetImageFlags(g_pImage, &uFlags);
if (uFlags & (ImageFlagsHasAlpha | ImageFlagsHasTranslucent)) if (uFlags & (ImageFlagsHasAlpha | ImageFlagsHasTranslucent))
{ {
@ -816,7 +817,7 @@ ImageView_DrawImage(HWND hwnd)
SelectObject(hdc, hbrOld); SelectObject(hdc, hbrOld);
} }
GdipDrawImageRectI(graphics, image, x, y, ZoomedWidth, ZoomedHeight); GdipDrawImageRectI(graphics, g_pImage, x, y, ZoomedWidth, ZoomedHeight);
} }
GdipDeleteGraphics(graphics); GdipDeleteGraphics(graphics);
EndPaint(hwnd, &ps); EndPaint(hwnd, &ps);
@ -829,18 +830,18 @@ ImageView_LoadSettings(VOID)
DWORD dwSize; DWORD dwSize;
LONG nError; LONG nError;
shiSettings.Maximized = FALSE; g_Settings.Maximized = FALSE;
shiSettings.X = CW_USEDEFAULT; g_Settings.X = CW_USEDEFAULT;
shiSettings.Y = CW_USEDEFAULT; g_Settings.Y = CW_USEDEFAULT;
shiSettings.Width = 520; g_Settings.Width = 520;
shiSettings.Height = 400; g_Settings.Height = 400;
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)
return FALSE; return FALSE;
dwSize = sizeof(shiSettings); dwSize = sizeof(g_Settings);
nError = RegQueryValueExW(hKey, L"Settings", NULL, NULL, (LPBYTE)&shiSettings, &dwSize); nError = RegQueryValueExW(hKey, L"Settings", NULL, NULL, (LPBYTE)&g_Settings, &dwSize);
RegCloseKey(hKey); RegCloseKey(hKey);
return !nError; return !nError;
@ -857,16 +858,16 @@ ImageView_SaveSettings(HWND hwnd)
GetWindowPlacement(hwnd, &wp); GetWindowPlacement(hwnd, &wp);
prc = &wp.rcNormalPosition; prc = &wp.rcNormalPosition;
shiSettings.X = prc->left; g_Settings.X = prc->left;
shiSettings.Y = prc->top; g_Settings.Y = prc->top;
shiSettings.Width = prc->right - prc->left; g_Settings.Width = prc->right - prc->left;
shiSettings.Height = prc->bottom - prc->top; g_Settings.Height = prc->bottom - prc->top;
shiSettings.Maximized = IsZoomed(hwnd); g_Settings.Maximized = IsZoomed(hwnd);
if (RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\ReactOS\\shimgvw"), 0, NULL, if (RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\ReactOS\\shimgvw"), 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS)
{ {
RegSetValueEx(hKey, _T("Settings"), 0, REG_BINARY, (LPBYTE)&shiSettings, sizeof(SHIMGVW_SETTINGS)); RegSetValueEx(hKey, _T("Settings"), 0, REG_BINARY, (LPBYTE)&g_Settings, sizeof(SHIMGVW_SETTINGS));
RegCloseKey(hKey); RegCloseKey(hKey);
} }
} }
@ -874,33 +875,33 @@ ImageView_SaveSettings(HWND hwnd)
static BOOL static BOOL
ImageView_CreateToolBar(HWND hwnd) ImageView_CreateToolBar(HWND hwnd)
{ {
hToolBar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, g_hToolBar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | CCS_BOTTOM | TBSTYLE_TOOLTIPS, WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | CCS_BOTTOM | TBSTYLE_TOOLTIPS,
0, 0, 0, 0, hwnd, 0, 0, 0, 0, hwnd,
0, hInstance, NULL); 0, g_hInstance, NULL);
if (hToolBar != NULL) if (g_hToolBar != NULL)
{ {
HIMAGELIST hImageList; HIMAGELIST hImageList;
SendMessageW(hToolBar, TB_SETEXTENDEDSTYLE, SendMessageW(g_hToolBar, TB_SETEXTENDEDSTYLE,
0, TBSTYLE_EX_HIDECLIPPEDBUTTONS); 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS);
SendMessageW(hToolBar, TB_BUTTONSTRUCTSIZE, SendMessageW(g_hToolBar, TB_BUTTONSTRUCTSIZE,
sizeof(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(BtnConfig); n++) for (UINT n = 0; n < _countof(s_ButtonConfig); n++)
{ {
ImageList_AddMasked(hImageList, LoadImageW(hInstance, MAKEINTRESOURCEW(BtnConfig[n].idb), IMAGE_BITMAP, ImageList_AddMasked(hImageList, LoadImageW(g_hInstance, MAKEINTRESOURCEW(s_ButtonConfig[n].idb), IMAGE_BITMAP,
TB_IMAGE_WIDTH, TB_IMAGE_HEIGHT, LR_DEFAULTCOLOR), RGB(255, 255, 255)); TB_IMAGE_WIDTH, TB_IMAGE_HEIGHT, LR_DEFAULTCOLOR), RGB(255, 255, 255));
} }
ImageList_Destroy((HIMAGELIST)SendMessageW(hToolBar, TB_SETIMAGELIST, ImageList_Destroy((HIMAGELIST)SendMessageW(g_hToolBar, TB_SETIMAGELIST,
0, (LPARAM)hImageList)); 0, (LPARAM)hImageList));
SendMessageW(hToolBar, TB_ADDBUTTONS, _countof(Buttons), (LPARAM)Buttons); SendMessageW(g_hToolBar, TB_ADDBUTTONS, _countof(s_Buttons), (LPARAM)s_Buttons);
return TRUE; return TRUE;
} }
@ -941,18 +942,18 @@ ImageView_DispWndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
break; break;
} }
} }
return CallWindowProcW(PrevProc, hwnd, Message, wParam, lParam); return CallWindowProcW(g_fnPrevProc, hwnd, Message, wParam, lParam);
} }
static VOID static VOID
ImageView_InitControls(HWND hwnd) ImageView_InitControls(HWND hwnd)
{ {
hDispWnd = CreateWindowExW(WS_EX_CLIENTEDGE, WC_STATIC, L"", g_hDispWnd = CreateWindowExW(WS_EX_CLIENTEDGE, WC_STATIC, L"",
WS_CHILD | WS_VISIBLE, WS_CHILD | WS_VISIBLE,
0, 0, 0, 0, hwnd, NULL, hInstance, NULL); 0, 0, 0, 0, hwnd, NULL, g_hInstance, NULL);
SetClassLongPtr(hDispWnd, GCL_STYLE, CS_HREDRAW | CS_VREDRAW); SetClassLongPtr(g_hDispWnd, GCL_STYLE, CS_HREDRAW | CS_VREDRAW);
PrevProc = (WNDPROC) SetWindowLongPtr(hDispWnd, GWLP_WNDPROC, (LPARAM) ImageView_DispWndProc); g_fnPrevProc = (WNDPROC) SetWindowLongPtr(g_hDispWnd, GWLP_WNDPROC, (LPARAM) ImageView_DispWndProc);
ImageView_CreateToolBar(hwnd); ImageView_CreateToolBar(hwnd);
} }
@ -972,11 +973,11 @@ ImageView_OnSize(HWND hwnd, UINT state, INT cx, INT cy)
{ {
RECT rc; RECT rc;
SendMessageW(hToolBar, TB_AUTOSIZE, 0, 0); SendMessageW(g_hToolBar, TB_AUTOSIZE, 0, 0);
GetWindowRect(hToolBar, &rc); GetWindowRect(g_hToolBar, &rc);
MoveWindow(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? */ /* is it maximized or restored? */
if (state == SIZE_MAXIMIZED || state == SIZE_RESTORED) if (state == SIZE_MAXIMIZED || state == SIZE_RESTORED)
@ -992,18 +993,18 @@ 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 }; SHFILEOPSTRUCT FileOp = { hwnd, FO_DELETE };
if (image) if (g_pImage)
{ {
GdipDisposeImage(image); GdipDisposeImage(g_pImage);
image = NULL; g_pImage = NULL;
} }
/* FileOp.pFrom must be double-null-terminated */ /* FileOp.pFrom must be double-null-terminated */
GetFullPathNameW(currentFile->FileName, _countof(szCurFile) - 1, szCurFile, NULL); GetFullPathNameW(g_pCurrentFile->FileName, _countof(szCurFile) - 1, szCurFile, NULL);
szCurFile[_countof(szCurFile) - 2] = UNICODE_NULL; /* Avoid buffer overrun */ szCurFile[_countof(szCurFile) - 2] = UNICODE_NULL; /* Avoid buffer overrun */
szCurFile[lstrlenW(szCurFile) + 1] = UNICODE_NULL; szCurFile[lstrlenW(szCurFile) + 1] = UNICODE_NULL;
GetFullPathNameW(currentFile->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 */
FileOp.pFrom = szCurFile; FileOp.pFrom = szCurFile;
@ -1011,11 +1012,11 @@ ImageView_Delete(HWND hwnd)
if (SHFileOperation(&FileOp) != 0) if (SHFileOperation(&FileOp) != 0)
return 0; return 0;
pFreeFileList(currentFile); pFreeFileList(g_pCurrentFile);
currentFile = NULL; g_pCurrentFile = NULL;
currentFile = pBuildFileList(szNextFile); g_pCurrentFile = pBuildFileList(szNextFile);
pLoadImageFromNode(currentFile, hwnd); pLoadImageFromNode(g_pCurrentFile, hwnd);
return 1; return 1;
} }
@ -1023,7 +1024,7 @@ ImageView_Delete(HWND hwnd)
static LRESULT static LRESULT
ImageView_Modify(HWND hwnd) ImageView_Modify(HWND hwnd)
{ {
int nChars = GetFullPathNameW(currentFile->FileName, 0, NULL, NULL); int nChars = GetFullPathNameW(g_pCurrentFile->FileName, 0, NULL, NULL);
LPWSTR pszPathName; LPWSTR pszPathName;
SHELLEXECUTEINFOW sei; SHELLEXECUTEINFOW sei;
@ -1040,7 +1041,7 @@ ImageView_Modify(HWND hwnd)
return 1; return 1;
} }
GetFullPathNameW(currentFile->FileName, nChars, pszPathName, NULL); GetFullPathNameW(g_pCurrentFile->FileName, nChars, pszPathName, NULL);
sei.cbSize = sizeof(sei); sei.cbSize = sizeof(sei);
sei.fMask = 0; sei.fMask = 0;
@ -1078,13 +1079,13 @@ ImageView_WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
switch (LOWORD(wParam)) switch (LOWORD(wParam))
{ {
case IDC_PREV_PIC: case IDC_PREV_PIC:
currentFile = currentFile->Prev; g_pCurrentFile = g_pCurrentFile->Prev;
pLoadImageFromNode(currentFile, hwnd); pLoadImageFromNode(g_pCurrentFile, hwnd);
break; break;
case IDC_NEXT_PIC: case IDC_NEXT_PIC:
currentFile = currentFile->Next; g_pCurrentFile = g_pCurrentFile->Next;
pLoadImageFromNode(currentFile, hwnd); pLoadImageFromNode(g_pCurrentFile, hwnd);
break; break;
case IDC_BEST_FIT: case IDC_BEST_FIT:
@ -1116,17 +1117,17 @@ ImageView_WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
break; break;
case IDC_ROT_CLOCKW: case IDC_ROT_CLOCKW:
if (image) if (g_pImage)
{ {
GdipImageRotateFlip(image, Rotate270FlipNone); GdipImageRotateFlip(g_pImage, Rotate270FlipNone);
ImageView_UpdateWindow(hwnd); ImageView_UpdateWindow(hwnd);
} }
break; break;
case IDC_ROT_COUNCW: case IDC_ROT_COUNCW:
if (image) if (g_pImage)
{ {
GdipImageRotateFlip(image, Rotate90FlipNone); GdipImageRotateFlip(g_pImage, Rotate90FlipNone);
ImageView_UpdateWindow(hwnd); ImageView_UpdateWindow(hwnd);
} }
break; break;
@ -1157,9 +1158,9 @@ ImageView_WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
LPTOOLTIPTEXTW lpttt; LPTOOLTIPTEXTW lpttt;
lpttt = (LPTOOLTIPTEXTW)lParam; lpttt = (LPTOOLTIPTEXTW)lParam;
lpttt->hinst = hInstance; lpttt->hinst = g_hInstance;
lpttt->lpszText = MAKEINTRESOURCEW(BtnConfig[lpttt->hdr.idFrom - IDC_TOOL_BASE].ids); lpttt->lpszText = MAKEINTRESOURCEW(s_ButtonConfig[lpttt->hdr.idFrom - IDC_TOOL_BASE].ids);
return 0; return 0;
} }
} }
@ -1180,7 +1181,7 @@ ImageView_WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
case WM_DESTROY: case WM_DESTROY:
{ {
ImageView_SaveSettings(hwnd); ImageView_SaveSettings(hwnd);
SetWindowLongPtr(hDispWnd, GWLP_WNDPROC, (LPARAM) PrevProc); SetWindowLongPtr(g_hDispWnd, GWLP_WNDPROC, (LPARAM)g_fnPrevProc);
PostQuitMessage(0); PostQuitMessage(0);
break; break;
} }
@ -1225,35 +1226,35 @@ ImageView_CreateWindow(HWND hwnd, LPCWSTR szFileName)
// Create the window // Create the window
WndClass.lpszClassName = WC_SHIMGVW; WndClass.lpszClassName = WC_SHIMGVW;
WndClass.lpfnWndProc = ImageView_WndProc; WndClass.lpfnWndProc = ImageView_WndProc;
WndClass.hInstance = hInstance; WndClass.hInstance = g_hInstance;
WndClass.style = CS_HREDRAW | CS_VREDRAW; WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.hIcon = LoadIconW(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;
LoadStringW(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_VISIBLE | WS_CLIPSIBLINGS,
shiSettings.X, shiSettings.Y, g_Settings.X, g_Settings.Y,
shiSettings.Width, shiSettings.Height, g_Settings.Width, g_Settings.Height,
NULL, NULL, hInstance, NULL); NULL, NULL, g_hInstance, NULL);
if (shiSettings.Maximized) if (g_Settings.Maximized)
ShowWindow(hMainWnd, SW_MAXIMIZE); 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);
PathUnquoteSpacesW(szInitialFile); PathUnquoteSpacesW(szInitialFile);
currentFile = pBuildFileList(szInitialFile); g_pCurrentFile = pBuildFileList(szInitialFile);
if (currentFile) if (g_pCurrentFile)
{ {
pLoadImageFromNode(currentFile, hMainWnd); pLoadImageFromNode(g_pCurrentFile, hMainWnd);
} }
/* Create accelerator table for keystrokes */ /* Create accelerator table for keystrokes */
hKbdAccel = LoadAcceleratorsW(hInstance, MAKEINTRESOURCEW(IDR_ACCELERATOR)); hKbdAccel = LoadAcceleratorsW(g_hInstance, MAKEINTRESOURCEW(IDR_ACCELERATOR));
// Show it // Show it
ShowWindow(hMainWnd, SW_SHOW); ShowWindow(hMainWnd, SW_SHOW);
@ -1275,12 +1276,12 @@ ImageView_CreateWindow(HWND hwnd, LPCWSTR szFileName)
/* Destroy accelerator table */ /* Destroy accelerator table */
DestroyAcceleratorTable(hKbdAccel); DestroyAcceleratorTable(hKbdAccel);
pFreeFileList(currentFile); pFreeFileList(g_pCurrentFile);
if (image) if (g_pImage)
{ {
GdipDisposeImage(image); GdipDisposeImage(g_pImage);
image = NULL; g_pImage = NULL;
} }
Anime_FreeInfo(); Anime_FreeInfo();
@ -1344,7 +1345,7 @@ DllMain(IN HINSTANCE hinstDLL,
{ {
case DLL_PROCESS_ATTACH: case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH: case DLL_THREAD_ATTACH:
hInstance = hinstDLL; g_hInstance = hinstDLL;
break; break;
} }