// Starts decoding of the new bitmap. If previous decoding is still running, // it will be stopped and all intermediate results will be discarded. void Startbitmapdecoding(t_procdata *pdata,uchar *data,int sizex,int sizey) { // Free resources allocated for the previous bitmap. User may want to // browse bitmap while and after it is processed. Freeprocdata(pdata); memset(pdata,0,sizeof(t_procdata)); pdata->data=data; pdata->sizex=sizex; pdata->sizey=sizey; pdata->blockborder=0.0; // Autoselect pdata->step=1; if (bestquality) pdata->mode|=M_BEST; Updatebuttons(); };
// Main PaperBack program. int PASCAL WinMain(HINSTANCE hi,HINSTANCE hprev,LPSTR cmdline,int show) { int dx,dy,isbitmap; char path[MAXPATH],drv[MAXDRIVE],dir[MAXDIR],fil[MAXFILE]; char s[TEXTLEN],inifile[MAXPATH]; WNDCLASS wc; MSG msg; TW_UINT16 result; // Save the instance. hinst=hi; // Very Advanced Controls like Magnificious Supertabs are used here. InitCommonControls(); // Create custom GDI objects. graybrush=CreateSolidBrush(GetSysColor(COLOR_3DFACE)); // Create name of initialization file. GetModuleFileName(NULL,path,MAXPATH); fnsplit(path,drv,dir,fil,NULL); fnmerge(inifile,drv,dir,fil,".ini"); // Get settings from the initialization file. GetPrivateProfileString("Settings","Infile","",infile,MAXPATH,inifile); GetPrivateProfileString("Settings","Inbmp","",inbmp,MAXPATH,inifile); GetPrivateProfileString("Settings","Outfile","",outfile,MAXPATH,inifile); GetPrivateProfileString("Settings","Outbmp","",outbmp,MAXPATH,inifile); dpi=GetPrivateProfileInt("Settings","Raster",200,inifile); dotpercent=GetPrivateProfileInt("Settings","Dot size",70,inifile); compression=GetPrivateProfileInt("Settings","Compression",2,inifile); redundancy=GetPrivateProfileInt("Settings","Redundancy",5,inifile); printheader=GetPrivateProfileInt("Settings","Header and footer",1,inifile); printborder=GetPrivateProfileInt("Settings","Border",0,inifile); autosave=GetPrivateProfileInt("Settings","Autosave",1,inifile); bestquality=GetPrivateProfileInt("Settings","Best quality",1,inifile); encryption=GetPrivateProfileInt("Settings","Encryption",0,inifile); opentext=GetPrivateProfileInt("Settings","Open password",0,inifile); // Get printer's page size. marginunits=GetPrivateProfileInt("Settings","Margin units",0,inifile); marginleft=GetPrivateProfileInt("Settings","Margin left",1000,inifile); marginright=GetPrivateProfileInt("Settings","Margin right",400,inifile); margintop=GetPrivateProfileInt("Settings","Margin top",400,inifile); marginbottom=GetPrivateProfileInt("Settings","Margin bottom",500,inifile); // Register class of main window. wc.style=CS_OWNDC; wc.lpfnWndProc=Mainwp; wc.cbClsExtra=wc.cbWndExtra=0; wc.hInstance=hinst; wc.hIcon=LoadIcon(hinst,"ICON_MAIN"); wc.hCursor=LoadCursor(NULL,IDC_ARROW); wc.hbrBackground=graybrush; wc.lpszMenuName=NULL; wc.lpszClassName=MAINCLASS; if (!RegisterClass(&wc)) return 1; // Create main window. It will accept drag-and-drop files. dx=min(GetSystemMetrics(SM_CXSCREEN),MAINDX); dy=min(GetSystemMetrics(SM_CYSCREEN),MAINDY); hmenu=LoadMenu(hinst,"MENU_MAIN"); hwmain=CreateWindowEx( WS_EX_ACCEPTFILES, MAINCLASS,"PaperBack", WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX| WS_CLIPCHILDREN|WS_VISIBLE, CW_USEDEFAULT,CW_USEDEFAULT,dx,dy, NULL,hmenu,hinst,NULL); if (hwmain==NULL) return 1; // Create controls in the window. if (Createcontrols()!=0) return 1; // Load TWAIN interface. Failure is not critical - we still can print data! twainstate=1; if (LoadTWAINlibrary()==0) { EnableMenuItem(hmenu,M_FILE_SELECT,MF_BYCOMMAND|MF_GRAYED); EnableMenuItem(hmenu,M_FILE_ACQUIRE,MF_BYCOMMAND|MF_GRAYED); }; Updatebuttons(); // Initialize printer settings. Initializeprintsettings(); // And now, the main Windows loop. while (1) { // Check if there are some unprocessed Windows messages and process them at // once. while (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { // Pass all messages to the TWAIN interface. result=TWRC_NOTDSEVENT; if (twainstate>=5) result=(TW_UINT16)PassmessagetoTWAIN(&msg); // If message was not processed by TWAIN, it must be processed by // the application. if (result==TWRC_NOTDSEVENT) { // Pass keyboard messages first to block display. if (msg.message!=WM_KEYDOWN || Changeblockselection(msg.wParam)==1) { TranslateMessage(&msg); DispatchMessage(&msg); }; }; }; if (msg.message==WM_QUIT) break; // Execute next steps of data decoding and file printing. if (procdata.step!=0) Nextdataprocessingstep(&procdata); else if (printdata.step!=0) Nextdataprintingstep(&printdata); // Some TWAIN drivers require very frequent calls when scanning, don't // sleep. if (twainstate>=5) continue; // Check whether new printing or decoding task can be executed. if (procdata.step==0 && printdata.step==0) { isbitmap=Getfilefromqueue(path); if (isbitmap==0) Printfile(path,NULL); else if (isbitmap==1) Decodebitmap(path); }; // If we have nothing to do, be kind to other applications. if (twainstate<5 && procdata.step==0 && printdata.step==0 && GetQueueStatus(QS_ALLINPUT)==0 ) { Sleep(1); // Reduces CPU time practically to zero }; }; // Save settings to the initialization file. WritePrivateProfileString("Settings","Infile",infile,inifile); WritePrivateProfileString("Settings","Inbmp",inbmp,inifile); WritePrivateProfileString("Settings","Outfile",outfile,inifile); WritePrivateProfileString("Settings","Outbmp",outbmp,inifile); sprintf(s,"%i",dpi); WritePrivateProfileString("Settings","Raster",s,inifile); sprintf(s,"%i",dotpercent); WritePrivateProfileString("Settings","Dot size",s,inifile); sprintf(s,"%i",compression); WritePrivateProfileString("Settings","Compression",s,inifile); sprintf(s,"%i",redundancy); WritePrivateProfileString("Settings","Redundancy",s,inifile); sprintf(s,"%i",printheader); WritePrivateProfileString("Settings","Header and footer",s,inifile); sprintf(s,"%i",printborder); WritePrivateProfileString("Settings","Border",s,inifile); sprintf(s,"%i",autosave); WritePrivateProfileString("Settings","Autosave",s,inifile); sprintf(s,"%i",bestquality); WritePrivateProfileString("Settings","Best quality",s,inifile); sprintf(s,"%i",encryption); WritePrivateProfileString("Settings","Encryption",s,inifile); sprintf(s,"%i",opentext); WritePrivateProfileString("Settings","Open password",s,inifile); // Save printer's page size. if (pagesetup.Flags & PSD_INTHOUSANDTHSOFINCHES) marginunits=1; else if (pagesetup.Flags & PSD_INHUNDREDTHSOFMILLIMETERS) marginunits=2; else marginunits=0; if (marginunits) { sprintf(s,"%i",marginunits); WritePrivateProfileString("Settings","Margin units",s,inifile); sprintf(s,"%i",pagesetup.rtMargin.left); WritePrivateProfileString("Settings","Margin left",s,inifile); sprintf(s,"%i",pagesetup.rtMargin.right); WritePrivateProfileString("Settings","Margin right",s,inifile); sprintf(s,"%i",pagesetup.rtMargin.top); WritePrivateProfileString("Settings","Margin top",s,inifile); sprintf(s,"%i",pagesetup.rtMargin.bottom); WritePrivateProfileString("Settings","Margin bottom",s,inifile); ; }; // Clear password. It's a bad idea to keep password in the swap file after // shutdown. memset(password,0,sizeof(password)); // Clean up. Freeprocdata(&procdata); Stopprinting(&printdata); CloseTWAINmanager(); CloseTWAINlibrary(); Closeprintsettings(); // Destroy objects. DeleteObject(graybrush); return 0; };