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

📄 dlg_utils.c

📁 图像处理的压缩算法
💻 C
📖 第 1 页 / 共 2 页
字号:
{
	string strPropertyName = (lpcstrPropertyName ? lpcstrPropertyName : ".V");
	string strPath = (lpcstrPath ? lpcstrPath : GetAppPath());
	string strFileFilter = (lpcstrFileFilter ? lpcstrFileFilter : "*.*");

	double dInitChoice;
	string strCommand;                                       
	if( bAppend )                                               // If user wants to append to list box...
	{
		strCommand.Format("dInitChoice=%s.Choice", lpcstrListBoxName); // Build command to get initial list box choice
		LT_execute(strCommand);                                 // Execute command to get initial list box choice
		LT_get_var("dInitChoice", &dInitChoice);                // Get initial list box choice from LabTalk variable
		LT_execute("Delete -v dInitChoice");                    // Delete LabTalk variable
	}
	else                                                        // Else user does not want to append...
	{
		strCommand.Format( "%s.Reset()", lpcstrListBoxName );   // Build command to reset list box
		LT_execute(strCommand);                                 // Execute command to reset list box
		dInitChoice = 1;                                        // Initialize list box choice
	}
		
	string strSearchPathFilter;
	strSearchPathFilter.Format( "%s*.*", strPath );             // Build search start path\file name
		
	WIN32_FIND_DATAA find;

	HANDLE hFile = FindFirstFile( strSearchPathFilter, &find ); // Find first file/folder that matches
	if( hFile != INVALID_HANDLE_VALUE )                         // If valid handle...
	{
		double dNumItems;
		string strFileFound, strFilename;
		do                                                      // Do while next file/folder is found...
		{
			if( find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )                     // If folder is next...                     
			{
				if( bRecursive )                                                       // If user wants to recurse...
				{
					strFileFound = find.cFileName;
					if( strFileFound.Compare(".") && strFileFound.Compare("..") )      // If file found (folder) is not  
					{
						strFileFound.Format("%s%s\\", strPath, find.cFileName);

						PopulateListBoxWithFilenames( lpcstrListBoxName, strPropertyName, // Recurse into subfolder
							 TRUE, strFileFound, strFileFilter, TRUE, wDisplayOptions );
					}
				}
			}
			else                                                                       // Else file is next...
			{
				strFilename = find.cFileName;
				if( strFilename.Match( strFileFilter ) )                               // If file name matches file filter...
				{
					strCommand.Format( "dNumItems=%s.NumItems", lpcstrListBoxName );      // Build command to get number of items in list box
					LT_execute( strCommand );                                          // Execute command to get number of items in list box
					LT_get_var( "dNumItems", &dNumItems );                             // Get number of items from LabTalk variable
	
					if( wDisplayOptions & DLG_UTILS_FILE_NO_PATH )                     // If user does not want path...
						strFileFound = strFilename;                                    // Just use filename
					else
						strFileFound.Format("%s%s", strPath, find.cFileName);          // Else use path and filename 
					if( wDisplayOptions & DLG_UTILS_FILE_NO_EXT )                      // If user does not want file extension...
						strFileFound = GetFilenameWithoutExt( strFileFound );          // Strip off file extension from filename

					strCommand.Format( "%s%s%d$=%s", lpcstrListBoxName, strPropertyName, nint(dNumItems) + 1, strFileFound ); // Build command to add file to list box
					LT_execute( strCommand );                                          // Add file to list box
				}
			}
		} while( FindNextFile( hFile, &find ) );                // While next file is found... 

		FindClose( hFile );                                     // Close find
		
		if( dNumItems >= 1 && dInitChoice < dNumItems )         // If at least one item is added to list box and choice is in range...
		{
			strCommand.Format( "%s.Choice=%d", lpcstrListBoxName, nint(dInitChoice) ); // Build command to choose slected item in list box
			LT_execute( strCommand );                           // Execute command to choose selected item in list box
			LT_execute( "delete -v dNumItems" );                // Delete LabTalk variable
		}

		return DLG_UTILS_NO_ERROR;
	}

	return DLG_UTILS_NO_FILES_FOUND_ERROR;
}

/**
		Get the current worksheet/workbook sheet selection range and populate the specified
		Dialog Builder edit box with it. The selection range must be contained within a single
		worksheet/workbook column and the Dialog Builder edit box control must be passed by
		reference.
	Example:
		Edit ebxWeighting = dlgStatisticsOn.GetItem(IDC_SO_WEIGHT_EBX, IDD_SO_OP_TAB);
		// Populate Weighting edit box, type out error if problem
		if( PopulateEditBoxWithOneColumnRange(ebxWeighting) )
		{
			strMsg = SO_WKS_WEIGHT_SEL_ERROR_MSG; // Output error message and return
			strMsg.Write(WRITE_MESSAGE_BOX);
			return false;
		}
	Parameters:
		ebx=Input reference to Dialog Builder edit box
	Return:
		Returns DLG_UTILS_NO_ERROR on success and a DLG_UTILS warning or error code on failure.
*/
int PopulateEditBoxWithOneColumnRange(Edit& ebx)
{
	string strSelectedRange;
	int iRet, iNumRanges;

	if(!ebx)                                                                   // If edit box is invalid...
		return DLG_UTILS_INVALID_EBX_ERROR;
	else                                                                       // Else populate edit box...
	{
		iRet = wuGetNonContiguousWksSelection(strSelectedRange, iNumRanges);   // Get current selection range

		if( iRet )                                                             // If no selection or bad selection...
			return iRet;
		else
		{
			if( iNumRanges != 1 )                                              // If selection range spans more than single column...
				return DLG_UTILS_NO_SINGLE_COL_ERROR;
			else                                                               // Else single column range
				ebx.Text = strSelectedRange;                                   // Set range in edit box
		}
	}

	return DLG_UTILS_NO_ERROR;
}

/**
		Populate the specified list box with string values from each subnode of the 
		specified TreeNode.
	Example:
		See function call in StatisticsOn.c.
	Parameters:
		tr=Input TreeNode whose subnodes will be used to populate a list box
		bAppend=Input option to append string values from each subnode (true) or to
			reset list box and populate starting in first item (default false)
	Return:
		Returns DLG_UTILS_NO_ERROR on success.
*/
int PopulateListBoxFromTreeNode(ListBox& lbx, TreeNode& tr, bool bAppend) // bAppend = false
{
	if( !lbx )                                    // If listbox is invalid...
		return DLG_UTILS_INVALID_LBX_ERROR;
	else                                          // Else populate listbox...
	{
		if( !tr )                                 // If TreeNode is invalid...
			return DLG_UTILS_INVALID_TREENODE_ERROR;
		else                                      // Else populate listbox
		{
			TreeNode trSubNode;
		
			if( !bAppend )                        // If user does not want to append items to list box...
				lbx.ResetContent();               // Reset list box
		
			trSubNode = tr.FirstNode;             // Get first subnode
			while( trSubNode )                    // While subnodes exist...
			{
				lbx.AddString(trSubNode.Display.strVal); // Add display value of subnode to list box
				trSubNode = trSubNode.NextNode;   // Get next subnode
			}
		}
	}

	return DLG_UTILS_NO_ERROR;
}

⌨️ 快捷键说明

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