?? fm.cpp
字號:
// FM.cpp
#include "StdAfx.h"
#include "resource.h"
#include "Panel.h"
extern "C"
{
#include "../../../../C/Alloc.h"
}
#include "Common/Defs.h"
#include "Common/StringConvert.h"
// #include "Common/CommandLineParser.h"
#include "Windows/Control/Toolbar.h"
#include "Windows/Error.h"
#include "Windows/COM.h"
#include "Windows/DLL.h"
#include "Windows/Security.h"
#include "Windows/MemoryLock.h"
#include "ViewSettings.h"
#include "../GUI/ExtractRes.h"
#include "App.h"
#include "StringUtils.h"
#include "MyLoadMenu.h"
#include "LangUtils.h"
#include "FormatUtils.h"
#include "RegistryUtils.h"
using namespace NWindows;
using namespace NFile;
using namespace NFind;
// using namespace NCommandLineParser;
#define MAX_LOADSTRING 100
#define MENU_HEIGHT 26
#ifndef _UNICODE
bool g_IsNT = false;
#endif
HINSTANCE g_hInstance;
HWND g_HWND;
bool g_OpenArchive = false;
static UString g_MainPath;
const int kNumDefaultPanels = 1;
const int kSplitterWidth = 4;
int kSplitterRateMax = 1 << 16;
int kPanelSizeMin = 120;
// bool OnMenuCommand(HWND hWnd, int id);
static UString GetProgramPath()
{
UString s;
NDLL::MyGetModuleFileName(g_hInstance, s);
return s;
}
UString GetProgramFolderPrefix()
{
UString path = GetProgramPath();
int pos = path.ReverseFind(WCHAR_PATH_SEPARATOR);
return path.Left(pos + 1);
}
class CSplitterPos
{
int _ratio; // 10000 is max
int _pos;
int _fullWidth;
void SetRatioFromPos(HWND hWnd)
{ _ratio = (_pos + kSplitterWidth / 2) * kSplitterRateMax /
MyMax(GetWidth(hWnd), 1); }
public:
int GetPos() const
{ return _pos; }
int GetWidth(HWND hWnd) const
{
RECT rect;
::GetClientRect(hWnd, &rect);
return rect.right;
}
void SetRatio(HWND hWnd, int aRatio)
{
_ratio = aRatio;
SetPosFromRatio(hWnd);
}
void SetPosPure(HWND hWnd, int pos)
{
int posMax = GetWidth(hWnd) - kSplitterWidth;
if (posMax < kPanelSizeMin * 2)
pos = posMax / 2;
else
{
if (pos > posMax - kPanelSizeMin)
pos = posMax - kPanelSizeMin;
else if (pos < kPanelSizeMin)
pos = kPanelSizeMin;
}
_pos = pos;
}
void SetPos(HWND hWnd, int pos)
{
_fullWidth = GetWidth(hWnd);
SetPosPure(hWnd, pos);
SetRatioFromPos(hWnd);
}
void SetPosFromRatio(HWND hWnd)
{
int fullWidth = GetWidth(hWnd);
if (_fullWidth != fullWidth && fullWidth != 0)
{
_fullWidth = fullWidth;
SetPosPure(hWnd, GetWidth(hWnd) * _ratio / kSplitterRateMax - kSplitterWidth / 2);
}
}
};
static bool g_CanChangeSplitter = false;
static UINT32 g_SplitterPos = 0;
static CSplitterPos g_Splitter;
static bool g_PanelsInfoDefined = false;
static int g_StartCaptureMousePos;
static int g_StartCaptureSplitterPos;
CApp g_App;
void MoveSubWindows(HWND hWnd);
void OnSize(HWND hWnd);
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
const wchar_t *kWindowClass = L"FM";
#ifndef _UNICODE
static bool IsItWindowsNT()
{
OSVERSIONINFO versionInfo;
versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
if (!::GetVersionEx(&versionInfo))
return false;
return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
}
#endif
// FUNCTION: InitInstance(HANDLE, int)
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
CWindow wnd;
g_hInstance = hInstance;
ReloadLangSmart();
// LoadString(hInstance, IDS_CLASS, windowClass, MAX_LOADSTRING);
// LoadString(hInstance, IDS_APP_TITLE, title, MAX_LOADSTRING);
UString title = LangString(IDS_APP_TITLE, 0x03000000);
/*
//If it is already running, then focus on the window
hWnd = FindWindow(windowClass, title);
if (hWnd)
{
SetForegroundWindow ((HWND) (((DWORD)hWnd) | 0x01));
return 0;
}
*/
WNDCLASSW wc;
// wc.style = CS_HREDRAW | CS_VREDRAW;
wc.style = 0;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_FAM));
// wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hCursor = ::LoadCursor(0, IDC_SIZEWE);
// wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
wc.lpszMenuName = MAKEINTRESOURCEW(IDM_MENU);
wc.lpszClassName = kWindowClass;
MyRegisterClass(&wc);
// RECT rect;
// GetClientRect(hWnd, &rect);
DWORD style = WS_OVERLAPPEDWINDOW;
// DWORD style = 0;
RECT rect;
bool maximized = false;
int x , y, xSize, ySize;
x = y = xSize = ySize = CW_USEDEFAULT;
bool windowPosIsRead = ReadWindowSize(rect, maximized);
if (windowPosIsRead)
{
// x = rect.left;
// y = rect.top;
xSize = rect.right - rect.left;
ySize = rect.bottom - rect.top;
}
UINT32 numPanels, currentPanel;
g_PanelsInfoDefined = ReadPanelsInfo(numPanels, currentPanel, g_SplitterPos);
if (g_PanelsInfoDefined)
{
if (numPanels < 1 || numPanels > 2)
numPanels = kNumDefaultPanels;
if (currentPanel >= 2)
currentPanel = 0;
}
else
{
numPanels = kNumDefaultPanels;
currentPanel = 0;
}
g_App.NumPanels = numPanels;
g_App.LastFocusedPanel = currentPanel;
if (!wnd.Create(kWindowClass, title, style,
x, y, xSize, ySize, NULL, NULL, hInstance, NULL))
return FALSE;
g_HWND = (HWND)wnd;
WINDOWPLACEMENT placement;
placement.length = sizeof(placement);
if (wnd.GetPlacement(&placement))
{
if (nCmdShow == SW_SHOWNORMAL || nCmdShow == SW_SHOW ||
nCmdShow == SW_SHOWDEFAULT)
{
if (maximized)
placement.showCmd = SW_SHOWMAXIMIZED;
else
placement.showCmd = SW_SHOWNORMAL;
}
else
placement.showCmd = nCmdShow;
if (windowPosIsRead)
placement.rcNormalPosition = rect;
wnd.SetPlacement(&placement);
// window.Show(nCmdShow);
}
else
wnd.Show(nCmdShow);
return TRUE;
}
/*
static void GetCommands(const UString &aCommandLine, UString &aCommands)
{
UString aProgramName;
aCommands.Empty();
bool aQuoteMode = false;
for (int i = 0; i < aCommandLine.Length(); i++)
{
wchar_t aChar = aCommandLine[i];
if (aChar == L'\"')
aQuoteMode = !aQuoteMode;
else if (aChar == L' ' && !aQuoteMode)
{
if (!aQuoteMode)
{
i++;
break;
}
}
else
aProgramName += aChar;
}
aCommands = aCommandLine.Mid(i);
}
*/
DWORD GetDllVersion(LPCTSTR lpszDllName)
{
HINSTANCE hinstDll;
DWORD dwVersion = 0;
hinstDll = LoadLibrary(lpszDllName);
if(hinstDll)
{
DLLGETVERSIONPROC pDllGetVersion;
pDllGetVersion = (DLLGETVERSIONPROC) GetProcAddress(hinstDll, "DllGetVersion");
/*Because some DLLs might not implement this function, you
must test for it explicitly. Depending on the particular
DLL, the lack of a DllGetVersion function can be a useful
indicator of the version.
*/
if(pDllGetVersion)
{
DLLVERSIONINFO dvi;
HRESULT hr;
ZeroMemory(&dvi, sizeof(dvi));
dvi.cbSize = sizeof(dvi);
hr = (*pDllGetVersion)(&dvi);
if(SUCCEEDED(hr))
{
dwVersion = MAKELONG(dvi.dwMinorVersion, dvi.dwMajorVersion);
}
}
FreeLibrary(hinstDll);
}
return dwVersion;
}
DWORD g_ComCtl32Version;
/*
#ifndef _WIN64
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
static bool IsWow64()
{
LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
GetModuleHandle("kernel32"), "IsWow64Process");
if (fnIsWow64Process == NULL)
return false;
BOOL isWow;
if (!fnIsWow64Process(GetCurrentProcess(),&isWow))
return false;
return isWow != FALSE;
}
#endif
*/
bool IsLargePageSupported()
{
#ifdef _WIN64
return true;
#else
OSVERSIONINFO versionInfo;
versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
if (!::GetVersionEx(&versionInfo))
return false;
if (versionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT || versionInfo.dwMajorVersion < 5)
return false;
if (versionInfo.dwMajorVersion > 5)
return true;
if (versionInfo.dwMinorVersion < 1)
return false;
if (versionInfo.dwMinorVersion > 1)
return true;
// return IsWow64();
return false;
#endif
}
static void SetMemoryLock()
{
if (!IsLargePageSupported())
return;
// if (ReadLockMemoryAdd())
NSecurity::AddLockMemoryPrivilege();
if (ReadLockMemoryEnable())
NSecurity::EnableLockMemoryPrivilege();
}
/*
static const int kNumSwitches = 1;
namespace NKey {
enum Enum
{
kOpenArachive = 0,
};
}
static const CSwitchForm kSwitchForms[kNumSwitches] =
{
{ L"SOA", NSwitchType::kSimple, false },
};
*/
// int APIENTRY WinMain2(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR /* lpCmdLine */, int /* nCmdShow */);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR /* lpCmdLine */, int nCmdShow)
{
#ifndef _UNICODE
g_IsNT = IsItWindowsNT();
#endif
#ifdef _WIN32
SetLargePageSize();
#endif
InitCommonControls();
g_ComCtl32Version = ::GetDllVersion(TEXT("comctl32.dll"));
// OleInitialize is required for drag and drop.
OleInitialize(NULL);
// Maybe needs CoInitializeEx also ?
// NCOM::CComInitializer comInitializer;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -