📄 x3.c
字号:
//-------------------------------------------------------------------------
#ifdef TEST
BOOL CALLBACK enumfunc(HWND wnd, int param)
{
FILE *fil = fopen("q", "a");
char buf[256], buf2[256];
int id = GetWindowLong(wnd, GWL_ID);
GetClassName(wnd, buf, 256);
GetWindowText(wnd, buf2, 256);
fprintf(fil, "%s(%s): %d\n", buf2, buf, id);
fclose(fil);
return TRUE;
}
#endif
/* hook function translates CBN style messaging to EN style messaging */
BOOL CALLBACK findHook(HWND hwnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
if (iMessage == WM_COMMAND)
{
int l = wParam >> 16;
if (l == CBN_SELENDOK)
{
SendMessage((HWND)lParam, WM_SETMODIFY, 1, 0);
// we do this so the edit box will have something in it when the dialog proc checks it
}
if (l == CBN_EDITUPDATE || l == CBN_SELENDOK)
{
SendMessage(hwnd, WM_COMMAND, (EN_UPDATE << 16) + (wParam &0xffff),
lParam);
}
if (l == CBN_EDITCHANGE || l == CBN_SELENDOK)
{
SendMessage(hwnd, WM_COMMAND, (EN_CHANGE << 16) + (wParam &0xffff),
lParam);
}
if ((wParam &0xffff) == IDCANCEL)
goto join;
}
if (iMessage == WM_SYSCOMMAND)
if (wParam == SC_CLOSE)
{
join: if (finding)
{
findflags = 0;
if (IsDlgButtonChecked(hwnd, 1040))
findflags++;
if (IsDlgButtonChecked(hwnd, 1041))
findflags += 2;
if (IsDlgButtonChecked(hwnd, 990))
findflags += 4;
if (IsWindow(GetDlgItem(hwnd, 1057)) && IsDlgButtonChecked(hwnd,
1057))
findflags += 8;
IntToProfile("FindFlags", findflags);
}
else
{
replaceflags = 0;
if (IsDlgButtonChecked(hwnd, 1040))
replaceflags++;
if (IsDlgButtonChecked(hwnd, 1041))
replaceflags += 2;
if (IsDlgButtonChecked(hwnd, 990))
replaceflags += 4;
if (IsWindow(GetDlgItem(hwnd, 1057)) && IsDlgButtonChecked(hwnd,
1057))
replaceflags += 8;
IntToProfile("ReplaceFlags", replaceflags);
}
hwndFind = 0;
}
if (iMessage == WM_INITDIALOG)
{
if (finding)
{
if (findflags &4)
CheckDlgButton(hwnd, 990, 1);
}
else
{
if (replaceflags &4)
CheckDlgButton(hwnd, 990, 1);
}
return 1;
}
else
return 0;
}
//-------------------------------------------------------------------------
void PopFindString(HWND hwnd)
{
char buf[256];
HWND hwndedit;
charinfo a;
if (IsWindow(hwndFind))
{
SetFocus(hwndFind);
return ;
}
if (GetWordFromPos(GetDlgItem(hwnd, ID_EDITCHILD), buf, - 1, 0, 0, 0) &&
buf[0])
strcpy(findbuffer, buf);
find.lStructSize = sizeof(find);
find.hwndOwner = hwndFrame;
find.hInstance = hInstance;
find.Flags = FR_ENABLETEMPLATE | FR_ENABLEHOOK;
if (findflags &1)
find.Flags |= FR_WHOLEWORD;
if (findflags &2)
find.Flags |= FR_MATCHCASE;
if (findflags &8)
find.Flags |= FR_DOWN;
find.lpstrFindWhat = findbuffer;
find.lpstrReplaceWith = 0;
find .wFindWhatLen = 256;
find .wReplaceWithLen = 0;
find.lpTemplateName = "FINDDLG";
find.lpfnHook = findHook;
finding = TRUE;
hwndFind = FindText(&find);
hwndedit = GetDlgItem(hwndFind, 1152);
SubClassHistoryCombo(hwndedit);
SendMessage(hwndedit, WM_SETHISTORY, 0, (LPARAM)findhist1);
// EnumChildWindows(hwndFind, (WNDENUMPROC)enumfunc,0) ;
lastfound = - 1;
// SendMessage(GetDlgItem(hwnd,ID_EDITCHILD),EM_GETSEL, (WPARAM)&findpos,0) ;
SendMessage(GetDlgItem(hwnd, ID_EDITCHILD), EM_EXGETSEL, 0, (LPARAM) &a);
findpos = a.min;
}
//-------------------------------------------------------------------------
void PopReplaceString(HWND hwnd)
{
DWINFO *p = (DWINFO*)GetWindowLong(hwnd, 0);
char buf[256];
HWND hwndedit;
charinfo a;
if (IsWindow(hwndFind))
{
SetFocus(hwndFind);
return ;
}
// if (GetWordFromPos(GetDlgItem(hwnd,ID_EDITCHILD),buf,-1,0,0,0) && buf[0])
// strcpy(findbuffer2,buf) ;
replace.lStructSize = sizeof(replace);
replace.hwndOwner = hwndFrame;
replace.hInstance = hInstance;
replace.Flags = FR_ENABLETEMPLATE | FR_ENABLEHOOK | FR_DOWN;
if (replaceflags &1)
find.Flags |= FR_WHOLEWORD;
if (replaceflags &2)
find.Flags |= FR_MATCHCASE;
replace.lpstrFindWhat = findbuffer2;
replace.lpstrReplaceWith = replacebuffer;
replace .wFindWhatLen = 256;
replace .wReplaceWithLen = 256;
replace.lpTemplateName = "REPLACEDLG";
replace.lpfnHook = findHook;
finding = FALSE;
hwndFind = ReplaceText(&replace);
hwndedit = GetDlgItem(hwndFind, 1152);
SubClassHistoryCombo(hwndedit);
SendMessage(hwndedit, WM_SETHISTORY, 0, (LPARAM)findhist2);
hwndedit = GetDlgItem(hwndFind, 1153);
SubClassHistoryCombo(hwndedit);
SendMessage(hwndedit, WM_SETHISTORY, 0, (LPARAM)replacehist);
lastfound = - 1;
SendMessage(GetDlgItem(hwnd, ID_EDITCHILD), EM_EXGETSEL, 0, (LPARAM) &a);
findpos = a.min;
if (a.min != a.max)
CheckRadioButton(hwndFind, IDC_RADIO_ALL_TEXT, IDC_RADIO_SELECTED_TEXT,
IDC_RADIO_SELECTED_TEXT);
else
CheckRadioButton(hwndFind, IDC_RADIO_ALL_TEXT, IDC_RADIO_SELECTED_TEXT,
IDC_RADIO_ALL_TEXT);
}
//-------------------------------------------------------------------------
int xfind(FINDREPLACE *find, char *buf, int pos, int *len, struct re_registers
**r, int *n)
{
int flags = find->Flags;
int i;
if (!find->lpstrFindWhat)
return - 1;
if (pos < 0)
pos = 0;
*len = strlen(find->lpstrFindWhat);
while (TRUE)
{
if (IsWindow(GetDlgItem(hwndFind, 990)) && IsDlgButtonChecked(hwndFind,
990))
{
#ifdef XREGEX_POSIX
regex_t preg;
regmatch_t match[1];
int err = regcomp(&preg, find->lpstrFindWhat, REG_EXTENDED | (
(flags &FR_MATCHCASE) ? 0 : REG_ICASE) | REG_NEWLINE);
if (err)
{
char ebuf[256];
regerror(err, &preg, ebuf, 256);
ExtendedMessageBox("Regular Expression Error",
MB_SETFOREGROUND | MB_SYSTEMMODAL, ebuf);
return - 1;
} if (!regexec(&preg, buf + pos, 1, &match, 0))
{
regfree(&preg);
*len = match->rm_eo - match->rm_so;
pos = match->rm_so + pos + buf;
}
else
{
regfree(&preg);
return - 1;
}
#else
// This isn't a full emacs version
char *err;
static struct re_pattern_buffer patbuf;
static struct re_registers registers;
static unsigned char trans[256], fastmap[256];
re_set_syntax(RE_SYNTAX_EMACS | RE_NEWLINE_ALT |
RE_CHAR_CLASSES | RE_INTERVALS);
patbuf.translate = &trans;
for (i = 0; i < 256; i++)
trans[i] = i;
if (!(flags &FR_MATCHCASE))
for (i = 'a'; i <= 'z'; i++)
trans[i] = i - 'a' + 'A';
patbuf.fastmap = &fastmap;
patbuf.fastmap_accurate = FALSE;
err = re_compile_pattern(find->lpstrFindWhat, strlen(find
->lpstrFindWhat), &patbuf);
if (err)
{
ExtendedMessageBox("Regular Expression Error",
MB_SETFOREGROUND | MB_SYSTEMMODAL, err);
return - 1;
} i = strlen(buf);
if (flags &FR_DOWN)
i = re_search(&patbuf, buf, i, pos, i - pos, ®isters);
else
i = re_search(&patbuf, buf, i, pos, - pos, ®isters);
if (i < 0)
return - 1;
if (r)
*r = ®isters;
if (n)
*n = patbuf.re_nsub;
*len = registers.end[0] - registers.start[0];
pos = registers.start[0] + buf;
#endif
}
else if (flags &FR_DOWN)
{
if (flags &FR_MATCHCASE)
pos = (int)strstr(buf + pos, find->lpstrFindWhat);
else
pos = (int)stristr(buf + pos, find->lpstrFindWhat);
}
else
{
do
{
int l = strlen(find->lpstrFindWhat);
if (flags &FR_MATCHCASE)
{
if (!strncmp(buf + pos, find->lpstrFindWhat, l))
break;
}
else
if (!strnicmp(buf + pos, find->lpstrFindWhat, l))
break;
pos--;
}
while (pos >= 0);
if (pos < 0)
pos = 0;
else
pos = pos + buf;
}
if (pos)
{
pos = (char*)pos - buf;
if (flags &FR_WHOLEWORD)
{
if (pos && isalnum(buf[pos - 1]))
pos += *len;
else if (!buf[pos + *len] || !isalnum(buf[pos + *len]))
return pos;
else
pos += *len;
}
else
return pos;
}
else
return - 1;
}
}
//-------------------------------------------------------------------------
void MoveFindWindow(HWND editwnd, int left, int right)
{
POINTL ptl, ptr;
RECT w, f, s;
int th = SendMessage(editwnd, EM_GETTEXTHEIGHT, 0, 0);
SendMessage(editwnd, EM_POSFROMCHAR, (WPARAM) &ptl, left);
SendMessage(editwnd, EM_POSFROMCHAR, (WPARAM) &ptr, right);
GetWindowRect(editwnd, &w);
GetWindowRect(hwndFind, &f);
if (IntersectRect(&s, &w, &f))
{
if (ptl.y >= (w.bottom - w.top) / 2)
{
MoveWindow(hwndFind, f.left, w.top, f.right - f.left, f.bottom -
f.top, TRUE);
}
else
{
MoveWindow(hwndFind, f.left, w.bottom - (f.bottom - f.top), f.right
- f.left, f.bottom - f.top, TRUE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -