#pragma once #include #include #include #include #include #include // CDlgIndicator 对话框 #define WM_REFRESH_OPTION WM_USER + 111 // WPARAM: source option SN, LPARAM: unused now enum ui_event { UI_EVENT_CLOSE_NORMAL = 0, UI_EVENT_CLOSE_CANCEL, UI_EVENT_BEGIN_SCANNING, }; extern HMODULE g_my_inst; class dlg_base { protected: HWND hwnd_; HWND parent_; UINT idd_; static std::wstring prop_name; static BOOL CALLBACK dlg_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp); virtual BOOL handle_message(UINT msg, WPARAM wp, LPARAM lp); virtual void on_font_changed(void); void create(void); public: dlg_base(HWND parent, UINT idd); virtual ~dlg_base(); 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 public: HWND hwnd(void); void screen_2_client(LPRECT r); void client_2_screen(LPRECT r); HWND get_item(UINT id); BOOL set_font(HFONT font); HFONT get_font(void); int get_string_width(const wchar_t* str); }; class dlg_page : public dlg_base { std::wstring name_; SIZE size_; UINT ctrl_id_; POINT pos_; SANEAPI sane_; SANE_Handle dev_; bool done_; std::vector ctrls_; int id_dpi_; float dpi_; int id_paper_; std::wstring paper_; int id_custom_area_; int id_custom_left_; int id_custom_right_; int id_custom_top_; int id_custom_bottom_; int id_custom_gamma_; static std::wstring property_type; static std::wstring property_host; static std::wstring property_size; static UINT dyn_id_base; static int gap_x; static int gap_y; static int spin_w; BOOL handle_message(UINT msg, WPARAM wp, LPARAM lp) override; void on_font_changed(void) override; HWND create_label(int sn, const wchar_t* title, int x, int y, SIZE size); HWND create_slider(int sn, int x, int y, double lower, double upper, double step, double pos, LPSIZE size, bool is_double); HWND create_edit(int sn, int x, int y, int h, int w = 50); HWND create_combox(int sn, int x, int y, std::vector& vals, const wchar_t* cur_val, LPSIZE size); HWND create_spin(int sn, HWND edit, double pos, double lower, double upper, bool is_double); HWND create_control_bool(int sn, const SANE_Option_Descriptor* desc, void* cur_val, const wchar_t* title, LPSIZE text_size); HWND create_control_int(int sn, const SANE_Option_Descriptor* desc, void* cur_val, const wchar_t* title, LPSIZE text_size); HWND create_control_float(int sn, const SANE_Option_Descriptor* desc, void* cur_val, const wchar_t* title, LPSIZE text_size); HWND create_control_string(int sn, const SANE_Option_Descriptor* desc, void* cur_val, const wchar_t* title, LPSIZE text_size); HWND create_control_button(int sn, const SANE_Option_Descriptor* desc, void* cur_val, const wchar_t* title, LPSIZE text_size); void handle_command(WORD code, WORD id, HANDLE ctrl); BOOL on_notify(int ctrl_id, LPNMHDR pnmh); void* value_from_ctrl(HWND ctrl, SANE_Value_Type* type); // call free_ctrl_value to free the returned value, data according to SANE-standard void set_ctrl_value(HWND ctrl, SANE_Value_Type type, void* val, bool only_me, bool skip_ctrl = false); void free_ctrl_value(void* val); int find_control_ind(HWND wnd); void control_action(HWND wnd); BOOL on_mouse_wheel(WORD vkey, short delta, short x, short y); public: dlg_page(HWND parent, const wchar_t* name, LPSANEAPI api, SANE_Handle dev); ~dlg_page(); public: bool add_control(int sn, const SANE_Option_Descriptor* desc, void* cur_val); void add_control_done(void); SIZE desired_size(void); void show(void); void hide(void); bool refresh(int sn, const SANE_Option_Descriptor* desc, void* cur_val); const wchar_t* name(void); };