Skip to content

Commit

Permalink
use ListBox_... macros
Browse files Browse the repository at this point in the history
  • Loading branch information
katahiromz committed Jul 20, 2024
1 parent 51dc203 commit f0e84c0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 42 deletions.
6 changes: 3 additions & 3 deletions src/MDropdownArrow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ class MDropdownListDlg : public MDialogBase
{
InitLangListBox(m_lst1);

INT nCount = (INT)SendMessageW(m_lst1, LB_GETCOUNT, 0, 0);
INT nCount = ListBox_GetCount(m_lst1);

RECT rc;
SendMessageW(m_lst1, LB_GETITEMRECT, 0, (LPARAM)&rc);
ListBox_GetItemRect(m_lst1, 0, &rc);
LONG cy = rc.bottom - rc.top;

if (nCount > 10)
Expand Down Expand Up @@ -156,7 +156,7 @@ class MDropdownArrow : public MWindowBase

BOOL DoComplement(HWND hwnd, WPARAM wParam)
{
INT nIndex = (INT)SendMessage(m_dialog.m_lst1, LB_GETCURSEL, 0, 0);
INT nIndex = ListBox_GetCurSel(m_dialog.m_lst1);
switch (wParam)
{
case VK_RETURN:
Expand Down
73 changes: 36 additions & 37 deletions src/MEditToolbarDlg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,15 @@ class MEditToolbarDlg : public MDialogBase
if (id != 0)
{
std::wstring str = g_db.GetNameOfResID(IDTYPE_COMMAND, IDTYPE_NEWCOMMAND, id, true);
SendMessageW(m_hLst1, LB_ADDSTRING, 0, (LPARAM)str.c_str());
ListBox_AddString(m_hLst1, str.c_str());
}
else
{
SendMessageW(m_hLst1, LB_ADDSTRING, 0, (LPARAM)L"---");
ListBox_AddString(m_hLst1, L"---");
}
}
SendMessageW(m_hLst1, LB_SETCURSEL, 0, 0);

SendMessageW(m_hLst1, LB_SETITEMHEIGHT, 0, GetItemHeight(hwnd));
ListBox_SetCurSel(m_hLst1, 0);
ListBox_SetItemHeight(m_hLst1, 0, GetItemHeight(hwnd));

SendMessageDx(WM_SETICON, ICON_BIG, (LPARAM)m_hIcon);
SendMessageDx(WM_SETICON, ICON_SMALL, (LPARAM)m_hIconSm);
Expand Down Expand Up @@ -238,85 +237,85 @@ class MEditToolbarDlg : public MDialogBase
auto& str = dialog.m_str;
if (str.empty() || str[0] == L'-')
str = L"---";
INT iItem = (INT)SendMessageW(m_hLst1, LB_INSERTSTRING, -1, (LPARAM)str.c_str());
SendMessageW(m_hLst1, LB_SETCURSEL, iItem, 0);
INT iItem = ListBox_InsertString(m_hLst1, -1, str.c_str());
ListBox_SetCurSel(m_hLst1, iItem);
}
}

void OnModify(HWND hwnd)
{
INT iItem = (INT)SendMessageW(m_hLst1, LB_GETCURSEL, 0, 0);
INT iItem = ListBox_GetCurSel(m_hLst1);
if (iItem < 0)
return;

WCHAR sz1[MAX_PATH];
sz1[0] = 0;
SendMessageW(m_hLst1, LB_GETTEXT, iItem, (LPARAM)sz1);
ListBox_GetText(m_hLst1, iItem, sz1);

MModifyTBBtnDlg dialog(IDD_MODIFYTBBTN, sz1);
if (dialog.DialogBoxDx(hwnd) == IDOK)
{
auto& str = dialog.m_str;
if (str.empty() || str[0] == L'-')
str = L"---";
SendMessageW(m_hLst1, LB_DELETESTRING, iItem, 0);
SendMessageW(m_hLst1, LB_INSERTSTRING, iItem, (LPARAM)str.c_str());
SendMessageW(m_hLst1, LB_SETCURSEL, iItem, 0);
ListBox_DeleteString(m_hLst1, iItem);
ListBox_InsertString(m_hLst1, iItem, str.c_str());
ListBox_SetCurSel(m_hLst1, iItem);
}
}

void OnDelete(HWND hwnd)
{
INT iItem = (INT)SendMessageW(m_hLst1, LB_GETCURSEL, 0, 0);
INT iItem = ListBox_GetCurSel(m_hLst1);
if (iItem >= 0)
{
SendMessageW(m_hLst1, LB_DELETESTRING, iItem, 0);
INT nCount = (INT)SendMessageW(m_hLst1, LB_GETCOUNT, 0, 0);
ListBox_DeleteString(m_hLst1, iItem);
INT nCount = ListBox_GetCount(m_hLst1);
if (nCount == iItem)
SendMessageW(m_hLst1, LB_SETCURSEL, iItem - 1, 0);
ListBox_SetCurSel(m_hLst1, iItem - 1);
else
SendMessageW(m_hLst1, LB_SETCURSEL, iItem, 0);
ListBox_SetCurSel(m_hLst1, iItem);
}
}

void OnUp(HWND hwnd)
{
INT iItem = (INT)SendMessageW(m_hLst1, LB_GETCURSEL, 0, 0);
INT iItem = ListBox_GetCurSel(m_hLst1);
if (iItem > 0)
{
WCHAR sz1[MAX_PATH], sz2[MAX_PATH];
sz1[0] = sz2[0] = 0;
SendMessageW(m_hLst1, LB_GETTEXT, iItem - 1, (LPARAM)sz1);
SendMessageW(m_hLst1, LB_GETTEXT, iItem, (LPARAM)sz2);
SendMessageW(m_hLst1, LB_DELETESTRING, iItem - 1, 0);
SendMessageW(m_hLst1, LB_DELETESTRING, iItem - 1, 0);
SendMessageW(m_hLst1, LB_INSERTSTRING, iItem - 1, (LPARAM)sz1);
SendMessageW(m_hLst1, LB_INSERTSTRING, iItem - 1, (LPARAM)sz2);
SendMessageW(m_hLst1, LB_SETCURSEL, iItem - 1, 0);
ListBox_GetText(m_hLst1, iItem - 1, sz1);
ListBox_GetText(m_hLst1, iItem, sz2);
ListBox_DeleteString(m_hLst1, iItem - 1);
ListBox_DeleteString(m_hLst1, iItem - 1);
ListBox_InsertString(m_hLst1, iItem - 1, sz1);
ListBox_InsertString(m_hLst1, iItem - 1, sz2);
ListBox_SetCurSel(m_hLst1, iItem - 1);
}
}

void OnDown(HWND hwnd)
{
INT iItem = (INT)SendMessageW(m_hLst1, LB_GETCURSEL, 0, 0);
INT cItems = (INT)SendMessageW(m_hLst1, LB_GETCOUNT, 0, 0);
INT iItem = ListBox_GetCurSel(m_hLst1);
INT cItems = ListBox_GetCount(m_hLst1);
if (iItem + 1 < cItems)
{
WCHAR sz1[MAX_PATH], sz2[MAX_PATH];
sz1[0] = sz2[0] = 0;
SendMessageW(m_hLst1, LB_GETTEXT, iItem, (LPARAM)sz1);
SendMessageW(m_hLst1, LB_GETTEXT, iItem + 1, (LPARAM)sz2);
SendMessageW(m_hLst1, LB_DELETESTRING, iItem, 0);
SendMessageW(m_hLst1, LB_DELETESTRING, iItem, 0);
SendMessageW(m_hLst1, LB_INSERTSTRING, iItem, (LPARAM)sz1);
SendMessageW(m_hLst1, LB_INSERTSTRING, iItem, (LPARAM)sz2);
SendMessageW(m_hLst1, LB_SETCURSEL, iItem + 1, 0);
ListBox_GetText(m_hLst1, iItem, sz1);
ListBox_GetText(m_hLst1, iItem + 1, sz2);
ListBox_DeleteString(m_hLst1, iItem);
ListBox_DeleteString(m_hLst1, iItem);
ListBox_InsertString(m_hLst1, iItem, sz1);
ListBox_InsertString(m_hLst1, iItem, sz2);
ListBox_SetCurSel(m_hLst1, iItem + 1);
}
}

void OnOK(HWND hwnd)
{
INT nCount = (INT)SendMessageW(m_hLst1, LB_GETCOUNT, 0, 0);
INT nCount = ListBox_GetCount(m_hLst1);

m_toolbar_res.clear();

Expand Down Expand Up @@ -345,7 +344,7 @@ class MEditToolbarDlg : public MDialogBase
{
WCHAR sz1[MAX_PATH];
sz1[0] = 0;
SendMessageW(m_hLst1, LB_GETTEXT, iItem, (LPARAM)sz1);
ListBox_GetText(m_hLst1, iItem, sz1);

if (!sz1[0] || sz1[0] == L'-')
{
Expand Down Expand Up @@ -410,7 +409,7 @@ class MEditToolbarDlg : public MDialogBase

WCHAR sz1[MAX_PATH];
sz1[0] = 0;
SendMessageW(m_hLst1, LB_GETTEXT, iItem, (LPARAM)sz1);
ListBox_GetText(m_hLst1, iItem, sz1);

if (lpDrawItem->itemState & ODS_SELECTED)
{
Expand Down
4 changes: 2 additions & 2 deletions src/RisohEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7675,8 +7675,8 @@ BOOL InitLangListBox(HWND hwnd)
{
for (auto& lang : g_langs)
{
INT index = (INT)SendMessageW(hwnd, LB_ADDSTRING, 0, (LPARAM)lang.str.c_str());
SendMessageW(hwnd, LB_SETITEMDATA, index, (LPARAM)lang.LangID);
INT index = ListBox_AddString(hwnd, lang.str.c_str());
ListBox_SetItemData(hwnd, index, lang.LangID);
}
return TRUE;
}
Expand Down

0 comments on commit f0e84c0

Please sign in to comment.