diff --git a/Console/PageSettingsTabs1.cpp b/Console/PageSettingsTabs1.cpp index 81e51f75..2ce7a890 100644 --- a/Console/PageSettingsTabs1.cpp +++ b/Console/PageSettingsTabs1.cpp @@ -169,6 +169,21 @@ LRESULT PageSettingsTabs1::OnCheckboxClicked(WORD /*wNotifyCode*/, WORD /*wID*/, ////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////// + +LRESULT PageSettingsTabs1::OnTabKillFocus(WORD /*wCommandCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/) +{ + if( wID == IDC_TAB_SHELL ) + { + CString strShell(L""); + this->ConvertShellLink(strShell); + } + return 0; +} + +////////////////////////////////////////////////////////////////////////////// + + ////////////////////////////////////////////////////////////////////////////// void PageSettingsTabs1::EnableControls() @@ -238,16 +253,38 @@ void PageSettingsTabs1::ConvertShellLink(CString& strShell) { DoDataExchange(DDX_SAVE); - m_strShell = strShell; + CString strLink; - if( m_strShell.Right(4).CompareNoCase(L".lnk") == 0 ) + if( strShell.IsEmpty() ) { + // text modified in shell text box + // this text can contain spaces or quotes + strLink = m_strShell.Trim(); + while( strLink.GetLength() > 0 && strLink.GetAt(0) == L'"' ) + strLink = strLink.Right(strLink.GetLength() - 1); + while( strLink.GetLength() > 0 && strLink.GetAt(strLink.GetLength() - 1) == L'"' ) + strLink = strLink.Left(strLink.GetLength() - 1); + } + else + { + // strShell from drag and drop or select file dialog + strLink = strShell; + + m_strShell = strShell; + if( m_strShell.Find(L' ') != -1 && m_strShell.Find(L'"') == -1 ) + { + m_strShell.Insert(0, L'"'); + m_strShell.Insert(m_strShell.GetLength(), L'"'); + } + } + if( strLink.Right(4).CompareNoCase(L".lnk") == 0 ) + { // set title wchar_t szTitle[_MAX_PATH]; if( _wsplitpath_s( - m_strShell.GetString(), + strLink.GetString(), nullptr, 0, nullptr, 0, szTitle, ARRAYSIZE(szTitle), @@ -262,7 +299,7 @@ void PageSettingsTabs1::ConvertShellLink(CString& strShell) CComPtr persistFile; if( SUCCEEDED(shellLink.QueryInterface(&persistFile)) ) { - if( SUCCEEDED(persistFile->Load(m_strShell, STGM_READ)) && + if( SUCCEEDED(persistFile->Load(strLink, STGM_READ)) && SUCCEEDED(shellLink->Resolve(m_hWnd, 0)) ) { WCHAR szBuffer[MAX_PATH]; @@ -280,9 +317,11 @@ void PageSettingsTabs1::ConvertShellLink(CString& strShell) m_strShell.Insert(m_strShell.GetLength(), L'"'); } - m_strShell += L" "; - m_strShell += szBuffer2; - + if( szBuffer2[0] ) + { + m_strShell += L" "; + m_strShell += szBuffer2; + } } if( SUCCEEDED(shellLink->GetWorkingDirectory(szBuffer, MAX_PATH)) ) @@ -313,14 +352,6 @@ void PageSettingsTabs1::ConvertShellLink(CString& strShell) } } } - else - { - if( m_strShell.Find(L' ') != -1 ) - { - m_strShell.Insert(0, L'"'); - m_strShell.Insert(m_strShell.GetLength(), L'"'); - } - } DoDataExchange(DDX_LOAD); } diff --git a/Console/PageSettingsTabs1.h b/Console/PageSettingsTabs1.h index cb818c57..56a8636a 100644 --- a/Console/PageSettingsTabs1.h +++ b/Console/PageSettingsTabs1.h @@ -62,6 +62,7 @@ class PageSettingsTabs1 COMMAND_ID_HANDLER(IDC_CHECK_RUN_AS_CURRENT_USER, OnCheckboxClicked) COMMAND_ID_HANDLER(IDC_CHECK_RUN_AS_ADMIN, OnCheckboxClicked) COMMAND_ID_HANDLER(IDC_CHECK_RUN_AS_USER, OnCheckboxClicked) + COMMAND_CODE_HANDLER(EN_KILLFOCUS, OnTabKillFocus) END_MSG_MAP() // Handler prototypes (uncomment arguments if needed): @@ -79,6 +80,8 @@ class PageSettingsTabs1 LRESULT OnClickedBtnBrowseDir(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); LRESULT OnCheckboxClicked(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + LRESULT OnTabKillFocus(WORD /*wCommandCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/); + void EnableControls(); void Load(std::shared_ptr& tabData);