From fb462ebd04e24c5a33e931f976dedf20fec2b10f Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Wed, 1 Feb 2023 13:57:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUTTON=E6=8E=A7=E4=BB=B6?= =?UTF-8?q?=E5=85=B3=E8=81=94=E7=8A=B6=E6=80=81BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sane/DlgPage.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++- sane/DlgPage.h | 7 ++++++ sane/resource.h | 13 ++++++++++- 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/sane/DlgPage.cpp b/sane/DlgPage.cpp index 2aac5f6..cc86b98 100644 --- a/sane/DlgPage.cpp +++ b/sane/DlgPage.cpp @@ -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_)) diff --git a/sane/DlgPage.h b/sane/DlgPage.h index 306ea50..196453c 100644 --- a/sane/DlgPage.h +++ b/sane/DlgPage.h @@ -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); }; diff --git a/sane/resource.h b/sane/resource.h index 951fb53..d033bfc 100644 --- a/sane/resource.h +++ b/sane/resource.h @@ -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