Code cleanup.

This commit is contained in:
spx 2010-12-11 16:30:49 +00:00
parent 42917f7d67
commit 191c12ecf6
2 changed files with 33 additions and 25 deletions

View File

@ -57,6 +57,12 @@ extern "C" EXPORT_PLUGIN void ExecuteBang(LPCTSTR szBang);
const WCHAR* WinClass = L"DummyRainWClass"; const WCHAR* WinClass = L"DummyRainWClass";
const WCHAR* WinName = L"Rainmeter control window"; const WCHAR* WinName = L"Rainmeter control window";
enum RetValue
{
RetSuccess = 0,
RetError = 1
};
/* /*
** WinMain ** WinMain
** **
@ -85,31 +91,30 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
{ {
// It's a !bang // It's a !bang
Bang(lpCmdLine); Bang(lpCmdLine);
return 0; return RetSuccess;
} }
// Check whether Rainmeter.exe is already running // Check whether Rainmeter.exe is already running
if (IsRunning(&hMutex)) if (IsRunning(&hMutex))
{ {
//MessageBox(NULL, L"Rainmeter.exe is already running.", L"Rainmeter", MB_ICONWARNING | MB_TOPMOST | MB_OK); //MessageBox(NULL, L"Rainmeter.exe is already running.", L"Rainmeter", MB_ICONWARNING | MB_TOPMOST | MB_OK);
return FALSE; return RetSuccess;
} }
if(!hPrevInstance) if(!hPrevInstance)
{ {
if (!InitApplication(hInstance, WinClass)) return FALSE; if (!InitApplication(hInstance, WinClass)) return RetError;
} }
hWnd=InitInstance(hInstance, WinClass, WinName); hWnd=InitInstance(hInstance, WinClass, WinName);
if(!hWnd) return FALSE; if(!hWnd) return RetError;
// Remove quotes from the commandline // Remove quotes from the commandline
WCHAR Path[256]; WCHAR Path[MAX_PATH+1] = {0};
Path[0] = 0;
int Pos = 0;
if(lpCmdLine) if(lpCmdLine)
{ {
for(size_t i = 0; i <= wcslen(lpCmdLine); i++) size_t Pos = 0;
for(size_t i = 0, len = wcslen(lpCmdLine); i <= len && Pos < MAX_PATH; ++i)
{ {
if(lpCmdLine[i] != L'\"') Path[Pos++] = lpCmdLine[i]; if(lpCmdLine[i] != L'\"') Path[Pos++] = lpCmdLine[i];
} }
@ -123,11 +128,17 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmd
if(module == NULL) if(module == NULL)
{ {
MessageBox(NULL, L"Unable to load Rainmeter.dll", L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONERROR); MessageBox(NULL, L"Unable to load Rainmeter.dll", L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONERROR);
return 0; DestroyWindow(hWnd);
return RetError;
} }
// Initialize the DLL // Initialize the DLL
initModuleEx(hWnd, module, NULL); if (initModuleEx(hWnd, module, NULL) == 1)
{
MessageBox(NULL, L"Unable to initialize Rainmeter.dll", L"Rainmeter", MB_OK | MB_TOPMOST | MB_ICONERROR);
DestroyWindow(hWnd);
return RetError;
}
// Run the standard window message loop // Run the standard window message loop
while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)

View File

@ -160,6 +160,17 @@ void Initialize(bool DummyLS, LPCTSTR CmdLine)
CRainmeter::SetCommandLine(CmdLine); CRainmeter::SetCommandLine(CmdLine);
} }
/*
** ExecuteBang
**
** Runs a bang command. This is called from the main application
** when a command is given as a command line argument.
**
*/
void ExecuteBang(LPCTSTR szBang)
{
if (Rainmeter) Rainmeter->ExecuteCommand(szBang, NULL);
}
/* /*
** ReadConfigString ** ReadConfigString
@ -1207,9 +1218,7 @@ CRainmeter::CRainmeter()
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
INITCOMMONCONTROLSEX initCtrls; INITCOMMONCONTROLSEX initCtrls = {sizeof(INITCOMMONCONTROLSEX), ICC_LISTVIEW_CLASSES};
initCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX);
initCtrls.dwICC = ICC_TAB_CLASSES;
InitCommonControlsEx(&initCtrls); InitCommonControlsEx(&initCtrls);
// Initialize GDI+. // Initialize GDI+.
@ -1255,18 +1264,6 @@ CRainmeter::~CRainmeter()
GdiplusShutdown(m_GDIplusToken); GdiplusShutdown(m_GDIplusToken);
} }
/*
** ExecuteBang
**
** Runs a bang command. This is called from the main application
** when a command is given as a command line argument.
**
*/
void ExecuteBang(LPCTSTR szBang)
{
if (Rainmeter) Rainmeter->ExecuteCommand(szBang, NULL);
}
/* /*
** Initialize ** Initialize
** **