Reduce variable scope
[TortoiseGit.git] / src / TortoiseIDiff / TortoiseIDiff.cpp
blob35264e59f772e728258f7ca69c74682b8fe0b590
1 // TortoiseIDiff - an image diff viewer in TortoiseSVN and TortoiseGit
3 // Copyright (C) 2006 - 2007, 2010-2013 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "stdafx.h"
20 #include "mainWindow.h"
21 #include "CmdLineParser.h"
22 #include "registry.h"
23 #include "LangDll.h"
24 #include "TortoiseIDiff.h"
25 #include "TaskbarUUID.h"
27 #pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
29 // Global Variables:
30 HINSTANCE hInst; // current instance
31 HINSTANCE hResource; // the resource dll
32 HCURSOR curHand;
33 HCURSOR curHandDown;
35 int APIENTRY _tWinMain(HINSTANCE hInstance,
36 HINSTANCE /*hPrevInstance*/,
37 LPTSTR lpCmdLine,
38 int /*nCmdShow*/)
40 SetDllDirectory(L"");
41 SetTaskIDPerUUID();
42 CRegStdDWORD loc = CRegStdDWORD(_T("Software\\TortoiseGit\\LanguageID"), 1033);
43 long langId = loc;
45 CLangDll langDLL;
46 hResource = langDLL.Init(_T("TortoiseIDiff"), langId);
47 if (hResource == NULL)
48 hResource = hInstance;
50 CCmdLineParser parser(lpCmdLine);
52 if (parser.HasKey(_T("?")) || parser.HasKey(_T("help")))
54 TCHAR buf[1024];
55 LoadString(hResource, IDS_COMMANDLINEHELP, buf, _countof(buf));
56 MessageBox(NULL, buf, _T("TortoiseIDiff"), MB_ICONINFORMATION);
57 langDLL.Close();
58 return 0;
62 MSG msg;
63 hInst = hInstance;
65 INITCOMMONCONTROLSEX used = {
66 sizeof(INITCOMMONCONTROLSEX),
67 ICC_STANDARD_CLASSES | ICC_BAR_CLASSES | ICC_WIN95_CLASSES
69 InitCommonControlsEx(&used);
71 // load the cursors we need
72 curHand = (HCURSOR)LoadImage(hInst, MAKEINTRESOURCE(IDC_PANCUR), IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE);
73 curHandDown = (HCURSOR)LoadImage(hInst, MAKEINTRESOURCE(IDC_PANDOWNCUR), IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE);
75 std::unique_ptr<CMainWindow> mainWindow(new CMainWindow(hResource));
76 mainWindow->SetRegistryPath(_T("Software\\TortoiseGit\\TortoiseIDiffWindowPos"));
77 std::wstring leftfile = parser.HasVal(_T("left")) ? parser.GetVal(_T("left")) : _T("");
78 if ((leftfile.empty()) && (lpCmdLine[0] != 0))
80 leftfile = lpCmdLine;
82 mainWindow->SetLeft(leftfile.c_str(), parser.HasVal(_T("lefttitle")) ? parser.GetVal(_T("lefttitle")) : _T(""));
83 mainWindow->SetRight(parser.HasVal(_T("right")) ? parser.GetVal(_T("right")) : _T(""), parser.HasVal(_T("righttitle")) ? parser.GetVal(_T("righttitle")) : _T(""));
84 if (mainWindow->RegisterAndCreateWindow())
86 HACCEL hAccelTable = LoadAccelerators(hResource, MAKEINTRESOURCE(IDR_TORTOISEIDIFF));
87 if (!parser.HasVal(_T("left")))
89 PostMessage(*mainWindow, WM_COMMAND, ID_FILE_OPEN, 0);
91 if (parser.HasKey(_T("overlay")))
93 PostMessage(*mainWindow, WM_COMMAND, ID_VIEW_OVERLAPIMAGES, 0);
95 if (parser.HasKey(_T("fit")))
97 PostMessage(*mainWindow, WM_COMMAND, ID_VIEW_FITTOGETHER, 0);
99 if (parser.HasKey(_T("showinfo")))
101 PostMessage(*mainWindow, WM_COMMAND, ID_VIEW_IMAGEINFO, 0);
103 // Main message loop:
104 while (GetMessage(&msg, NULL, 0, 0))
106 if (!TranslateAccelerator(*mainWindow, hAccelTable, &msg))
108 TranslateMessage(&msg);
109 DispatchMessage(&msg);
112 return (int) msg.wParam;
114 langDLL.Close();
115 DestroyCursor(curHand);
116 DestroyCursor(curHandDown);
117 return 1;