📄 mcbmain.c
字号:
* Only accept one filename at most
*************************************************************
*/
if (DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0) > 1)
{
McbSETSTATUS(hWndStatus,
_T("Multiple files not supported"), 0);
}
else
{
/*
*********************************************************
* Obtain the filename, the first call obtains the size.
*********************************************************
*/
cch = DragQueryFile(hDrop, 0, NULL, 0);
if (cch)
{
lpszFile = (LPTSTR)malloc((cch+1) + sizeof(TCHAR));
cch = DragQueryFile(hDrop, 0, lpszFile, cch+1);
if (cch)
{
/*
*************************************************
* Attempt to load the file then parse it into the
* tree.
*************************************************
*/
lpszText = McbLoadFile(lpszFile);
if (lpszText)
{
SetWindowText(hWndRich, lpszText);
if (McbParseXMLIntoTree(hWndRich, hWndStatus,
hWndTree, lpszText))
{
/*
*****************************************
* Update the options
*****************************************
*/
_tcscpy(g_options.szLastFile, lpszFile);
bTreeUpdated = TRUE;
}
free(lpszText);
}
}
else
{
McbSETSTATUS(hWndStatus,
_T("Failed to query filename"), 0);
}
free(lpszFile);
}
}
DragFinish(hDrop);
}
return DefWindowProc(hWnd, msg, wParam, lParam);
/*
*********************************************************************
* Notification messages
*********************************************************************
*/
case WM_NOTIFY:
{
/*
*************************************************************
* Obtain the notification header
*************************************************************
*/
pNmh = (NMHDR*)lParam;
switch(pNmh->idFrom)
{
/*
*************************************************************
* Tree view
*************************************************************
*/
case IDC_TREE:
/*
*********************************************************
* If the selection has changed in the tree view.
*********************************************************
*/
if (pNmh->code == TVN_SELCHANGED)
{
if (bTreeUpdated)
{
/*
*************************************************
* Obtain the item from the tree view. When the
* tree view was built (in McbBuildTree()) the
* lParam parameter value was built up to contain
* the character offset at which the node starts
* at and the length of the node start.
* We'll use this to format the rich edit box so
* that when someone selects an entry in the tree
* control, the current selection changes in the
* rich edit box.
*************************************************
*/
pNmtv = (NM_TREEVIEW*)lParam;
tvItem.mask = TVIF_PARAM | TVIF_HANDLE;
tvItem.hItem = pNmtv->itemNew.hItem;
if (TreeView_GetItem(hWndTree, &tvItem))
{
/*
*********************************************
* Set the selection in the rich edit box,
* scroll the window so it is visible and
* ensure the selection is visible.
*********************************************
*/
range.cpMin = LOWORD(tvItem.lParam);
range.cpMax = range.cpMin +
HIWORD(tvItem.lParam);
SendMessage(hWndRich, EM_EXSETSEL, 0,
(LPARAM)&range);
SendMessage(hWndRich, EM_SCROLLCARET, 0, 0);
SendMessage(hWndRich, EM_HIDESELECTION,
(WPARAM)(BOOL)FALSE,
(LPARAM)(BOOL)FALSE);
}
}
}
break;
}
}
break;
/*
*********************************************************************
* Menu/control messages.
*********************************************************************
*/
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case IDM_ABOUT:
DialogBox(g_hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd,
(DLGPROC)McbAbout);
break;
/*
*****************************************************************
* Format XML command
*****************************************************************
*/
case IDM_FORMATXML:
lpszText = McbGetWindowText(hWndRich);
if (lpszText)
{
/*
*********************************************************
* Create formatted version of the XML
*********************************************************
*/
lpszText2 = McbFormatXML(lpszText);
if (lpszText2)
{
/*
*****************************************************
* Update the rich edit control
*****************************************************
*/
SetWindowText(hWndRich, lpszText2);
free(lpszText2);
}
free(lpszText);
}
/*
*************************************************************
* Drop into the Parse XML command
*************************************************************
*/
/*
*****************************************************************
* Parse XML command
*****************************************************************
*/
case IDM_PARSE:
lpszText = McbGetWindowText(hWndRich);
if (lpszText)
{
if (McbParseXMLIntoTree(hWndRich, hWndStatus, hWndTree,
lpszText))
{
bTreeUpdated = TRUE;
}
free(lpszText);
}
break;
/*
*****************************************************************
* Rich edit control commands
*****************************************************************
*/
case IDC_RICHEDIT:
switch(wmEvent)
{
case EN_CHANGE:
bTreeUpdated = FALSE;
}
break;
/*
*****************************************************************
* Change view command
*****************************************************************
*/
case IDM_CHANGEVIEW:
g_options.bPanelsVertical = !g_options.bPanelsVertical;
PostMessage(hWnd, WM_SIZE, 0, 0);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
/*
*****************************************************************
* File open command
*****************************************************************
*/
case IDM_FILEOPEN:
if (McbGetFileNameAndLoadXML(hWnd, hWndRich, hWndStatus,
hWndTree, &g_options))
{
bTreeUpdated = TRUE;
}
break;
/*
*****************************************************************
* File save command.
*****************************************************************
*/
case IDM_FILESAVE:
lpszText = McbGetWindowText(hWndRich);
if (lpszText)
{
McbGetFileNameAndSaveXML(lpszText, hWnd, hWndRich,
hWndStatus, &g_options);
}
else
{
McbSETSTATUS(hWndStatus, _T("No data to save!"), 0);
}
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
break;
/*
*********************************************************************
* Painting messages.
*********************************************************************
*/
case WM_PAINT:
hDC = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
/*
*********************************************************************
* Terminate message or cleanup.
*********************************************************************
*/
case WM_DESTROY:
/*
*****************************************************************
* Save options to file.
*****************************************************************
*/
McbArchiveOptions(g_szOptFile, &g_options, TRUE);
if (hWndRich) DestroyWindow(hWndRich);
if (hWndStatus) DestroyWindow(hWndStatus);
if (hImages) ImageList_Destroy(hImages);
if (hWndTree) DestroyWindow(hWndTree);
if (hFontArial) DeleteObject(hFontArial);
if (hInstRichEdit) FreeLibrary(hInstRichEdit);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}/* CALLBACK McbWndProc */
/**
****************************************************************************
* <P> Registers the window class.
*
* This function and its usage is only necessary if you want this code to be
* compatible with Win32 systems prior to the 'RegisterClassEx' function that
* was added to Windows 95. It is important to call this function so that the
* application will get 'well formed' small icons associated with it.</P>
*
* @methodName McbRegisterClass
*
* @param hInstance
*
* @return ATOM
*
* @exception none
*
* @author Martyn C Brown
*
* @changeHistory
* 3rd February 2002 - (V1.0) Creation (MCB)
****************************************************************************
*/
ATOM McbRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)McbWndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_MCBXML);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_MCBXML;
wcex.lpszClassName = g_szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
return RegisterClassEx(&wcex);
}/* McbRegisterClass */
/**
****************************************************************************
* <P> Application entry point. </P>
*
* @methodName APIENTRY WinMain
*
* @param hInstance
* @param hPrevInstance
* @param lpCmdLine
* @param nCmdShow
*
* @return int
*
* @exception none
*
* @author Martyn C Brown
*
* @changeHistory
* 3rd February 2002 - (V1.0) Creation (MCB)
****************************************************************************
*/
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;
/*
*************************************************************************
* Initialize global strings
*************************************************************************
*/
LoadString(hInstance, IDS_APP_TITLE, g_szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_MCBXML, g_szWindowClass, MAX_LOADSTRING);
McbRegisterClass(hInstance);
/*
*************************************************************************
* Perform application initialization:
*************************************************************************
*/
if (!McbInitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MCBXML);
/*
*************************************************************************
* Main message loop
*************************************************************************
*/
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}/* WinMain */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -