151 lines
3.8 KiB
C++
151 lines
3.8 KiB
C++
// DlgIndicator.cpp: 实现文件
|
|
//
|
|
|
|
#include "DlgIndicator.h"
|
|
#include "resource.h"
|
|
#include "scanned_img.h" // for local_trans
|
|
|
|
// CDlgIndicator 对话框
|
|
#define WM_SCAN_WORKING WM_USER + 1 // WPARAM: unused; LPARAM: unsed
|
|
#define WM_USB_PACKET_RECEIVED WM_USER + 2 // WPARAM: unused; LPARAM: unsed
|
|
#define WM_IMAGE_RECEIVED WM_USER + 3 // WPARAM: unused; LPARAM: unsed
|
|
#define WM_SCAN_FINISHED WM_USER + 4 // WPARAM: std::string* msg; LPARAM: boo err
|
|
|
|
|
|
dlg_indicator::dlg_indicator(HWND parent) : dlg_base(parent, IDD_INDICATOR)
|
|
, papers_(0), images_(0), err_(false)
|
|
{
|
|
create();
|
|
SetWindowLongW(GetDlgItem(hwnd_, IDC_STATIC_ERR), GWL_STYLE, GetWindowLong(GetDlgItem(hwnd_, IDC_STATIC_ERR), GWL_STYLE) | SS_OWNERDRAW);
|
|
}
|
|
dlg_indicator::~dlg_indicator()
|
|
{
|
|
}
|
|
|
|
|
|
BOOL dlg_indicator::handle_message(UINT msg, WPARAM wp, LPARAM lp)
|
|
{
|
|
wchar_t text[40] = { 0 };
|
|
BOOL ret = TRUE;
|
|
|
|
switch (msg)
|
|
{
|
|
case WM_INITDIALOG:
|
|
swprintf_s(text, _countof(text) - 1, L"%u", papers_);
|
|
SetDlgItemTextW(hwnd_, IDC_EDIT_IMAGE, text);
|
|
SetDlgItemTextW(hwnd_, IDC_EDIT_PAPER, text);
|
|
UpdateWindow(hwnd_);
|
|
break;
|
|
case WM_USB_PACKET_RECEIVED:
|
|
papers_++;
|
|
swprintf_s(text, _countof(text) - 1, L"%u", papers_);
|
|
SetDlgItemTextW(hwnd_, IDC_EDIT_PAPER, text);
|
|
UpdateWindow(hwnd_);
|
|
break;
|
|
case WM_IMAGE_RECEIVED:
|
|
images_++;
|
|
swprintf_s(text, _countof(text) - 1, L"%u", images_);
|
|
SetDlgItemTextW(hwnd_, IDC_EDIT_IMAGE, text);
|
|
UpdateWindow(hwnd_);
|
|
break;
|
|
case WM_COMMAND:
|
|
handle_command(HIWORD(wp), LOWORD(wp), (HWND)lp);
|
|
break;
|
|
case WM_DRAWITEM:
|
|
if (wp == IDC_STATIC_ERR)
|
|
{
|
|
DRAWITEMSTRUCT* ds = (DRAWITEMSTRUCT*)lp;
|
|
wchar_t text[128] = { 0 };
|
|
SetTextColor(ds->hDC, err_ ? RGB(255, 0, 0) : RGB(0, 0, 0));
|
|
SetBkMode(ds->hDC, TRANSPARENT);
|
|
GetWindowTextW(ds->hwndItem, text, _countof(text) - 1);
|
|
TextOutW(ds->hDC, 0, 0, text, lstrlenW(text));
|
|
}
|
|
ret = FALSE;
|
|
break;
|
|
case WM_SCAN_WORKING:
|
|
notify_ui_event(SANE_EVENT_WORKING);
|
|
break;
|
|
case WM_SCAN_FINISHED:
|
|
if (lp)
|
|
{
|
|
std::string* str = (std::string*)wp;
|
|
std::wstring err(local_trans::a2u(str->c_str(), CP_UTF8));
|
|
|
|
SetDlgItemTextW(hwnd_, IDC_STATIC_ERR, err.c_str());
|
|
delete str;
|
|
}
|
|
else
|
|
{
|
|
wchar_t msg[128] = { 0 };
|
|
std::string* str = (std::string*)wp;
|
|
swprintf_s(msg, _countof(msg) - 1, L"\u603b\u8ba1\u626b\u63cf\u56fe\u7247\uff1a%u \u5f20", images_);
|
|
|
|
SetDlgItemTextW(hwnd_, IDC_STATIC_ERR, msg);
|
|
delete str;
|
|
SetTimer(hwnd_, 1, 3000, NULL);
|
|
}
|
|
SetDlgItemTextW(hwnd_, IDCANCEL, L"\u5173\u95ed");
|
|
ShowWindow(GetDlgItem(hwnd_, IDC_STATIC_PAPER), SW_HIDE);
|
|
ShowWindow(GetDlgItem(hwnd_, IDC_STATIC_IMAGE), SW_HIDE);
|
|
ShowWindow(GetDlgItem(hwnd_, IDC_EDIT_PAPER), SW_HIDE);
|
|
ShowWindow(GetDlgItem(hwnd_, IDC_EDIT_IMAGE), SW_HIDE);
|
|
ShowWindow(GetDlgItem(hwnd_, IDC_STATIC_ERR), SW_SHOW);
|
|
SetWindowTextW(hwnd_, L"\u626b\u63cf\u7ed3\u675f");
|
|
UpdateWindow(hwnd_);
|
|
break;
|
|
case WM_TIMER:
|
|
if (wp == 1)
|
|
{
|
|
KillTimer(hwnd_, wp);
|
|
notify_over(false);
|
|
break;
|
|
}
|
|
default:
|
|
ret = FALSE;
|
|
break;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
void dlg_indicator::handle_command(WORD code, WORD id, HANDLE ctrl)
|
|
{
|
|
if (id == IDCANCEL)
|
|
{
|
|
notify_over(true);
|
|
}
|
|
}
|
|
void dlg_indicator::notify_over(bool cancel)
|
|
{
|
|
notify_ui_event(cancel ? SANE_EVENT_UI_CLOSE_CANCEL : SANE_EVENT_UI_CLOSE_NORMAL);
|
|
}
|
|
|
|
HWND dlg_indicator::window(void)
|
|
{
|
|
return hwnd_;
|
|
}
|
|
HWND dlg_indicator::parent(void)
|
|
{
|
|
return parent_;
|
|
}
|
|
void dlg_indicator::notify_data_arrived(bool image)
|
|
{
|
|
PostMessage(hwnd_, image ? WM_IMAGE_RECEIVED : WM_USB_PACKET_RECEIVED, 0, 0);
|
|
}
|
|
void dlg_indicator::notify_scan_over(const char* msg, bool err)
|
|
{
|
|
std::string* mstr(new std::string(msg ? msg : ""));
|
|
|
|
err_ = err;
|
|
if (!PostMessage(hwnd_, WM_SCAN_FINISHED, (WPARAM)mstr, (LPARAM)err))
|
|
{
|
|
delete mstr;
|
|
notify_over(false);
|
|
}
|
|
}
|
|
void dlg_indicator::notify_working(void)
|
|
{
|
|
PostMessage(hwnd_, WM_SCAN_WORKING, 0, 0);
|
|
}
|
|
// CDlgIndicator 消息处理程序
|