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

📄 mcbmain.c

📁 brew 平台xml解析
💻 C
📖 第 1 页 / 共 5 页
字号:
		}
       /*
        *********************************************************************
        * If we failed to load the file.
        *********************************************************************
        */
        else 
		{	
			TreeView_DeleteAllItems(hWndTree);

			McbSETSTATUS(hWnd, _T("Failed to read the file"), 0);
		}
	}

	return nResult;

}/* McbGetFileNameAndLoadXML */

/**
 ****************************************************************************
 * <P> Obtain a filename from the punter and attempt to save XML into it. 
 * </P>
 *
 * @methodName  McbGetFileNameAndSaveXML
 *
 * @param       lpszXML
 * @param       hWnd		
 * @param       hWndRich		
 * @param       hWndStatus		
 * @param       *pOptions		
 *
 * @return      int
 *
 * @exception   none
 *
 * @author      Martyn C Brown
 *
 * @changeHistory  
 *	4th February  	2002	 - 	(V1.0) Creation (MCB)
 ****************************************************************************
 */
int McbGetFileNameAndSaveXML(LPTSTR lpszXML, HWND hWnd, HWND hWndRich, 
							HWND hWndStatus, McbOptions *pOptions)
{
	int nResult = FALSE;
	
	TCHAR szFile[_MAX_PATH+1];
	TCHAR szFileTitle[_MAX_PATH+1];
	TCHAR szStartDir[_MAX_PATH+1];
	TCHAR szDrive[_MAX_DRIVE+1];   
	TCHAR szDir[_MAX_DIR+1];
	TCHAR szExt[_MAX_EXT+1];   
	TCHAR szFname[_MAX_FNAME+1];

	OPENFILENAME openName;

	if (lpszXML)
	{
        openName.lStructSize = sizeof(OPENFILENAME);
        openName.hwndOwner = hWnd;
        openName.hInstance = g_hInst;

        openName.lpstrFilter = _T("XML Files (*.xml)\0*.xml\0Text Files (*.txt)")
            _T("\0*.txt\0All Files (*.*)\0*.*\0\0");

        openName.lpstrCustomFilter = NULL;
        openName.nMaxCustFilter = 0;
        openName.nFilterIndex = pOptions->nFilterIndex;
        openName.lpstrFile = szFile;
        openName.nMaxFile = _MAX_PATH;
        openName.lpstrFileTitle = szFileTitle;
        openName.nMaxFileTitle = _MAX_PATH;
        openName.lpstrInitialDir = NULL;
        openName.lpstrTitle = _T("Save XML file");
        openName.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | 
            OFN_NOREADONLYRETURN | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
        openName.nFileOffset = 0;
        openName.nFileExtension = 0;
        openName.lpstrDefExt = NULL;
        openName.lCustData = 0;
        openName.lpfnHook = NULL;
        openName.lpTemplateName = NULL;

        if (*pOptions->szLastFile)
        {
            _tsplitpath(pOptions->szLastFile, szDrive, szDir, szFname, szExt);

            _tcscpy(szStartDir, szDrive);
            _tcscpy(szStartDir + _tcslen(szDrive), szDir);
        
            openName.lpstrInitialDir = szStartDir;

            _tcscpy(szFile, szFname);
            _tcscpy(szFile + _tcslen(szFname), szExt);
        }
        else
        {
            szFile[0] = 0;
        }

       /*
        *********************************************************************
        * Obtain the file name and attempt to save it
        *********************************************************************
        */
        if (GetSaveFileName(&openName))
        {
            if (McbSaveFile(szFile, lpszXML))
            {
               /*
                *************************************************************
                * Cache the options.
                *************************************************************
                */
				pOptions->nFilterIndex = openName.nFilterIndex;
				_tcscpy(pOptions->szLastFile, szFile);

                McbSETSTATUS(hWnd, _T("Saved"), 0);
            }
            else
            {
                McbSETSTATUS(hWnd, _T("Failed to write to file"), 0);
            }
        }
	}

	return nResult;

}/* McbGetFileNameAndSaveXML */

/**
 ****************************************************************************
 * <P> Processes messages for the main window. </P>
 *
 * @methodName  CALLBACK McbWndProc
 *
 * @param       hWnd		
 * @param       message		
 * @param       wParam		
 * @param       lParam		
 *
 * @return      LRESULT
 *
 * @exception   none
 *
 * @author      Martyn C Brown
 *
 * @changeHistory  
 *	3rd February  	2002	 - 	(V1.0) Creation (MCB)
 ****************************************************************************
 */
LRESULT CALLBACK McbWndProc(HWND hWnd, UINT msg, WPARAM wParam, 
						   LPARAM lParam)
{
	static HWND			hWndRich = NULL;		/* rich edit */
	static HWND			hWndStatus = NULL;		/* status bar */
	static HWND			hWndTree = NULL;		/* tree control */
	static HFONT		hFontArial = NULL;		/* main font */
	static HINSTANCE	hInstRichEdit = NULL;	/* rich edit dll */
	static HIMAGELIST	hImages = NULL;			/* Image list for the tree */
	static BOOL			bTreeUpdated = FALSE;

	int				wmId;
	int				wmEvent;
	PAINTSTRUCT		ps;
	HDC				hDC;
	RECT			rcWnd;
	RECT			rcTemp;
	int				nInit;
	DWORD			dwStyle;
	DWORD			dwExStyle;
	int				nWndHeight;
	int				nWndWidth;
	int				nX;
	TEXTMETRIC		txtMet;
	BOOL			bRedraw;
	LOGFONT			logFont;
	LPTSTR			lpszText;
	LPTSTR			lpszText2;
	LPTSTR			lpszFile;
	NMHDR			*pNmh;
	NM_TREEVIEW		*pNmtv;
	TV_ITEM			tvItem;
	CHARRANGE		range;
	HDROP			hDrop;
	UINT			cch;

	switch (msg) 
	{
       /*
        *********************************************************************
        * The window procedure receives this message after the window is 
		* created, but before the window becomes visible. The message is sent 
		* before the CreateWindowEx or CreateWindow function returns.
		* Within here we are going to create all the required resources.
        *********************************************************************
        */
		case WM_CREATE:
			{
				nInit = FALSE;

               /*
                *************************************************************
                * Load options from file.
                *************************************************************
                */
				McbGetOptionsFileName(g_szOptFile);
				McbArchiveOptions(g_szOptFile, &g_options, FALSE);

               /*
                *************************************************************
                * Load the DLL which services common controls for the tree
				* control
                *************************************************************
                */
                InitCommonControls();

               /*
                *************************************************************
                * Create the tree view control
                *************************************************************
                */
				dwStyle = WS_VISIBLE | WS_CHILD | WS_BORDER | TVS_HASBUTTONS 
					| TVS_HASLINES | TVS_LINESATROOT;

				dwExStyle = 0;

                hWndTree = CreateWindowEx(dwExStyle, WC_TREEVIEW, NULL, 
					dwStyle, 0, 0, 0, 0, hWnd, (HMENU)IDC_TREE, g_hInst, 
					NULL);

				if (hWndTree)
				{
                   /*
                    *********************************************************
                    * Create the status bar
                    *********************************************************
                    */
					dwStyle = WS_CHILD | WS_VISIBLE;

                    hWndStatus = CreateStatusWindow(dwStyle, NULL, hWnd, 0);

					if (hWndStatus)
					{
                       /*
                        *****************************************************
                        * Load the dll for the rich edit 
                        *****************************************************
                        */
#define McbRICHEDIT	_T("RICHED32.DLL")
						hInstRichEdit = LoadLibrary(McbRICHEDIT);

                       /*
                        *****************************************************
                        * Create rich edit box
                        *****************************************************
                        */
                        dwStyle = WS_VISIBLE | WS_CHILD | WS_BORDER | 
							WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL |
							ES_MULTILINE;
 
                        hWndRich = CreateWindowEx(dwExStyle, _T("RICHEDIT"), 
							NULL, dwStyle, 0, 0, 0, 0, hWnd, 
							(HMENU)IDC_RICHEDIT, g_hInst, NULL);

						if (hWndRich)
						{
                           /*
                            *************************************************
                            * Enable drag and drop notifications.
                            *************************************************
                            */
							DragAcceptFiles(hWnd, TRUE);

                           /*
                            *************************************************
                            * Create font
                            *************************************************
                            */
                            hDC = GetDC(hWnd);
                            GetTextMetrics(hDC, &txtMet);
                            ReleaseDC(hWnd, hDC);

							logFont.lfHeight =			txtMet.tmHeight;	   
							logFont.lfWidth =			
								txtMet.tmAveCharWidth;  
							logFont.lfEscapement =		0;                      
							logFont.lfOrientation =		0;                      
							logFont.lfWeight =			FW_NORMAL;              
							logFont.lfItalic =			txtMet.tmItalic;        
							logFont.lfUnderline =		txtMet.tmUnderlined;    
							logFont.lfStrikeOut =		txtMet.tmStruckOut;     
							logFont.lfCharSet =			txtMet.tmCharSet;       
							logFont.lfOutPrecision =	OUT_DEFAULT_PRECIS;     
							logFont.lfClipPrecision =	CLIP_DEFAULT_PRECIS;    
							logFont.lfQuality =			DEFAULT_QUALITY;        
							logFont.lfPitchAndFamily =	
								txtMet.tmPitchAndFamily;

							_tcscpy(logFont.lfFaceName, _T("Arial"));

                            hFontArial = CreateFontIndirect(&logFont);                

							if (hFontArial)
							{                    
                               /*
                                *********************************************
                                * Associate the font with the edit window.
                                *********************************************
                                */
                                bRedraw = FALSE;

                                SendMessage(hWndRich, WM_SETFONT, 
									(WPARAM)hFontArial, 
									MAKELPARAM(bRedraw, 0));  

                               /*
                                *********************************************
                                * Attempt to load the last file
                                *********************************************
                                */
								lpszText = McbLoadFile(g_options.szLastFile);

								if (lpszText)
								{
									SetWindowText(hWndRich, lpszText);

									if (McbParseXMLIntoTree(hWndRich, 
										hWndStatus, hWndTree, lpszText))
									{
										bTreeUpdated = TRUE;
									}

									free(lpszText);
								}
								
                               /*
                                *********************************************
                                * Create the image list from the bitmap
                                *********************************************
                                */
								hImages = ImageList_LoadImage(g_hInst, 
									MAKEINTRESOURCE(IDB_BMPIMAGELIST),
									12, 5, RGB(0, 0, 0), IMAGE_BITMAP, 
									LR_DEFAULTCOLOR);

								if (hImages)
								{
                                   /*
                                    *****************************************
                                    * Associate the image list with the 
                                    * tree-view control. 
                                    *****************************************
                                    */
                                    TreeView_SetImageList(hWndTree, hImages, 
										TVSIL_NORMAL);
                                    
                                    nInit = TRUE;
								}
							}
						}
					}
				}

				if (nInit == FALSE)
				{
                   /*
                    *********************************************************
                    * Terminate by sending a destroy message back to self.
                    *********************************************************
                    */
                    PostMessage(hWnd, WM_DESTROY, 0, 0);
				}
			}
			break;

       /*
        *********************************************************************
        * Window resize message.  Scale the controls and graphics here.
        *********************************************************************
        */
		case WM_SIZE:
			{
               /*
                *************************************************************
                * Obtain the status window sizes
                *************************************************************
                */
				GetClientRect(hWndStatus, &rcTemp);

               /*
                *************************************************************
                * Obtain the size of the main window, allowing for the size
				* of the status window
                *************************************************************
                */
				GetClientRect(hWnd, &rcWnd);

				rcWnd.bottom -= rcTemp.bottom;

				nWndHeight = rcWnd.bottom - rcWnd.top;
				nWndWidth = rcWnd.right - rcWnd.left;

               /*
                *************************************************************
                * Resize the windows
                *************************************************************
                */
				MoveWindow(hWndStatus, 0, nWndHeight, nWndWidth, rcTemp.top, 
					TRUE);

				if (g_options.bPanelsVertical) 
				{
					nX = (int)nWndWidth / 2;

					MoveWindow(hWndRich, 0, 0, nX, nWndHeight, TRUE);
					MoveWindow(hWndTree, nX, 0, nWndWidth - nX, nWndHeight, 
						TRUE);
				}
				else
				{
					nX = (int)nWndHeight / 2;

					MoveWindow(hWndRich, 0, 0, nWndWidth, nX, TRUE);
					MoveWindow(hWndTree, 0, nX, nWndWidth, nWndHeight - nX, 
						TRUE);
				}

				return DefWindowProc(hWnd, msg, wParam, lParam);
			}

       /*
        *********************************************************************
        * Drag and drop messages
        *********************************************************************
        */
		case WM_DROPFILES:
			{
				hDrop = (HDROP)wParam;

               /*
                *************************************************************

⌨️ 快捷键说明

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