⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scan.c

📁 清华紫光twain扫描仪编程接口范例
💻 C
字号:

// UNISCAN windows scanning program
// Tsinghua Unisplendour Group
// Programmed in MS VC/C++
// Daohong Kan, Aug.23, 1996
// Source files: SCAN.C, TWAIN.C, SCAN.H, TWAIN.H, RESOURCE.H,
//               SCAN.RC, SCAN.DEF, SCAN.MAK

#include "windows.h"
#include "scan.h"
#include "twain.h"

HANDLE hInst;
HWND   hWnd;

extern HANDLE       hDSMLib;
extern DSMENTRYPROC pDSMEntry;
extern TW_IDENTITY AppID, ScannerID;
extern char dsmOpened, dsOpened;

void UNMessageBox(char *);
extern UNLoadDSM();
extern UNSelectSource();
extern UNOpenDS();
extern UNNegotiateCap();
extern UNEnableDS();
extern UNGetImage();
extern UNCloseDS();
extern UNCloseDSM();

int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow)
    {
    MSG msg;
    TW_EVENT twEvent;
    TW_UINT16 rc;

    if (!hPrevInstance)          /* Other instances of app running? */
        {
        if (!InitApplication(hInstance)) /* Initialize shared things */
            return (FALSE);
        }
    if (!InitInstance(hInstance, nCmdShow))
        return (FALSE);
        
    while (GetMessage(&msg, NULL, 0, 0))
        {
        rc = TWRC_NOTDSEVENT;
        if (dsOpened == 'Y')    // Source is enabled
            {
            twEvent.pEvent = (TW_MEMREF)&msg;
            twEvent.TWMessage = MSG_NULL;
            rc = (*pDSMEntry)(&AppID, &ScannerID, DG_CONTROL, DAT_EVENT,
                                      MSG_PROCESSEVENT, (TW_MEMREF)&twEvent);
            switch(twEvent.TWMessage)
                {
            case MSG_XFERREADY:
                UNGetImage();
//                UNCloseDS();
                break;
            case MSG_CLOSEDSREQ:
                UNCloseDS();
                break;
            default:
                break;
                }
            }
        if (rc != TWRC_DSEVENT)
            {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
            }
        }
    return (msg.wParam);       /* Returns the value from PostQuitMessage */
    }

BOOL InitApplication(HANDLE hInstance)
    {
    WNDCLASS  wc;

    wc.style         = 0;
    wc.lpfnWndProc   = MainWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = GetStockObject(WHITE_BRUSH);
    wc.lpszMenuName  = "GenericMenu";
    wc.lpszClassName = "GenericWClass";
    return (RegisterClass(&wc));
    }

BOOL InitInstance(HANDLE hInstance, int nCmdShow)
    {
    hInst = hInstance;
    hWnd = CreateWindow("GenericWClass", "Generic Sample Application",
                  WS_OVERLAPPEDWINDOW,
                  CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                  NULL, NULL, hInstance, NULL);
    if (!hWnd)
        return (FALSE);
    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);
    UNLoadDSM();    // Load & Open DSM
    return (TRUE);
    }

long CALLBACK  MainWndProc(HWND hWnd, UINT message,
                                   WPARAM wParam, LPARAM lParam)
    {
    switch (message)
        {
    case WM_COMMAND:       /* message: command from application menu */
        switch (wParam)
            {
        case UN_SELECT_SOURCE:
            if (dsmOpened == 'Y')
                UNSelectSource();
            break;
            
        case UN_ACQUIRE:
            if (dsmOpened == 'Y')
                UNOpenDS();
            if (dsOpened == 'Y')
                {
                UNNegotiateCap();
                UNEnableDS();
                }
            break;
            
        case UN_XFERDONE:
            break;
            
        case UN_ABOUT:
            DialogBox(hInst, "AboutBox", hWnd, About);
            break;
            
        default:                        /* Lets Windows process it   */
            return (DefWindowProc(hWnd, message, wParam, lParam));
            }
        break;
        
//    case WM_PAINT:
//        break;

    case WM_DESTROY:          /* message: window being destroyed */
        if (dsOpened == 'Y')
            UNCloseDS();
        if (dsmOpened == 'Y')
            UNCloseDSM();
        PostQuitMessage(0);
        break;

    default:                  /* Passes it on if unproccessed    */
        return (DefWindowProc(hWnd, message, wParam, lParam));
        }
    return 0L;
    }

BOOL  CALLBACK About(HWND hDlg, unsigned message,
                             WORD wParam, LONG lParam)
    {
    switch (message)
        {
    case WM_INITDIALOG:            /* message: initialize dialog box */
        return (TRUE);

    case WM_COMMAND:               /* message: received a command */
        if (wParam == IDOK || wParam == IDCANCEL)
            {
            EndDialog(hDlg, TRUE); /* Exits the dialog box        */
            return (TRUE);
            }
        break;
        }
    return (FALSE);
    }

void UNMessageBox(char *Context)
    {
    MessageBox(hWnd, Context, "Message Board", MB_OK|MB_SYSTEMMODAL|MB_ICONEXCLAMATION);
    }
    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -