Skip to content

Commit

Permalink
Wnd_GetTextを適用する
Browse files Browse the repository at this point in the history
std::make_unique<WCHAR[]>を使わないように修正
  • Loading branch information
sanomari committed Oct 25, 2020
1 parent ed530f8 commit c5b4a0f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 63 deletions.
16 changes: 8 additions & 8 deletions sakura_core/dlg/CDlgAbout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,14 +390,14 @@ BOOL CUrlWnd::SetSubclassWindow( HWND hWnd )
SendMessageAny( hWnd, WM_SETFONT, (WPARAM)m_hFont, (LPARAM)FALSE );

// 設定されているテキストを取得する
const ULONG cchText = ::GetWindowTextLength( hWnd );
auto textBuf = std::make_unique<WCHAR[]>( cchText + 1 );
WCHAR* pchText = textBuf.get();
::GetWindowText( hWnd, pchText, cchText + 1 );

// サイズを調整する
auto retSetText = OnSetText( pchText, cchText );
return retSetText ? TRUE : FALSE;
std::wstring strText;
if( ApiWrap::Wnd_GetText( hWnd, strText ) ){
// サイズを調整する
auto retSetText = OnSetText( strText.data(), strText.length() );
return retSetText ? TRUE : FALSE;
}

return FALSE;
}

LRESULT CALLBACK CUrlWnd::UrlWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
Expand Down
11 changes: 3 additions & 8 deletions sakura_core/dlg/CDlgFind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,8 @@ void CDlgFind::SetCombosList( void )
while (Combo_GetCount(hwndCombo) > 0) {
Combo_DeleteString( hwndCombo, 0);
}
int nBufferSize = ::GetWindowTextLength( GetItemHwnd(IDC_COMBO_TEXT) ) + 1;
auto vText = std::make_unique<WCHAR[]>(nBufferSize);
Combo_GetText( hwndCombo, &vText[0], nBufferSize );
if (m_strText.compare( &vText[0] ) != 0) {
std::wstring strText;
if( !ApiWrap::DlgItem_GetText( GetHwnd(), IDC_COMBO_TEXT, strText ) || strText != m_strText ) {
::DlgItem_SetText( GetHwnd(), IDC_COMBO_TEXT, m_strText.c_str() );
}
}
Expand All @@ -212,10 +210,7 @@ int CDlgFind::GetData( void )
m_pShareData->m_Common.m_sSearch.m_bNOTIFYNOTFOUND = m_bNOTIFYNOTFOUND; // 検索/置換 見つからないときメッセージを表示

/* 検索文字列 */
int nBufferSize = ::GetWindowTextLength( GetItemHwnd(IDC_COMBO_TEXT) ) + 1;
auto vText = std::make_unique<WCHAR[]>(nBufferSize);
::DlgItem_GetText( GetHwnd(), IDC_COMBO_TEXT, &vText[0], nBufferSize);
m_strText = &vText[0];
ApiWrap::DlgItem_GetText( GetHwnd(), IDC_COMBO_TEXT, m_strText );

/* 検索ダイアログを自動的に閉じる */
m_pShareData->m_Common.m_sSearch.m_bAutoCloseDlgFind = ::IsDlgButtonChecked( GetHwnd(), IDC_CHECK_bAutoCloseDlgFind );
Expand Down
7 changes: 2 additions & 5 deletions sakura_core/dlg/CDlgGrep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,11 +791,8 @@ int CDlgGrep::GetData( void )
m_bGrepSeparateFolder = IsDlgButtonCheckedBool( GetHwnd(), IDC_CHECK_SEP_FOLDER );

/* 検索文字列 */
int nBufferSize = ::GetWindowTextLength( GetItemHwnd(IDC_COMBO_TEXT) ) + 1;
auto vText = std::make_unique<WCHAR[]>(nBufferSize);
::DlgItem_GetText( GetHwnd(), IDC_COMBO_TEXT, &vText[0], nBufferSize);
m_strText = &vText[0];
m_bSetText = true;
m_bSetText = ApiWrap::DlgItem_GetText( GetHwnd(), IDC_COMBO_TEXT, m_strText );;

/* 検索ファイル */
::DlgItem_GetText( GetHwnd(), IDC_COMBO_FILE, m_szFile, _countof2(m_szFile) );
/* 検索フォルダ */
Expand Down
5 changes: 1 addition & 4 deletions sakura_core/dlg/CDlgGrepReplace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,7 @@ int CDlgGrepReplace::GetData( void )
m_bPaste = IsDlgButtonCheckedBool( GetHwnd(), IDC_CHK_PASTE );

/* 置換後 */
int nBufferSize = ::GetWindowTextLength( GetItemHwnd(IDC_COMBO_TEXT2) ) + 1;
auto vText = std::make_unique<WCHAR[]>(nBufferSize);
::DlgItem_GetText( GetHwnd(), IDC_COMBO_TEXT2, &vText[0], nBufferSize);
m_strText2 = &vText[0];
ApiWrap::DlgItem_GetText(GetHwnd(), IDC_COMBO_TEXT2, m_strText2 );

if( 0 == ::GetWindowTextLength( GetItemHwnd(IDC_COMBO_TEXT) ) ){
WarningMessage( GetHwnd(), LS(STR_DLGREPLC_REPSTR) );
Expand Down
23 changes: 7 additions & 16 deletions sakura_core/dlg/CDlgReplace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,8 @@ void CDlgReplace::SetCombosList( void )
while (Combo_GetCount(hwndCombo) > 0) {
Combo_DeleteString( hwndCombo, 0);
}
int nBufferSize = ::GetWindowTextLength( hwndCombo ) + 1;
auto vText = std::make_unique<WCHAR[]>(nBufferSize);
Combo_GetText( hwndCombo, &vText[0], nBufferSize );
if (m_strText.compare( &vText[0] ) != 0) {
std::wstring strText;
if( !ApiWrap::DlgItem_GetText( GetHwnd(), IDC_COMBO_TEXT, strText ) || strText != m_strText ) {
::DlgItem_SetText( GetHwnd(), IDC_COMBO_TEXT, m_strText.c_str() );
}

Expand All @@ -206,10 +204,8 @@ void CDlgReplace::SetCombosList( void )
while (Combo_GetCount(hwndCombo) > 0) {
Combo_DeleteString( hwndCombo, 0);
}
nBufferSize = ::GetWindowTextLength( hwndCombo ) + 1;
vText = std::make_unique<WCHAR[]>(nBufferSize);
Combo_GetText( hwndCombo, &vText[0], nBufferSize );
if (m_strText2.compare( &vText[0] ) != 0) {
std::wstring strText2;
if( !ApiWrap::DlgItem_GetText( GetHwnd(), IDC_COMBO_TEXT2, strText2 ) || strText2 != m_strText2 ) {
::DlgItem_SetText( GetHwnd(), IDC_COMBO_TEXT2, m_strText2.c_str() );
}
}
Expand Down Expand Up @@ -240,18 +236,13 @@ int CDlgReplace::GetData( void )
m_pShareData->m_Common.m_sSearch.m_bNOTIFYNOTFOUND = m_bNOTIFYNOTFOUND; // 検索/置換 見つからないときメッセージを表示

/* 検索文字列 */
int nBufferSize = ::GetWindowTextLength( GetItemHwnd(IDC_COMBO_TEXT) ) + 1;
auto vText = std::make_unique<WCHAR[]>(nBufferSize);
::DlgItem_GetText( GetHwnd(), IDC_COMBO_TEXT, &vText[0], nBufferSize);
m_strText = &vText[0];
ApiWrap::DlgItem_GetText( GetHwnd(), IDC_COMBO_TEXT, m_strText );

/* 置換後文字列 */
if( ::IsDlgButtonChecked( GetHwnd(), IDC_RADIO_LINEDELETE ) ){
m_strText2 = L"";
}else{
nBufferSize = ::GetWindowTextLength( GetItemHwnd(IDC_COMBO_TEXT2) ) + 1;
vText = std::make_unique<WCHAR[]>(nBufferSize);
::DlgItem_GetText( GetHwnd(), IDC_COMBO_TEXT2, &vText[0], nBufferSize);
m_strText2 = &vText[0];
ApiWrap::DlgItem_GetText( GetHwnd(), IDC_COMBO_TEXT2, m_strText2 );
}

/* 置換 ダイアログを自動的に閉じる */
Expand Down
36 changes: 18 additions & 18 deletions sakura_core/typeprop/CPropTypesRegex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ INT_PTR CPropTypesRegex::DispatchEvent(
case IDC_BUTTON_REGEX_INS: /* 挿入 */
{
//挿入するキー情報を取得する。
auto szKeyWord = std::make_unique<WCHAR[]>(nKeyWordSize);
szKeyWord[0] = L'\0';
::DlgItem_GetText( hwndDlg, IDC_EDIT_REGEX, &szKeyWord[0], nKeyWordSize );
if( szKeyWord[0] == L'\0' ) return FALSE;
std::wstring strKeyWord;
if( !ApiWrap::DlgItem_GetText( hwndDlg, IDC_EDIT_REGEX, strKeyWord ) ){
return FALSE;
}
//同じキーがないか調べる。
nIndex2 = ListView_GetItemCount(hwndList);
if( nIndex2 >= MAX_REGEX_KEYWORD )
Expand All @@ -200,7 +200,7 @@ INT_PTR CPropTypesRegex::DispatchEvent(
//選択中でなければ最後にする。
nIndex = nIndex2;
}
if( !CheckKeywordList(hwndDlg, &szKeyWord[0], -1) ){
if( !CheckKeywordList( hwndDlg, strKeyWord.c_str(), -1 ) ){
return FALSE;
}

Expand All @@ -209,7 +209,7 @@ INT_PTR CPropTypesRegex::DispatchEvent(
::DlgItem_GetText( hwndDlg, IDC_COMBO_REGEX_COLOR, szColorIndex, _countof(szColorIndex) );
//キー情報を挿入する。
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.pszText = &szKeyWord[0];
lvi.pszText = strKeyWord.data();
lvi.iItem = nIndex;
lvi.iSubItem = 0;
lvi.lParam = 0;
Expand All @@ -227,28 +227,28 @@ INT_PTR CPropTypesRegex::DispatchEvent(

case IDC_BUTTON_REGEX_ADD: /* 追加 */
{
auto szKeyWord = std::make_unique<WCHAR[]>(nKeyWordSize);
//最後のキー番号を取得する。
nIndex = ListView_GetItemCount( hwndList );
//追加するキー情報を取得する。
szKeyWord[0] = L'\0';
::DlgItem_GetText( hwndDlg, IDC_EDIT_REGEX, &szKeyWord[0], nKeyWordSize );
if( szKeyWord[0] == L'\0' ) return FALSE;
std::wstring strKeyWord;
if( !ApiWrap::DlgItem_GetText( hwndDlg, IDC_EDIT_REGEX, strKeyWord ) ){
return FALSE;
}
nIndex2 = ListView_GetItemCount(hwndList);
if( nIndex2 >= MAX_REGEX_KEYWORD )
{
ErrorMessage( hwndDlg, LS(STR_PROPTYPEREGEX_NOREG));
return FALSE;
}
if( !CheckKeywordList(hwndDlg, &szKeyWord[0], -1) ){
if( !CheckKeywordList( hwndDlg, strKeyWord.c_str(), -1 ) ){
return FALSE;
}
//追加するキー情報を取得する。
wmemset(szColorIndex, 0, _countof(szColorIndex));
::DlgItem_GetText( hwndDlg, IDC_COMBO_REGEX_COLOR, szColorIndex, _countof(szColorIndex) );
//キーを追加する。
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.pszText = &szKeyWord[0];
lvi.pszText = strKeyWord.data();
lvi.iItem = nIndex;
lvi.iSubItem = 0;
lvi.lParam = 0;
Expand All @@ -266,7 +266,6 @@ INT_PTR CPropTypesRegex::DispatchEvent(

case IDC_BUTTON_REGEX_UPD: /* 更新 */
{
auto szKeyWord = std::make_unique<WCHAR[]>(nKeyWordSize);
//選択中のキーを探す。
nIndex = ListView_GetNextItem( hwndList, -1, LVNI_ALL | LVNI_SELECTED );
if( -1 == nIndex )
Expand All @@ -275,18 +274,19 @@ INT_PTR CPropTypesRegex::DispatchEvent(
return FALSE;
}
//更新するキー情報を取得する。
szKeyWord[0] = L'\0';
::DlgItem_GetText( hwndDlg, IDC_EDIT_REGEX, &szKeyWord[0], nKeyWordSize );
if( szKeyWord[0] == L'\0' ) return FALSE;
if( !CheckKeywordList(hwndDlg, &szKeyWord[0], nIndex) ){
std::wstring strKeyWord;
if( !ApiWrap::DlgItem_GetText( hwndDlg, IDC_EDIT_REGEX, strKeyWord ) ){
return FALSE;
}
if( !CheckKeywordList( hwndDlg, strKeyWord.c_str(), nIndex ) ){
return FALSE;
}
//追加するキー情報を取得する。
wmemset(szColorIndex, 0, _countof(szColorIndex));
::DlgItem_GetText( hwndDlg, IDC_COMBO_REGEX_COLOR, szColorIndex, _countof(szColorIndex) );
//キーを更新する。
lvi.mask = LVIF_TEXT | LVIF_PARAM;
lvi.pszText = &szKeyWord[0];
lvi.pszText = strKeyWord.data();
lvi.iItem = nIndex;
lvi.iSubItem = 0;
lvi.lParam = 0;
Expand Down
5 changes: 1 addition & 4 deletions sakura_core/window/CMainToolBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,7 @@ void CMainToolBar::AcceptSharedSearchKey()
int CMainToolBar::GetSearchKey(std::wstring& strText)
{
if( m_hwndSearchBox ){
int nBufferSize = ::GetWindowTextLength( m_hwndSearchBox ) + 1;
auto vText = std::make_unique<WCHAR[]>(nBufferSize);
::GetWindowText( m_hwndSearchBox, &vText[0], nBufferSize);
strText = &vText[0];
ApiWrap::Wnd_GetText( m_hwndSearchBox, strText );
}else{
strText = L"";
}
Expand Down

0 comments on commit c5b4a0f

Please sign in to comment.