1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
void CactwainDlg::OnBnClickedButton1()
{
if (TWAIN_IsAvailable())
{
if (hBmp!=NULL)
DeleteObject(hBmp);
int ss;
ss=TWAIN_SelectImageSource(this->GetSafeHwnd());
// TODO: Add your control notification handler code here
HANDLE hdib=TWAIN_AcquireNative(this->GetSafeHwnd(),TWAIN_ANYTYPE);
if (hdib==NULL)
return;
int h=TWAIN_DibHeight(hdib);
int w=TWAIN_DibWidth(hdib);
hBmp=::CreateBitmap(w,h,1,32,NULL);
HDC dcm=::CreateCompatibleDC(NULL);
SelectObject(dcm,hBmp);
TWAIN_DrawDibToDC(dcm,0,0,w,h,hdib,8,8);
DeleteDC(dcm);
TWAIN_FreeNative(hdib);
TWAIN_CloseSource();
}
void CactwainDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
HDC dcmem=CreateCompatibleDC(NULL);
if (hBmp!=NULL)
{
SelectObject(dcmem,hBmp);
BITMAP bi;
GetObject(hBmp,sizeof(BITMAP),&bi);
PAINTSTRUCT ps;
HDC dc=::BeginPaint(this->GetSafeHwnd(),&ps);
//TWAIN_DrawDibToDC(dc,0,64,w,h,hBmp,8,8);
BitBlt(dc,0,64,bi.bmWidth,bi.bmHeight,dcmem,0,0,SRCCOPY);
::EndPaint(this->GetSafeHwnd(),&ps);
}
DeleteDC(dcmem);
CDialog::OnPaint();
}
} |
Partager