code_app/modules/twainui/twainui.h

80 lines
2.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <string>
#include <vector>
#include <functional>
#include "sane/sane_ex.h"
#include "base/HGDef.h"
#include <Windows.h>
typedef struct _dev_que
{
int id; // ID用户选中后返回该值
std::string name; // 设备名称
std::string sn; // 设备序列号
}DEVQUE;
// 功能: 选择多个同型设备中的一个,模态
//
// 参数: devs - 设备队列列表
//
// 返回: 用户选择的设备所对应的DEVQUE::id或者-1代表用户放弃选择设备
int choose_scanner(const std::vector<DEVQUE>& devs); // blocked. return selected DEVQUE::id or -1 if user cancelled
// 功能: 应用当前设备对应的用户配置,同步
//
// 参数: dev_name - 设备名称
//
// device - 设备打开的句柄
//
// api - sane_xxx API函数指针
//
// 返回: 当前设备配置方案的名称。返回指针通过调用函数twain_ui_free来释放
char* apply_current_config(const char* dev_name, SANE_Handle device, LPSANEAPI api);
// 功能: 释放由界面模块返回的动态分配的内存,同步
//
// 参数: buf - 内存地址
//
// 返回: 无
void twain_ui_free(void* buf);
enum ui_result
{
UI_RESULT_FAILED = -1, // 一般用于界面初始化失败
UI_RESULT_OK, // 界面正常显示
UI_RESULT_CLOSE_NORMAL, // 界面正常关闭
UI_RESULT_CLOSE_CANCEL, // 用户取消操作,如取消扫描……
UI_RESULT_START_SCAN, // 用户点击了开始扫描
};
// 功能: 释放由界面模块返回的动态分配的内存,模态
//
// 参数: device - 当前打开的设备句柄
//
// parent - 父窗口句柄
//
// api - sane_xxx API函数指针
//
// with_scan - 是否显示“扫描”按钮
//
// 返回: ui_result 类型, UI_RESULT_CLOSE_NORMAL or UI_RESULT_START_SCAN
int show_setting_ui(SANE_Handle device, HWND parent, LPSANEAPI api, bool with_scan/*是否显示“扫描”按钮*/);
// 功能: 显示扫描进度界面,非模态
//
// 参数: parent - 父窗口句柄
//
// callback - 用户界面操作事件回调(主要为取消扫描事件)
//
// notify - ui接收进度通知函数外部通过该返回的函数来通知当前扫描进度或事件
// notify events: SANE_EVENT_WORKING - void*: unused, be NULL, flag - unused, be 0
// SANE_EVENT_SCAN_FINISHED - void*: (utf8*)message, flag - error code (0 is success)
// SANE_EVENT_USB_DATA_RECEIVED- void* unused, be NULL, flag - unused, be 0
// SANE_EVENT_IMAGE_OK - void* unused, be NULL, flag - unused, be 0
//
// 返回: ui_result 类型, UI_RESULT_FAILED or UI_RESULT_OK
int show_progress_ui(HWND parent, std::function<void(ui_result)> callback, std::function<void(int/*event*/, void*/*msg*/, int/*flag*/)>* notify);