/*[]=====================================================================[]*/ /*[] LeadTools Run Time Library - Version 14 []*/ /*[] []*/ /*[] []*/ /*[] Copyright (c) 1991-2005 by LEAD Technologies, Inc. []*/ /*[] All Rights Reserved. []*/ /*[]=====================================================================[]*/ #define STRICT #include #include #include "resource.h" #include "Twain.h" // Global variables L_TCHAR szFrameClass[] = TEXT ("MDIFrame"); L_TCHAR szChildClass[] = TEXT ("MDIBarChild"); HMENU hMenuInitWindow, hMenuChildWindow; HMENU hMenuInit, hMenuChild; HINSTANCE hInstMain; HWND hwndFrame, hwndClient; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HACCEL hAccel; MSG msg; WNDCLASS wndclass; hInstMain = hInstance; // Register the frame window class wndclass.style = 0; wndclass.lpfnWndProc = FrameWndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MAINFRAME)); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szFrameClass; if (!RegisterClass (&wndclass)) return 0; // Register the child window class wndclass.style = 0; wndclass.lpfnWndProc = ChildWndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = sizeof(HANDLE); wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CHILDFRAME)); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH); wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szChildClass; if (!RegisterClass (&wndclass)) return 0; // Obtain handles to three possible menus & submenus hMenuInit = LoadMenu (hInstance, MAKEINTRESOURCE(IDR_MAINFRAME)); hMenuChild = LoadMenu (hInstance, MAKEINTRESOURCE(IDR_CHILDFRAME)); hMenuInitWindow = GetSubMenu (hMenuInit, INIT_MENU_POS); hMenuChildWindow = GetSubMenu (hMenuChild, CHILD_MENU_POS); // Load accelerator table hAccel = LoadAccelerators (hInstance, MAKEINTRESOURCE(IDC_MAINACCEL)); // Create the frame window hwndFrame = CreateWindow(szFrameClass, TEXT ("TWAIN Demo"), WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, hMenuInit, hInstance, NULL); ShowWindow (hwndFrame, iCmdShow); UpdateWindow (hwndFrame); // Enter the modified message loop while (GetMessage (&msg, NULL, 0, 0)) { if ((!TranslateMDISysAccel (hwndClient, &msg)) && (!TranslateAccelerator (hwndFrame, hAccel, &msg))) { TranslateMessage(&msg); DispatchMessage(&msg); } } // Clean up by deleting unattached menus DestroyMenu (hMenuChild); return msg.wParam; } L_BOOL CALLBACK CloseEnumProc (HWND hwnd, LPARAM lParam) { if (GetWindow (hwnd, GW_OWNER)) // Check for icon title return TRUE; SendMessage (GetParent (hwnd), WM_MDIRESTORE, (WPARAM) hwnd, 0); if (!SendMessage (hwnd, WM_QUERYENDSESSION, 0, 0)) return TRUE; SendMessage (GetParent (hwnd), WM_MDIDESTROY, (WPARAM) hwnd, 0); return TRUE; } L_INT DoDialogBoxParam(L_INT nDialog, HWND hWnd, DLGPROC pfnDialog, LPARAM lParam) { DLGPROC pfn; L_INT nRet; pfn = (DLGPROC) MakeProcInstance((FARPROC) pfnDialog, hInstMain); nRet = DialogBoxParam (hInstMain, MAKEINTRESOURCE (nDialog), hWnd, pfn, lParam); FreeProcInstance((FARPROC) pfn); return(nRet); } L_BOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { UNREFERENCED_PARAMETER(lParam); switch (message) { case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: case IDCANCEL: EndDialog (hDlg, 0); return(TRUE); } } return(FALSE); } float Fix32ToFloat (TW_FIX32 * ptwFix) { float Floater = 0; Floater = (float)ptwFix->Whole + (float)ptwFix->Frac / (float)65536.0; return Floater; } TW_FIX32 FloatToFix32 (float Floater) { TW_FIX32 Fix32; TW_INT32 Int32 = (TW_INT32)(Floater * 65536.0 + 0.5); Fix32.Whole = (TW_INT16) (Int32 >> 16); Fix32.Frac = (TW_UINT16) (Int32 & 0x0000FFFFL); return Fix32; }