修复BUTTON控件关联状态BUG

This commit is contained in:
gb 2023-02-01 13:57:47 +08:00
parent f397231416
commit fb462ebd04
3 changed files with 75 additions and 2 deletions

View File

@ -139,6 +139,19 @@ int dlg_base::select_combo_text(HWND combo, const wchar_t* text)
return ret;
}
std::wstring dlg_base::get_wnd_text(HWND h)
{
int len = GetWindowTextLengthW(h);
wchar_t* buf = new wchar_t[len + 8];
std::wstring ret(L"");
memset(buf, 0, (len + 8) * 2);
GetWindowTextW(h, buf, len + 2);
ret = buf;
delete[] buf;
return std::move(ret);
}
BOOL dlg_base::handle_message(UINT msg, WPARAM wp, LPARAM lp)
{
@ -284,6 +297,48 @@ int dlg_base::get_string_width(const wchar_t* str)
return size.cx;
}
bool dlg_base::get_item_rect(UINT id, LPRECT r, bool client)
{
if (client)
return GetClientRect(GetDlgItem(hwnd_, id), r) == TRUE;
else
return GetWindowRect(GetDlgItem(hwnd_, id), r) == TRUE;
}
std::wstring dlg_base::get_item_text(UINT id)
{
return std::move(dlg_base::get_wnd_text(get_item(id)));
}
int dlg_base::get_width_diff_as_text_length(UINT id)
{
RECT r = { 0 };
get_item_rect(id, &r);
return get_string_width(get_item_text(id).c_str()) - RECT_W(r);
}
void dlg_base::offset_item(UINT id, int dx, int dy)
{
RECT r = { 0 };
get_item_rect(id, &r, false);
OffsetRect(&r, dx, dy);
screen_2_client(&r);
MoveWindow(get_item(id), r.left, r.top, RECT_W(r), RECT_H(r), FALSE);
}
void dlg_base::expand_item(UINT id, int dx, int dy)
{
RECT r = { 0 };
get_item_rect(id, &r, false);
r.right += dx;
r.bottom += dy;
screen_2_client(&r);
MoveWindow(get_item(id), r.left, r.top, RECT_W(r), RECT_H(r), FALSE);
}
bool dlg_base::set_item_text(UINT id, const wchar_t* text)
{
return SetWindowTextW(GetDlgItem(hwnd_, id), text) == TRUE;
}
void dlg_base::show_scroll_bar(int bar, bool show)
{
DWORD style = GetWindowLong(hwnd(), GWL_STYLE);
@ -971,7 +1026,7 @@ void dlg_page::set_ctrl_value(HWND ctrl, SANE_Value_Type type, void* val, bool o
{
if (type == SANE_TYPE_BOOL)
{
DWORD id = GetWindowLong(ctrl, GWL_ID);
DWORD id = GetWindowLong(ctrl, GWL_ID) - dlg_page::dyn_id_base;
HWND host = (HWND)GetPropW(ctrl, dlg_page::property_host.c_str());
if (IsWindow(host) && (id == id_custom_area_ || id == id_custom_gamma_))

View File

@ -52,6 +52,7 @@ public:
static bool get_max_size(SIZE& dst, const SIZE& src); // return whether changed dst
static bool get_max_size(SIZE& dst, int cx, int cy); // return whether changed dst
static int select_combo_text(HWND combo, const wchar_t* text);
static std::wstring get_wnd_text(HWND h);
public:
void set_ui_event_notify(void(__stdcall* notify)(int, void*, void*), void* param);
@ -64,6 +65,12 @@ public:
BOOL set_font(HFONT font);
HFONT get_font(void);
int get_string_width(const wchar_t* str);
bool get_item_rect(UINT id, LPRECT r, bool client = true);
std::wstring get_item_text(UINT id);
int get_width_diff_as_text_length(UINT id); //
void offset_item(UINT id, int dx, int dy);
void expand_item(UINT id, int dx, int dy);
bool set_item_text(UINT id, const wchar_t* text);
void show_scroll_bar(int bar = SB_VERT, bool show = true);
bool track_mouse_hover(void);
};

View File

@ -31,6 +31,17 @@
#define IDC_EDIT_INPUT 1018
#define IDC_EDIT_OUTPUT 1019
#define IDC_LIST1 1020
#define IDC_STATIC_UNIT 1021
#define IDC_STATIC_DPI 1022
#define IDC_STATIC_AREA 1023
#define IDC_STATIC_LEFT 1024
#define IDC_STATIC_TOP 1025
#define IDC_STATIC_W 1026
#define IDC_STATIC_H 1027
#define IDC_STATIC_SCHEME 1028
#define IDC_STATIC_COLOR 1029
#define IDC_STATIC_INPUT 1030
#define IDC_STATIC_OUTPUT 1031
// Next default values for new objects
//
@ -38,7 +49,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 109
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1021
#define _APS_NEXT_CONTROL_VALUE 1032
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif