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

📄 twd_slb.cpp

📁 又VC++实现的基于TWAIN的扫描仪图像输入处理软件
💻 CPP
字号:
/***********************************************************************
 TWAIN Sample Source:
*************************************************************************/ 

#include <windows.h>
#include <stdlib.h>
#include <string.h>
#ifdef WIN32
#include <windowsx.h>
#endif

#include "twd_lb.h"
#include "stdafx.h"
#include "twain.h"
#include "twd_type.h"


#define  TW_FILENAME        500
#define  TW_DIRECTORY       501
#define  TW_FILES           502
#define  TW_DIRECTORIES     503
#define  TW_LB_FILENAMES    504
#define  TW_LB_DIRECTORIES  505
#define  TW_OKAY            506
#define  TW_CANCEL          507
#define  TW_FILETYPE        508
#define  TW_BMP             600
#define  TW_TIFF            601

#define    MAXFILENAME    80

extern void LogMessage(char msg[]);

// Globals
char    DisplayFileName [MAXFILENAME];    // for list box result return
BOOL timerflag = FALSE;

// Externals
extern HANDLE hImageDlg;
extern UINT TimerOut;

//  SDH - 02/03/95: NULL under C with this compiler is void* not 0 which causes a
//  compiler warning.  Rather than change every line, we kludge this here.
#ifdef NULL
#undef NULL                      
#endif
#define NULL 0

/***************************************************************************
 * FUNCTION: open_file_LB
 * 
 * ARGS:    std windows call back function args.
 * 
 * RETURNS: BOOL
 *
 * NOTES: This a dialog box which allows the user to browse the system for 
 * files of a type apporpriate to the application at hand.  You may change 
 * disks, dir's or file type.
 */

#ifdef WIN32
LRESULT CALLBACK open_file_LB (HWND hdlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
#else	//16 bit version
BOOL FAR PASCAL _export open_file_LB (HWND hdlg, WORD wMsg, WORD wParam, LONG lParam)
#endif
{
    static char list[MAXFILENAME];
    static char wild_list[MAXFILENAME];
  
    #define DEFAULT_EXT (int)0     // ; or *.BMP
    char *ext_table[] = {"*.BMP","*.TIFF"};
    
  /*  switch (wMsg)
	{
        case WM_CLOSE:
    	    // ask the application to close us ??   
        	#ifdef DEBUG
            	MessageBox (hdlg, "Help child is committing suicide!! Got a WM_CLOSE message.", "Source Debug", MB_OK);
	        #endif
    	    NotifyCloseDSReq ();
        	break;
		
        case WM_INITDIALOG:
			// if the autotests are running, there will be a temp file in the
			// windows directory called xfer.$$$.  This file will hold the name
			// of the file to be acquired.  The dialog will exit before drawing
			// and after sending an XferReady message to the source
			GetWindowsDirectory(temp,MAX_TWPATH);  
			lstrcat(temp,"\\xfer.$$$");
			if ((hfile = OpenFile(temp,&of,OF_READ))!=HFILE_ERROR)
			{
				memset(DisplayFileName,'\0',MAXFILENAME);
				_lread(hfile,buf,MAX_TWPATH+20);  
				lstrcpyn(DisplayFileName,strtok(buf,","),sizeof(DisplayFileName));
				TimerOut = atoi(strtok(NULL,","));
				
				_lclose(hfile);
				OpenFile(temp,&of,OF_DELETE);
				
				SetTimer(hdlg,1,TimerOut,NULL);
				timerflag = TRUE;
				
				// fill in the edit fields
				SetWindowText(GetDlgItem(hdlg,TW_FILENAME),DisplayFileName);
			}

    	    // init dir and file list boxes show/select the default file type 
        	lstrcpy (wild_list, ext_table[DEFAULT_EXT]);

	        // show file/directory lists 
    	    DlgDirList (hdlg,wild_list,TW_LB_DIRECTORIES,TW_DIRECTORY,0xC010);
        	DlgDirList (hdlg,wild_list,TW_LB_FILENAMES,NULL,0);
        
    	    // define filename box & fill 
			hCtl = GetDlgItem (hdlg, TW_FILENAME);
        	SendMessage (hCtl,EM_LIMITTEXT,MAXFILENAME,0);
                     
	        SendMessage (hCtl,WM_SETTEXT,0,(long)(LPSTR)wild_list);
            
			#ifdef WIN32
				SendMessage (hCtl,EM_SETSEL,0,MAXFILENAME);
			#else     //GR: 16 bit version
				SendMessage (hCtl,EM_SETSEL,0,MAKELONG (0, MAXFILENAME));
			#endif

        	//punch up extension type Check the default radio button 
			hCtl = GetDlgItem (hdlg, TW_BMP);
        	SendMessage (hCtl,BM_SETCHECK,1,0L);
                     
        	// Be sure to uncheck all other radio buttons!  If you do not, tabbing through
           	// the LB will reach .TIFF button, putting *.TIFF into filename but NOT checking
           	// the radio button. 
			//
           	// Click on a radio button unchecks all others but this start up problem is not
           	// covered.  Yeah, I could have used CheckRadioButton too. 
         
			hCtl = GetDlgItem (hdlg, TW_TIFF);
        	SendMessage (hCtl,BM_SETCHECK,0,0L);
            
  		    break;
		
		case WM_TIMER:
			if (timerflag)
			{
				if ((OpenFile(DisplayFileName, &of, OF_EXIST))!=HFILE_ERROR)
				{   
					LogMessage("WM_TIMER  xferready\r\n");
					
					// Send message back to the application that we are ready 
	  	    		NotifyXferReady();
					// following xfer, the app will remove the source				
				}
				// if the app closes after the transaction, this is not needed
				NotifyCloseDSReq ();
				timerflag = FALSE;
			}
			break;

		case WM_COMMAND:
    	{
        	//  SDH - 02/06/95 - wNotify up top for consistency with C convention.
	        //  hCtl is duplicated from above.
		    //  WORD wNotify;
	    	//  HWND hCtl;

			#ifdef WIN32
				wNotify = GET_WM_COMMAND_CMD (wParam, lParam);
				hCtl =    GET_WM_COMMAND_HWND (wParam, lParam);
                id = GET_WM_COMMAND_ID (wParam, lParam);
			#else     //GR: 16 bit version
				wNotify = HIWORD(lParam);
				hCtl =    LOWORD(lParam);
                id = wParam;
			#endif
		
			switch (id)
			{
				case TW_OKAY:
			        
			        LogMessage("OnOK handler\r\n");

			        // try to open "filename" file 
		    	    From_List:
		    		SendMessage (GetDlgItem (hdlg, TW_FILENAME),
 	        			 	WM_GETTEXT,
 	                   	 	MAXFILENAME,
 	                   	 	(LONG)(LPSTR)list);

					if ((OpenFile(list, &of, OF_EXIST))!=-1)
					{
						LogMessage("TW_OKAY xferready\r\n");
						
						lstrcpy (DisplayFileName, list);  // return the filename 
		  	       		// Send message back to the application that we are ready 
  	    		  		NotifyXferReady();
						// following xfer, the app will remove the source				
					}
					// if the app closes after the transaction, this is not needed
					// NotifyCloseDSReq ();
					break;

				case TW_CANCEL:
   					// ask the application to close us ??
					#ifdef DEBUG
						MessageBox (hdlg, "Too late, child suicide.  TW_CANCEL message.", "Source Debug", MB_OK);
					#endif
			    	NotifyCloseDSReq ();
   					break;


				// handle radio buttons
		        // The radio buttons stand for file extensions.  So when the extension
		        // is change rebuild the file list box.
				//
		        // NOTE: the file extensions are in a table indexed via ID
		        // NOTE: the extension radio buttons MUST be sequentially numbered
		        // for use of CheckRadioButton.  Although I do not use the routine
		        // since the default button handler does just fine with checking and
		        // unchecking. Default == EN_CHANGE ??
				//
		        // Virgins are in lower case, after the 1st go to upper case by DlgDirList.
			    
				case TW_BMP:
				case TW_TIFF:
				    // The following lines are here as a reminder of a past bug.  The Borland
			        // C compiler generates code which allows the first to lines to pass while
			        // the third will fail.  The reason, assume DS==SS based on the default for
		    	    // the memory model is NOT good enough in a DLL.  The use of assume DS==SS
		        	// NEVER will cause the compiler to generate the correct code.
					//
			        // 1).  lstrcpy (wild_list, "PIZ");
			        // 2).  lstrcpy (wild_list, ext_table[4]);
					// 3).  lstrcpy (wild_list, ext_table[wParam-TW_BMP]);
					//
			    
				    lstrcpy (wild_list, ext_table[wParam-TW_BMP]);
		
				    SendMessage (GetDlgItem(hdlg, TW_FILENAME),
			                WM_SETTEXT,
 				            0,
							(long)(LPSTR)wild_list);
    						DlgDirList (hdlg,
                			wild_list,
					 		TW_LB_FILENAMES,
                			NULL,
                			0);

    				break;
    
				case TW_LB_FILENAMES:
    				// punch up selected file into filename box 
    				if (wNotify==LBN_SELCHANGE)
    				{

						#ifdef WIN32
							DlgDirSelectEx (hdlg,
								list,
								sizeof (list),
								TW_LB_FILENAMES);
						#else     //GR: 16 bit version
							DlgDirSelect (hdlg,
						    	list,
						      	TW_LB_FILENAMES);
						#endif
						SendMessage (GetDlgItem(hdlg, TW_FILENAME),
                     		 	 WM_SETTEXT,
                     		 	 0,
                     		 	 (LONG)(LPSTR)list);
    				}
    
    				if (wNotify==LBN_DBLCLK)
    				{
    					LogMessage("Goto\r\n");
    					goto From_List;
    				}
    				
    				break;

				case TW_FILENAME:
    			{
    				// grey the okay button if "filename" box is empty  or contains a wild card 
    				int length_text;

	    			if (wNotify==EN_CHANGE)
	    			{
						length_text = (int)SendMessage (GetDlgItem (hdlg, TW_FILENAME),
                    							WM_GETTEXTLENGTH,
                    							0, 0L);

						SendMessage (GetDlgItem(hdlg, TW_FILENAME), WM_GETTEXT, MAXFILENAME, (long)buffer);

    					// also gray if any wildcards in filename
		    			if (strstr (buffer, "*")!=NULL)
        				length_text = 0;  // cancel length

						EnableWindow (GetDlgItem(hdlg, TW_OKAY), length_text);
    				}
		    		break;
				}
	
				case TW_LB_DIRECTORIES:
			    	// just show the new path in filename edit control 
		    		if (wNotify==LBN_SELCHANGE)
		    		{

						#ifdef WIN32
							DlgDirSelectEx (hdlg,
							list,
            	       		sizeof (list),
							TW_LB_DIRECTORIES);
						#else     //GR: 16 bit version
							DlgDirSelect (hdlg,list,TW_LB_DIRECTORIES);
					   
						#endif
						lstrcat (list, wild_list);
						SendMessage (GetDlgItem(hdlg, TW_FILENAME),
        			         WM_SETTEXT,
            			     0,
                			 (LONG)(LPSTR)list);
    				}

   					// dblclk redraw dirlist and filelist and highlight and setfocus on "filename" 
    				if (wNotify==LBN_DBLCLK)
					{

						#ifdef WIN32
							DlgDirSelectEx (hdlg,
								list,
                            	sizeof (list),
								TW_LB_DIRECTORIES);
						#else     //GR: 16 bit version
							DlgDirSelect (hdlg,
				    		  	list,
				      			TW_LB_DIRECTORIES);
						#endif

			    		DlgDirList (hdlg,
            			    list,
							TW_LB_DIRECTORIES,
							TW_DIRECTORY,
                			0xC010);

			    		DlgDirList (hdlg,
            			    wild_list,
							TW_LB_FILENAMES,
                			NULL,
                			0);

			    		hCtl = GetDlgItem(hdlg, TW_FILENAME);
    					SendMessage (hCtl,
            		    	WM_SETTEXT,
                 			0,
                 			(long)(LPSTR)wild_list);
							
						#ifdef WIN32
							SendMessage (hCtl,
								EM_SETSEL,
                		     	0,
				     			MAXFILENAME);
						#else	//GR: 16 bit version
							SendMessage (hCtl,
								EM_SETSEL,
                		     	0,
                	     	    MAKELONG (0, MAXFILENAME));
						#endif
    					SetFocus (hCtl);
					}
    				break;

    			default:
    				break;
			}
    
    		break;

		} 

*/
    	/**************************DEFAULT*************************************/
/*    	default:    // for wMsg level switch 
    		return FALSE;
	} 
*/
    return TRUE; // iff handled
}

⌨️ 快捷键说明

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