设置界面添加滚动条支持(V)
This commit is contained in:
parent
cf2c03e3cd
commit
4e6f71bd53
128
sane/DlgPage.cpp
128
sane/DlgPage.cpp
|
@ -246,7 +246,26 @@ int dlg_base::get_string_width(const wchar_t* str)
|
|||
|
||||
return size.cx;
|
||||
}
|
||||
|
||||
void dlg_base::show_scroll_bar(int bar, bool show)
|
||||
{
|
||||
DWORD style = GetWindowLong(hwnd(), GWL_STYLE);
|
||||
if (bar == SB_VERT || bar == SB_BOTH)
|
||||
{
|
||||
if (show)
|
||||
style |= WS_VSCROLL;
|
||||
else
|
||||
style &= ~WS_VSCROLL;
|
||||
SetWindowLong(hwnd(), GWL_STYLE, style);
|
||||
}
|
||||
else if (bar == SB_HORZ || bar == SB_BOTH)
|
||||
{
|
||||
if (show)
|
||||
style |= WS_HSCROLL;
|
||||
else
|
||||
style &= ~WS_HSCROLL;
|
||||
SetWindowLong(hwnd(), GWL_STYLE, style);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// dlg_page 对话框
|
||||
|
@ -257,13 +276,15 @@ UINT dlg_page::dyn_id_base = 3000;
|
|||
int dlg_page::gap_x = 20;
|
||||
int dlg_page::gap_y = 15;
|
||||
int dlg_page::spin_w = 8;
|
||||
int dlg_page::sb_adden = 30;
|
||||
|
||||
dlg_page::dlg_page(HWND parent, const wchar_t* name
|
||||
, LPSANEAPI api, SANE_Handle dev)
|
||||
: dlg_base(parent, IDD_PAGE), name_(name ? name : L""), ctrl_id_(0)
|
||||
, sane_(*api), dev_(dev), done_(false)
|
||||
, id_custom_area_(-1), id_custom_left_(-1), id_custom_right_(-1), id_custom_top_(-1), id_custom_bottom_(-1)
|
||||
, id_custom_gamma_(-1), id_paper_(-1), paper_(L"A4"), id_dpi_(-1), dpi_(200)
|
||||
, id_custom_gamma_(-1), id_paper_(-1), paper_(L"A4"), id_dpi_(-1), dpi_(200), vsb_pos_(0), hsb_pos_(0)
|
||||
, vsb_(false), hsb_(false)
|
||||
{
|
||||
size_.cx = size_.cy = 0;
|
||||
pos_.x = 12;
|
||||
|
@ -291,6 +312,14 @@ BOOL dlg_page::handle_message(UINT msg, WPARAM wp, LPARAM lp)
|
|||
case WM_COMMAND:
|
||||
handle_command(HIWORD(wp), LOWORD(wp), (HWND)lp);
|
||||
break;
|
||||
case WM_VSCROLL:
|
||||
if(vsb_)
|
||||
on_vscroll(HIWORD(wp), LOWORD(wp));
|
||||
break;
|
||||
case WM_HSCROLL:
|
||||
if(hsb_)
|
||||
on_hscroll(HIWORD(wp), LOWORD(wp));
|
||||
break;
|
||||
default:
|
||||
ret = FALSE;
|
||||
}
|
||||
|
@ -981,6 +1010,68 @@ BOOL dlg_page::on_mouse_wheel(WORD vkey, short delta, short x, short y)
|
|||
|
||||
return handled;
|
||||
}
|
||||
void dlg_page::on_vscroll(int pos, int sb_ev)
|
||||
{
|
||||
int old = vsb_pos_;
|
||||
if (sb_ev == SB_THUMBPOSITION || sb_ev == SB_THUMBTRACK)
|
||||
{
|
||||
vsb_pos_ = pos;
|
||||
}
|
||||
else if (sb_ev == SB_LINEUP || sb_ev == SB_TOP)
|
||||
vsb_pos_--;
|
||||
else if (sb_ev == SB_LINEDOWN || sb_ev == SB_BOTTOM)
|
||||
vsb_pos_++;
|
||||
else if (sb_ev == SB_PAGEUP)
|
||||
vsb_pos_ -= size_view_.cy;
|
||||
else if (sb_ev == SB_PAGEDOWN)
|
||||
vsb_pos_ += size_view_.cy;
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (vsb_pos_ < 0)
|
||||
vsb_pos_ = 0;
|
||||
else if (vsb_pos_ > desired_size().cy - size_view_.cy + dlg_page::sb_adden)
|
||||
vsb_pos_ = desired_size().cy - size_view_.cy + dlg_page::sb_adden;
|
||||
|
||||
if (old != vsb_pos_)
|
||||
{
|
||||
ScrollWindow(hwnd(), 0, old - vsb_pos_, NULL, NULL);
|
||||
SetScrollPos(hwnd(), SB_VERT, vsb_pos_, TRUE);
|
||||
}
|
||||
}
|
||||
void dlg_page::on_hscroll(int pos, int sb_ev)
|
||||
{
|
||||
int old = hsb_pos_;
|
||||
if (sb_ev == SB_THUMBPOSITION || sb_ev == SB_THUMBTRACK)
|
||||
{
|
||||
hsb_pos_ = pos;
|
||||
}
|
||||
else if (sb_ev == SB_LINEUP || sb_ev == SB_TOP)
|
||||
hsb_pos_--;
|
||||
else if (sb_ev == SB_LINEDOWN || sb_ev == SB_BOTTOM)
|
||||
hsb_pos_++;
|
||||
else if (sb_ev == SB_PAGEUP)
|
||||
hsb_pos_ -= size_view_.cx;
|
||||
else if (sb_ev == SB_PAGEDOWN)
|
||||
hsb_pos_ += size_view_.cx;
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (hsb_pos_ < 0)
|
||||
hsb_pos_ = 0;
|
||||
else if (hsb_pos_ > desired_size().cx - size_view_.cx + dlg_page::sb_adden)
|
||||
hsb_pos_ = desired_size().cx - size_view_.cx + dlg_page::sb_adden;
|
||||
|
||||
if (old != hsb_pos_)
|
||||
{
|
||||
ScrollWindow(hwnd(), old - hsb_pos_, 0, NULL, NULL);
|
||||
SetScrollPos(hwnd(), SB_HORZ, hsb_pos_, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
bool dlg_page::add_control(int sn, const SANE_Option_Descriptor* desc, void* cur_val)
|
||||
{
|
||||
|
@ -1072,8 +1163,8 @@ bool dlg_page::add_control(int sn, const SANE_Option_Descriptor* desc, void* cur
|
|||
SetPropW(wnd, dlg_page::property_host.c_str(), host);
|
||||
ctrls_.push_back(wnd);
|
||||
}
|
||||
if (size_.cx < pos_.x + text.cx)
|
||||
size_.cx = pos_.x + text.cx;
|
||||
if (size_.cx < pos_.x + text.cx + 10)
|
||||
size_.cx = pos_.x + text.cx + 10;
|
||||
pos_.y += text.cy + dlg_page::gap_y;
|
||||
}
|
||||
break;
|
||||
|
@ -1081,6 +1172,7 @@ bool dlg_page::add_control(int sn, const SANE_Option_Descriptor* desc, void* cur
|
|||
}
|
||||
}
|
||||
size_.cy = pos_.y;
|
||||
size_view_ = size_;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -1144,6 +1236,34 @@ const wchar_t* dlg_page::name(void)
|
|||
{
|
||||
return name_.c_str();
|
||||
}
|
||||
void dlg_page::set_view_size(SIZE size)
|
||||
{
|
||||
int h = size.cy;
|
||||
vsb_ = h < desired_size().cy;
|
||||
if (!vsb_)
|
||||
{
|
||||
show_scroll_bar(SB_VERT, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
size_view_.cy = h;
|
||||
show_scroll_bar(SB_VERT, true);
|
||||
SetScrollRange(hwnd(), SB_VERT, 0, desired_size().cy - h + dlg_page::sb_adden, FALSE);
|
||||
}
|
||||
|
||||
int w = size.cx;
|
||||
hsb_ = w < desired_size().cx;
|
||||
if (!hsb_)
|
||||
{
|
||||
show_scroll_bar(SB_HORZ, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
size_view_.cx = w;
|
||||
show_scroll_bar(SB_HORZ, true);
|
||||
SetScrollRange(hwnd(), SB_HORZ, 0, desired_size().cx - w + dlg_page::sb_adden, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
|
|
@ -56,6 +56,7 @@ public:
|
|||
BOOL set_font(HFONT font);
|
||||
HFONT get_font(void);
|
||||
int get_string_width(const wchar_t* str);
|
||||
void show_scroll_bar(int bar = SB_VERT, bool show = true);
|
||||
};
|
||||
|
||||
class dlg_page : public dlg_base
|
||||
|
@ -88,7 +89,13 @@ class dlg_page : public dlg_base
|
|||
static int gap_x;
|
||||
static int gap_y;
|
||||
static int spin_w;
|
||||
static int sb_adden;
|
||||
|
||||
SIZE size_view_;
|
||||
int vsb_pos_;
|
||||
int hsb_pos_;
|
||||
bool vsb_;
|
||||
bool hsb_;
|
||||
|
||||
BOOL handle_message(UINT msg, WPARAM wp, LPARAM lp) override;
|
||||
void on_font_changed(void) override;
|
||||
|
@ -114,6 +121,8 @@ class dlg_page : public dlg_base
|
|||
int find_control_ind(HWND wnd);
|
||||
void control_action(HWND wnd);
|
||||
BOOL on_mouse_wheel(WORD vkey, short delta, short x, short y);
|
||||
void on_vscroll(int pos, int sb_ev);
|
||||
void on_hscroll(int pos, int sb_ev);
|
||||
|
||||
public:
|
||||
dlg_page(HWND parent, const wchar_t* name, LPSANEAPI api, SANE_Handle dev);
|
||||
|
@ -127,6 +136,7 @@ public:
|
|||
void hide(void);
|
||||
bool refresh(int sn, const SANE_Option_Descriptor* desc, void* cur_val);
|
||||
const wchar_t* name(void);
|
||||
void set_view_size(SIZE size);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -171,14 +171,26 @@ void dlg_setting::on_init_dialog(void)
|
|||
MoveWindow(tab_, r.left, r.top, r.right - r.left, y, TRUE);
|
||||
}
|
||||
|
||||
RECT desk = { 0 };
|
||||
int diff = 0;
|
||||
|
||||
GetClientRect(GetDesktopWindow(), &desk);
|
||||
GetWindowRect(hwnd(), &r);
|
||||
r.right += size.cx - (rme.right - rme.left);
|
||||
r.bottom += size.cy;
|
||||
if (r.bottom - r.top > desk.bottom - desk.top)
|
||||
{
|
||||
diff = (r.bottom - r.top) - (desk.bottom - desk.top) + 100;
|
||||
r.top = desk.top;
|
||||
r.bottom = desk.bottom - 100;
|
||||
}
|
||||
MoveWindow(hwnd(), r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE);
|
||||
|
||||
size.cy -= diff;
|
||||
for (int i = 0; page = get_page(i); ++i)
|
||||
{
|
||||
MoveWindow(page->hwnd(), 0, y, size.cx, size.cy - y, TRUE);
|
||||
page->set_view_size(size);
|
||||
}
|
||||
|
||||
GetWindowRect(get_item(IDC_BUTTON_SCAN), &r);
|
||||
|
|
21
sane/sane.rc
21
sane/sane.rc
|
@ -75,7 +75,7 @@ BEGIN
|
|||
END
|
||||
|
||||
IDD_PAGE DIALOGEX 0, 0, 258, 133
|
||||
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_SYSMENU
|
||||
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_SYSMENU
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
END
|
||||
|
@ -153,9 +153,9 @@ BEGIN
|
|||
IDD_PAGE, DIALOG
|
||||
BEGIN
|
||||
LEFTMARGIN, 7
|
||||
RIGHTMARGIN, 251
|
||||
RIGHTMARGIN, 240
|
||||
TOPMARGIN, 7
|
||||
BOTTOMMARGIN, 126
|
||||
BOTTOMMARGIN, 115
|
||||
END
|
||||
|
||||
IDD_AREA, DIALOG
|
||||
|
@ -248,8 +248,8 @@ END
|
|||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 4,25,10000,22259
|
||||
PRODUCTVERSION 4,25,10000,22259
|
||||
FILEVERSION 4,27,10000,22263
|
||||
PRODUCTVERSION 4,27,10000,22263
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
|
@ -264,14 +264,13 @@ BEGIN
|
|||
BEGIN
|
||||
BLOCK "080404b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", "宁波华高信息科技有限公司"
|
||||
VALUE "FileDescription", "华高扫描仪应用程序"
|
||||
VALUE "FileVersion", "4.25.10000.22259"
|
||||
VALUE "FileDescription", "扫描仪应用程序"
|
||||
VALUE "FileVersion", "4.27.10000.22263"
|
||||
VALUE "InternalName", "sane.dll"
|
||||
VALUE "LegalCopyright", "Copyright (C) HUAGOScan 2022"
|
||||
VALUE "LegalCopyright", "Copyright (C) Scan 2022"
|
||||
VALUE "OriginalFilename", "sane.dll"
|
||||
VALUE "ProductName", "HUAGOScan"
|
||||
VALUE "ProductVersion", "4.25.10000.22259"
|
||||
VALUE "ProductName", "Scan"
|
||||
VALUE "ProductVersion", "4.27.10000.22263"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
|
|
@ -257,7 +257,7 @@ void scanner::on_ui_event(int uev, void* sender)
|
|||
else
|
||||
{
|
||||
if (/*events_.count() > 5 && !is_ui_wait_img_ &&*/
|
||||
(uev == SANE_EVENT_UI_CLOSE_CANCEL || uev == SANE_EVENT_UI_CLOSE_NORMAL))
|
||||
(uev == SANE_EVENT_UI_CLOSE_CANCEL || uev == SANE_EVENT_UI_CLOSE_NORMAL || uev == SANE_EVENT_UI_CLOSE_SETTING))
|
||||
{
|
||||
events_.clear();
|
||||
ui_hide();
|
||||
|
|
Loading…
Reference in New Issue