📄 windiff.c
字号:
*/
BOOL
InitApplication(HINSTANCE hInstance)
{
WNDCLASS wc;
BOOL resp;
/* register the bar window class */
InitBarClass(hInstance);
wc.style = 0;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, "WinDiff");
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszClassName = "WinDiffViewerClass";
wc.lpszMenuName = NULL;
resp = RegisterClass(&wc);
return(resp);
}
/***************************************************************************
* Function: InitInstance
*
* Purpose:
*
* Create and show the windows
*/
BOOL
InitInstance(HINSTANCE hInstance, int nCmdShow)
{
RECT rect;
HANDLE hstatus;
int bar_width;
RECT childrc;
hInst = hInstance;
/* initialise a heap. we use this one heap throughout
* the app. for all memory requirements
*/
hHeap = gmem_init();
/* initialise the list package */
List_Init();
hMenu = LoadMenu(hInstance, "WinDiffMenu");
haccel = LoadAccelerators(hInstance, "WinDiffAccel");
/* create the main window */
hwndClient = CreateWindow("WinDiffViewerClass",
"WinDiff",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
hMenu,
hInstance,
NULL
);
if (!hwndClient) {
return(FALSE);
}
/* create 3 child windows, one status, one table and one bar
* Initially, the bar window is hidden and covered by the table.
*/
/* create a status bar window as
* a child of the main window.
*/
/* build a status struct for two labels and an abort button */
hstatus = StatusAlloc(3);
StatusAddItem(hstatus, 0, SF_STATIC, SF_LEFT|SF_VAR|SF_SZMIN, IDL_STATLAB, 14, NULL);
StatusAddItem(hstatus, 1, SF_BUTTON, SF_RIGHT|SF_RAISE, IDM_ABORT, 8,
LoadRcString(IDS_EXIT));
StatusAddItem(hstatus, 2, SF_STATIC, SF_LOWER|SF_LEFT|SF_VAR,
IDL_NAMES, 60, NULL);
/* ask the status bar how high it should be for the controls
* we have chosen, and save this value for re-sizing.
*/
status_height = StatusHeight(hstatus);
/* create a window of this height */
GetClientRect(hwndClient, &rect);
childrc = rect;
childrc.bottom = status_height;
hwndStatus = StatusCreate(hInst, hwndClient, IDC_STATUS, &childrc,
hstatus);
/* layout constants are stated as percentages of the window width */
bar_width = (rect.right - rect.left) * BAR_WIN_WIDTH / 100;
/* create the table class covering all the remaining part of
* the main window
*/
hwndRCD = CreateWindow(TableClassName,
NULL,
WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL,
0,
status_height,
(int)(rect.right - rect.left),
(int)(rect.bottom - status_height),
hwndClient,
(HANDLE) IDC_RCDISP1,
hInst,
NULL);
/* create a bar window as a child of the main window.
* this window remains hidden until we switch into MODE_EXPAND
*/
hwndBar = CreateWindow("BarClass",
NULL,
WS_CHILD | WS_VISIBLE,
0,
status_height,
bar_width,
(int)(rect.bottom - status_height),
hwndClient,
(HANDLE) IDC_BAR,
hInst,
NULL);
/* nMinMax indicates whether we are to be minimised on startup,
* on command line parameters
*/
ShowWindow(hwndBar, SW_HIDE);
if (GetProfileInt(APPNAME, "OutlineSaved", 0))
{
WINDOWPLACEMENT wp;
/* restore the previous expanded size and position */
wp.length = sizeof( WINDOWPLACEMENT );
wp.flags = 0;
wp.showCmd = GetProfileInt( APPNAME, "OutlineShowCmd",
SW_SHOWNORMAL);
wp.ptMaxPosition.x = GetProfileInt( APPNAME, "OutlineMaxX", 0);
wp.ptMaxPosition.y = GetProfileInt( APPNAME, "OutlineMaxY", 0);
wp.rcNormalPosition.left = (int)GetProfileInt( APPNAME, "OutlineNormLeft", (UINT)(-1));
wp.rcNormalPosition.top = (int)GetProfileInt( APPNAME, "OutlineNormTop", (UINT)(-1));
wp.rcNormalPosition.right = (int)GetProfileInt( APPNAME, "OutlineNormRight", (UINT)(-1));
wp.rcNormalPosition.bottom = (int)GetProfileInt( APPNAME, "OutlineNormBottom",(UINT)(-1));
SetWindowPlacement(hwndClient,&wp);
}
else ShowWindow(hwndClient, nMinMax);
UpdateWindow(hwndClient);
/* initialise busy flag and status line to show we are idle
* (ie not comparing or scanning)
*/
SetNotBusy();
return(TRUE);
} /* InitInstance */
/***************************************************************************
* Function: windiff_usage
*
* Purpose:
*
* Complain to command line users about poor syntax,
* will be replaced by proper help file.
*/
void
windiff_usage(LPSTR msg)
{
int retval;
TCHAR szBuf[MAX_PATH];
if (msg==NULL)
msg = LoadRcString(IDS_USAGE_STR);
LoadString(hInst, IDS_WINDIFF_USAGE, szBuf, sizeof(szBuf));
retval = MessageBox(hwndClient,
msg,
szBuf, MB_ICONINFORMATION|MB_OKCANCEL);
if (retval == IDCANCEL) {
exit(1);
}
}
/***************************************************************************
* Function: ParseArgs
*
* Purpose:
*
* Parse command line arguments
*
* The user can give one or two paths. If only one, we assume the second
* is '.' for the current directory. If one of the two paths is a directory
* and the other a file, we compare a file of the same name in the two dirs.
*
* The command -s filename causes the outline list to be written to a file
* and then the program exits. -s{slrd} filename allows selection of which
* files are written out; by default, we assume -sld for files left and different.
*
* -T means tree. Go deep.
*
* The default is Deep, -L overrides and implies shallow, -T overrides -L
*/
void
ParseArgs(int argc, char ** argv)
{
int i;
LPSTR chp;
PTHREADARGS ta;
DWORD threadid;
/* thread args can't be on the stack since the stack will change
* before the thread completes execution
*/
ta = (PTHREADARGS) gmem_get(hHeap, sizeof(THREADARGS));
ta->first = NULL;
ta->second = NULL;
ta->savelist = NULL;
ta->saveopts = 0;
ta->fDeep = FALSE; /* No -T option seen yet */
for (i = 1; i < argc; i++) {
/* is this an option ? */
if ((argv[i][0] == '-') || (argv[i][0] == '/')) {
switch(argv[i][1]) {
case 's':
case 'S':
/* read letters for the save option: s,l,r,d */
for(chp = &argv[i][2]; *chp != '\0'; chp++) {
switch(*chp) {
case 's':
case 'S':
ta->saveopts |= INCLUDE_SAME;
break;
case 'l':
case 'L':
ta->saveopts |= INCLUDE_LEFTONLY;
break;
case 'r':
case 'R':
ta->saveopts |= INCLUDE_RIGHTONLY;
break;
case 'd':
case 'D':
ta->saveopts |= INCLUDE_DIFFER;
break;
default:
windiff_usage(NULL);
return;
}
}
if (ta->saveopts == 0) {
/* default to left and differ */
ta->saveopts = (INCLUDE_LEFTONLY) | (INCLUDE_DIFFER);
}
ta->savelist = argv[++i];
break;
case 't':
case 'T':
ta->fDeep = TRUE;
break;
default:
windiff_usage(NULL);
return;
}
} else {
if (ta->first == NULL) {
ta->first = argv[i];
} else {
ta->second = argv[i];
}
}
}
/* set the correct depth */
if (ta->fDeep)
; /* explicitly set -- leave it alone */
else ta->fDeep = TRUE; /* global default */
/* any paths to scan ? */
if (ta->first == NULL) {
return;
}
if (ta->second == NULL) {
ta->second = ".";
}
SetBusy();
/* minimise the window if -s flag given */
if (ta->savelist != NULL) {
ShowWindow(hwndClient, SW_MINIMIZE);
}
/* make an empty view */
current_view = view_new(hwndRCD);
DisplayMode = MODE_OUTLINE;
ta->view = current_view;
/* attempt to create a worker thread */
ghThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)wd_initial, (LPVOID) ta,
0, &threadid);
if (ghThread == NULL)
{
wd_initial( (LPVOID) ta);
}
} /* ParseArgs */
/***************************************************************************
* Function: CreateTools
*
* Purpose:
*
* Create any pens/brushes, and read defaults
* from the profile file for menu settings etc.
*/
void
CreateTools(void)
{
/* standard message that table class sends us for
* notifications and queries.
*/
table_msgcode = RegisterWindowMessage(TableMessage);
line_numbers = GetProfileInt(APPNAME, "LineNumbers", line_numbers);
outline_include = GetProfileInt(APPNAME, "FileInclude", outline_include);
ignore_blanks = GetProfileInt(APPNAME, "Blanks", ignore_blanks);
picture_mode = GetProfileInt(APPNAME, "Picture", picture_mode);
GetProfileString(APPNAME, "Editor", editor_cmdline, (LPTSTR)editor_cmdline,
sizeof(editor_cmdline));
InitializeCriticalSection(&CSWindiff);
}
/***************************************************************************
* Function: DeleteTools
*
* Purpose:
*
* Delete any pens or brushes that were created in CreateTools
*/
void
DeleteTools(void)
{
DeleteCriticalSection(&CSWindiff);
}
/***************************************************************************
* Function:
*
* Purpose:
*
* Check whether we have had an abort request (IDM_ABORT), and
* return TRUE if abort requested, otherwise FALSE
*/
BOOL
Poll(void)
{
return(bAbort);
}
/***************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -