diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index cb36b91..8f93658 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1138,7 +1138,7 @@ SHELLEXECUTEINFO exec; exec.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS; exec.hwnd = 0; exec.lpVerb = "open"; - exec.lpFile = "ttcalc.chm"; + exec.lpFile = GetPrgRes()->GetHelpFile().c_str(); exec.lpParameters = 0; exec.lpDirectory = ""; exec.nShow = SW_SHOWNORMAL; diff --git a/src/pad.cpp b/src/pad.cpp index 9bd5c44..5b7d019 100644 --- a/src/pad.cpp +++ b/src/pad.cpp @@ -821,7 +821,7 @@ ATOM a = RegisterPadClass(ttcalc_pad_class_name); DEFAULT_QUALITY, DEFAULT_PITCH, "Ms Shell Dlg"); - HWND pad = CreateWindowEx(0, ttcalc_pad_class_name, + HWND pad = CreateWindowEx(WS_EX_CLIENTEDGE, ttcalc_pad_class_name, "Pad", WS_OVERLAPPEDWINDOW | WS_POPUPWINDOW , GetPrgRes()->GetPadXPos(), GetPrgRes()->GetPadYPos(), diff --git a/src/programresources.cpp b/src/programresources.cpp index 0aaacd0..bd349bc 100644 --- a/src/programresources.cpp +++ b/src/programresources.cpp @@ -645,6 +645,12 @@ return true; } +const std::string & ProgramResources::GetHelpFile() +{ + return help_file; +} + + bool ProgramResources::ReadTextValueFromRegistry(HKEY main_key, const char * sub_key, const char * value, std::string & result) { HKEY reg_key; @@ -672,20 +678,40 @@ return status; } - -void ProgramResources::SetNameOfConfigurationFile() +/* + setting names of: + - configuration file + - help file +*/ +void ProgramResources::SetNameOfFiles() { -static const char simple_file_name[] = "ttcalc.ini"; +char buffer[_MAX_PATH]; +static const char conf_name[] = "ttcalc.ini"; +static const char help_name[] = "ttcalc.chm"; // if there'll be an error we assume that the current directory will be used - // (in the portable version the configuration file is in a current directory) - configuration_file = std::string(".\\") + simple_file_name; + configuration_file = ".\\"; + configuration_file += conf_name; + help_file = ".\\"; + help_file += help_name; -#ifndef TTCALC_PORTABLE + if( !GetCurrentDirectory(_MAX_PATH, buffer) ) + return; -static const char simple_directory_name[] = "TTCalc"; -std::string application_data; + help_file = buffer; + help_file += '\\'; + help_file += help_name; + +#ifdef TTCALC_PORTABLE + configuration_file = buffer; + configuration_file += '\\'; + configuration_file += conf_name; + +#else + + static const char dir_name[] = "TTCalc"; + std::string app_data; // we're trying to read the value "AppData" from registry // which can be, for instance, as: @@ -695,38 +721,38 @@ std::string application_data; HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "AppData", - application_data) ) + app_data) ) { - std::string application_directory = application_data + '\\' + simple_directory_name; - bool success = false; + std::string app_dir = app_data + '\\' + dir_name; - // we have to remember the currect directory - // (because we're using it when we're opening the help) - char * buffer = new char[_MAX_PATH]; - - if( GetCurrentDirectory(_MAX_PATH, buffer) ) - { - // we're testing whether we've got our directory or not - if( SetCurrentDirectory( application_directory.c_str() ) ) - success = true; - else - // now we must create our directory inside it - if( CreateDirectory(application_directory.c_str(), 0) ) - success = true; - - if( success ) - configuration_file = application_directory + '\\' + simple_file_name; - - SetCurrentDirectory(buffer); - } - - delete [] buffer; + if( CreateDirIfNotExists(app_dir) ) + configuration_file = app_dir + '\\' + conf_name; } #endif } + +bool ProgramResources::CreateDirIfNotExists(const std::string & app_dir) +{ +bool success = false; + + if( SetCurrentDirectory( app_dir.c_str() ) ) + { + success = true; + } + else + if( CreateDirectory(app_dir.c_str(), 0) ) + { + success = true; + } + +return success; +} + + + void ProgramResources::CheckCoordinates() { if( x_pos < -50 ) diff --git a/src/programresources.h b/src/programresources.h index ee227eb..564323b 100644 --- a/src/programresources.h +++ b/src/programresources.h @@ -317,8 +317,21 @@ public: will be in a special directory for a particular user, for example: "C:\Documents and Settings\user\applitacion data" */ - void SetNameOfConfigurationFile(); + void SetNameOfFiles(); + + /*! + returning the name of the help file + SetNameOfFiles() should be used first + */ + const std::string & GetHelpFile(); + + + /*! + returning true if such a dir exists + if not the method is trying to create it and returns true if it is created + */ + bool CreateDirIfNotExists(const std::string & app_dir); /*! reading and writing to a file @@ -410,6 +423,7 @@ private: View view; std::string configuration_file; + std::string help_file; int y_size_normal; int y_size_compact; diff --git a/src/winmain.cpp b/src/winmain.cpp index 7695660..f837a6f 100644 --- a/src/winmain.cpp +++ b/src/winmain.cpp @@ -59,7 +59,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) GetPrgRes()->GetLanguages()->InitAll(); GetPrgRes()->GetLanguages()->SetCurrentLanguage(Languages::en); //GetPrgRes()->GetConvert()->Init(); - GetPrgRes()->SetNameOfConfigurationFile(); + GetPrgRes()->SetNameOfFiles(); GetPrgRes()->ReadFromFile(); INITCOMMONCONTROLSEX common_ctrl;