?? mcbmain.c
字號:
if (lpszXML)
{
/*
*****************************************************************
* Parse the XML into the tree structure
*****************************************************************
*/
pRoot = McbParseXML(lpszXML, NULL);
if (pRoot)
{
/*
*************************************************************
* Find the head element
*************************************************************
*/
pChild = McbFindElement(pRoot, _T("XMLOptions"));
if (pChild)
{
nResult = TRUE;
/*
*********************************************************
* Search for the vertical panel attribute, if this isnt
* found then the assume horizontal panel
*********************************************************
*/
pAttr = McbFindAttribute(pChild, _T("PanelsVertical"));
if (pAttr)
{
pOptions->bPanelsVertical = TRUE;
}
/*
*********************************************************
* Find the file options element
*/
pChild = McbFindElement(pChild, _T("FileOptions"));
if (pChild)
{
/*
*****************************************************
* Obtain the filename attribute
*****************************************************
*/
pAttr = McbFindAttribute(pChild, _T("Filename"));
if (pAttr && pAttr->lpszValue)
{
lpszValue = McbRemoveQuotes(pAttr->lpszValue);
if (lpszValue)
{
_tcscpy(pOptions->szLastFile, lpszValue);
free(lpszValue);
}
}
/*
*****************************************************
* Obtain the filter index attribute
*****************************************************
*/
pAttr = McbFindAttribute(pChild, _T("FilterIndex"));
if (pAttr && pAttr->lpszValue)
{
pOptions->nFilterIndex = _ttol(pAttr->lpszValue);
}
}
}
McbDeleteRoot(pRoot);
}
free(lpszXML);
}
}
return nResult;
}/* McbArchiveOptions */
/*
****************************************************************************
* Constants used withthe image list.
****************************************************************************
*/
#define McbATTRIBUTEBMP 0
#define McbCDATABMP 1
#define McbCLEARBMP 2
#define McbDECLARATIONBMP 3
#define McbELEMENTBMP 4
#define McbTEXTBMP 5
/*
****************************************************************************
* Helper macro to set the status bar text.
****************************************************************************
*/
#define McbSETSTATUS(hWnd, lpszText, nPanel) \
SendMessage((hWnd), SB_SETTEXT, (nPanel), (LPARAM)(lpszText))
/**
****************************************************************************
* <P> Message handler for about box. </P>
*
* @methodName CALLBACK McbAbout
*
* @param hDlg
* @param message
* @param wParam
* @param lParam
*
* @return LRESULT
*
* @exception none
*
* @author Martyn C Brown
*
* @changeHistory
* 3rd February 2002 - (V1.0) Creation (MCB)
****************************************************************************
*/
LRESULT CALLBACK McbAbout(HWND hDlg, UINT message, WPARAM wParam,
LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}/* CALLBACK McbAbout */
/**
****************************************************************************
* <P> Saves instance handle and creates main window.
*
* In this function, we save the instance handle in a global variable and
* create and display the main program window. </P>
*
* @methodName McbInitInstance
*
* @param hInstance
* @param nCmdShow
*
* @return BOOL
*
* @exception none
*
* @author Martyn C Brown
*
* @changeHistory
* 3rd February 2002 - (V1.0) Creation (MCB)
****************************************************************************
*/
BOOL McbInitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
/*
**************************************************************************
* Store instance handle in our global variable
**************************************************************************
*/
g_hInst = hInstance;
hWnd = CreateWindow(g_szWindowClass, g_szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}/* McbInitInstance */
/**
****************************************************************************
* <P> Replace non-printable characters with a space. </P>
*
* @methodName McbReplaceNonPrintableChars
*
* @param lpszText
*
* @return void
*
* @exception none
*
* @author Martyn C Brown
*
* @changeHistory
* 26th August 2001 - (V1.0) Creation (MCB)
****************************************************************************
*/
void McbReplaceNonPrintableChars(LPTSTR lpszText)
{
LPTSTR lpszMarker = lpszText;
if (lpszMarker)
{
for (; *lpszMarker; lpszMarker++)
{
switch(*lpszMarker)
{
case _T('\r'):
case _T('\n'):
case _T('\t'):
*lpszMarker = _T(' ');
}
}
}
}/* McbReplaceNonPrintableChars */
/**
****************************************************************************
* <P> Recursively build the tree control. </P>
*
* @methodName McbBuildTree
*
* @param HWND hWndTree
* @param McbXMLNode *pNode
* @param HTREEITEM hParent
*
* @return void
*
* @exception none
*
* @author Martyn C Brown
*
* @changeHistory
* 20th August 2001 - (V1.0) Creation (MCB)
****************************************************************************
*/
void McbBuildTree(HWND hWndTree, McbXMLNode *pNode, HTREEITEM hParent)
{
int cbElement;
TV_INSERTSTRUCT insert;
int nImage;
HTREEITEM hElement;
int nIndex;
int cb;
int cbText;
int cbName;
int cbValue;
McbXMLNode *pChild;
McbXMLClear *pClear;
McbXMLElement *pElement;
McbXMLAttribute *pAttrib;
LPTSTR lpszText;
LPTSTR lpszMarker;
assert(pNode->type == eNodeElement);
assert(hWndTree);
pElement = pNode->node.pElement;
assert(pElement);
cbElement = pElement->lpszName ? _tcslen(pElement->lpszName) : 0;
insert.hParent = hParent;
insert.hInsertAfter = TVI_LAST;
insert.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE |
TVIF_STATE | TVIF_PARAM;
nImage = pElement->nIsDeclaration ? McbDECLARATIONBMP : McbELEMENTBMP;
insert.item.hItem;
insert.item.state = TVIS_BOLD;
insert.item.stateMask = TVIS_BOLD;
insert.item.pszText = pElement->lpszName;
insert.item.cchTextMax = cbElement;
insert.item.iImage = nImage;
insert.item.iSelectedImage = nImage;
insert.item.cChildren = 0;
/*
*************************************************************************
* The lParam for each node will contain the character offset at where the
* node starts (calculated when the xml was parsed) and the significant
* size of the node. This can then be used to update the rich edit window
* when someone selects a node in the tree.
*************************************************************************
*/
insert.item.lParam = (LPARAM)MAKELONG((WORD)pNode->nStringOffset,
(WORD)cbElement);
/*
*************************************************************************
* Insert the element into the tree
*************************************************************************
*/
if (cbElement)
{
hElement = (HTREEITEM)SendMessage(hWndTree, TVM_INSERTITEM, 0,
(LPARAM)(LPTV_INSERTSTRUCT)&insert);
assert(hElement);
}
else
{
hElement = NULL;
}
insert.hParent = hElement;
/*
*************************************************************************
* Enumerate nodes in the list
*************************************************************************
*/
nIndex = 0;
while(pChild = McbEnumNodes(pElement, &nIndex))
{
switch(pChild->type)
{
/*
*********************************************************************
* If we have an attribute node
*********************************************************************
*/
case eNodeAttribute:
insert.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE |
TVIF_PARAM;
insert.item.iImage = McbATTRIBUTEBMP;
insert.item.iSelectedImage = McbATTRIBUTEBMP;
pAttrib = pChild->node.pAttrib;
/*
*****************************************************************
* Construct attribute name : value
*****************************************************************
*/
cbName = pAttrib->lpszName ? _tcslen(pAttrib->lpszName) : 0;
cbValue = pAttrib->lpszValue ? _tcslen(pAttrib->lpszValue) : 0;
insert.item.lParam = (LPARAM)MAKELONG((WORD)
pChild->nStringOffset, (WORD)cbName);
cbText = cbName + cbValue;
assert(cbText);
if (cbValue) cbText += 3;
lpszText = (LPTSTR)malloc((cbText+1) * sizeof(TCHAR));
lpszMarker = lpszText;
if (cbName)
{
_tcscpy(lpszMarker, pAttrib->lpszName);
lpszMarker += cbName;
}
if (cbValue)
{
_tcscpy(lpszMarker, _T(" : "));
lpszMarker += 3;
_tcscpy(lpszMarker, pAttrib->lpszValue);
}
insert.item.cchTextMax = cbText;
insert.item.pszText = lpszText;
McbReplaceNonPrintableChars(insert.item.pszText);
/*
*****************************************************************
* Insert each attribute into the tree.
*****************************************************************
*/
SendMessage(hWndTree, TVM_INSERTITEM, 0, (LPARAM)
(LPTV_INSERTSTRUCT)&insert);
free(lpszText);
break;
/*
*********************************************************************
* If we have an element node.
*********************************************************************
*/
case eNodeElement:
McbBuildTree(hWndTree, pChild, hElement);
break;
/*
*********************************************************************
* If we have a text node.
*********************************************************************
*/
case eNodeText:
insert.item.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE |
TVIF_PARAM;
insert.item.iImage = McbTEXTBMP;
insert.item.iSelectedImage = McbTEXTBMP;
cbText = _tcslen(pChild->node.pText->lpszValue);
lpszText = (LPTSTR)malloc((cbText+1) * sizeof(TCHAR));
insert.item.lParam = (LPARAM)MAKELONG((WORD)
pChild->nStringOffset, (WORD)cbText);
_tcscpy(lpszText, pChild->node.pText->lpszValue);
insert.item.pszText = lpszText;
insert.item.cchTextMax = cbText;
McbReplaceNonPrintableChars(insert.item.pszText);
/*
*****************************************************************
* Insert text node into the tree
*****************************************************************
*/
SendMessage(hWndTree, TVM_INSERTITEM, 0,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -