📄 gvwinit.c
字号:
button_size.y = 24;
info_rect.left = 0;
info_rect.right = info_rect.left + 96 * char_size.x;
info_rect.bottom = height;
info_rect.top = info_rect.bottom - char_size.y - 4;
// buttons at top
button_shift.x = button_size.x - 1;
button_shift.y = 0;
button_rect.top = 0;
button_rect.left = 0;
button_rect.right = 0; /* don't care */
button_rect.bottom = button_size.y+1;
if (!option.button_show)
button_rect.bottom = 0;
img_offset.x = 0;
img_offset.y = button_rect.bottom + 1;
info_file.x = info_rect.left + 2;
info_file.y = info_rect.top + 3;
info_coord.left = info_rect.left + 42 * char_size.x;
info_coord.right = info_rect.left + 62 * char_size.x;
info_coord.top = info_rect.top + 3;
info_coord.bottom = info_coord.top + char_size.y+2;
info_page.x = info_rect.left + 64 * char_size.x + 2;
info_page.y = info_rect.top + 3;
}
/* create gsview window menu bar, buttons and child window */
void
gsview_create()
{
int i;
WNDCLASS wndclass;
HGLOBAL hglobal;
short *pButtonID;
HWND hbutton;
WNDPROC lpfnMenuButtonProc;
RECT rect;
int x, y;
/* setup OPENFILENAME struct */
ofn.lpstrFilter = (LPTSTR)NULL;
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwndimg;
ofn.nFilterIndex = FILTER_PS;
ofn.lpstrFile = szOFilename;
ofn.nMaxFile = sizeof(szOFilename);
ofn.lpstrFileTitle = (LPTSTR)NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrTitle = (LPTSTR)NULL;
ofn.lpstrInitialDir = (LPTSTR)NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_SHOWHELP;
nHelpTopic = IDS_TOPICROOT;
/* set size of info area, buttons and offset to child window */
GetClientRect(hwndimg, &rect);
calc_info_button_areas(rect.right-rect.left, rect.bottom-rect.top);
hcWait = LoadCursor((HINSTANCE)NULL, IDC_WAIT);
hcHand = LoadCursor(phInstance,MAKEINTRESOURCE(IDP_HAND));
/* add buttons */
lpfnMenuButtonProc = (WNDPROC)MakeProcInstance((FARPROC)MenuButtonProc, phInstance);
/* get default button class info */
GetClassInfo((HINSTANCE)NULL, TEXT("button"), &wndclass);
lpfnButtonWndProc = wndclass.lpfnWndProc;
hglobal = LoadResource(phInstance, FindResource(phInstance, MAKEINTRESOURCE(IDR_BUTTON), RT_RCDATA));
if ( (pButtonID = (short *)LockResource(hglobal)) == (short *)NULL)
return;
x = button_rect.left;
y = button_rect.top+1;
for (i=0; pButtonID[i]; i++) {
if (pButtonID[i] < 100) {
/* not a button, but a spacer */
x += pButtonID[i];
}
else {
hbutton = CreateWindow(TEXT("button"), NULL,
WS_CHILD | BS_OWNERDRAW |
(option.button_show ? WS_VISIBLE : 0),
x, y, button_size.x, button_size.y,
hwndimg, (HMENU)(int)pButtonID[i],
phInstance, NULL);
SetWindowLong(hbutton, GWL_WNDPROC, (LONG)lpfnMenuButtonProc);
if (hbutton) {
if (buttonhead == (struct buttonlist *)NULL)
buttontail = buttonhead = (struct buttonlist *)
malloc(sizeof(struct buttonlist));
else {
buttontail->next = (struct buttonlist *)
malloc(sizeof(struct buttonlist));
buttontail = buttontail->next;
}
buttontail->hbutton = hbutton;
buttontail->next = NULL;
}
x += button_shift.x;
y += button_shift.y;
}
}
FreeResource(hglobal);
/* create child window */
GetClientRect(hwndimg, &rect);
hwnd_image = hwndimgchild =
CreateWindow(szImgClassName, szAppName,
WS_CHILD /* | WS_VISIBLE */,
rect.left, rect.top,
rect.right-rect.left, rect.bottom-rect.top,
hwndimg, NULL, phInstance, (void FAR *)NULL);
}
void
show_buttons(void)
{
struct buttonlist *bp = buttonhead;
RECT rect;
GetClientRect(hwndimg, &rect);
calc_info_button_areas(rect.right - rect.left, rect.bottom - rect.top);
SetWindowPos(hwndimgchild, (HWND)NULL,
rect.left+img_offset.x, rect.top+img_offset.y,
rect.right-img_offset.x, info_rect.top-img_offset.y,
SWP_NOZORDER | SWP_NOACTIVATE);
while (bp) {
ShowWindow(bp->hbutton, option.button_show ? SW_SHOWNA : SW_HIDE);
bp = bp->next;
}
InvalidateRect(hwndimg, &rect, TRUE);
UpdateWindow(hwndimg);
}
char hkey_root[]="HKEY_CLASSES_ROOT";
char reg_win32s_error[]="ERROR: You can't set named values under Win32s\n";
void
reg_quote(char *d, char *s)
{
while (*s) {
if (*s == '\\')
*d++ = '\\';
*d++ = *s++;
}
*d = *s;
}
/* Open the key. If it doesn't exist, create it */
BOOL
reg_open_key(FILE *newfile, FILE *oldfile, char *name, HKEY *hkey)
{
LONG lrc;
lrc = RegOpenKeyA(HKEY_CLASSES_ROOT, name, hkey);
if (lrc == ERROR_SUCCESS) {
if (oldfile)
fprintf(oldfile, "\n[%s\\%s]\n", hkey_root, name);
}
else {
lrc = RegCreateKeyA(HKEY_CLASSES_ROOT, name, hkey);
}
if (newfile)
fprintf(newfile, "\n[%s\\%s]\n", hkey_root, name);
if (lrc != ERROR_SUCCESS)
*hkey = HKEY_CLASSES_ROOT;
return (lrc == ERROR_SUCCESS);
}
BOOL
reg_set_value(FILE *newfile, FILE *oldfile, HKEY hkey, char *name, char *value)
{
DWORD keytype;
DWORD cbData;
char buf[MAXSTR];
char qbuf[MAXSTR];
LONG lenbuf;
if (hkey == HKEY_CLASSES_ROOT)
return FALSE;
if (oldfile) {
lenbuf = sizeof(buf);
if (name==(char *)NULL) {
if (RegQueryValueA(hkey, (LPSTR)name, (LPSTR)buf, &lenbuf)
== ERROR_SUCCESS) {
if (strlen(buf)) {
reg_quote(qbuf, buf);
fprintf(oldfile, "@=\042%s\042\n", qbuf);
}
}
}
else if (!is_win32s) {
cbData = sizeof(buf);
keytype = REG_SZ;
if (RegQueryValueExA(hkey, name, 0, &keytype,
(LPBYTE)buf, &cbData) == ERROR_SUCCESS) {
reg_quote(qbuf, buf);
fprintf(oldfile, "\042%s\042=\042%s\042\n", name, qbuf);
}
}
else {
fprintf(oldfile, reg_win32s_error);
return FALSE;
}
}
if (name==(char *)NULL) {
reg_quote(qbuf, value);
if (newfile)
fprintf(newfile, "@=\042%s\042\n", qbuf);
if (RegSetValueA(hkey, NULL, REG_SZ,
value, strlen(value)) != ERROR_SUCCESS)
return FALSE;
}
else if (!is_win32s) {
reg_quote(qbuf, value);
if (newfile)
fprintf(newfile, "\042%s\042=\042%s\042\n", name, qbuf);
if (RegSetValueExA(hkey, name, 0, REG_SZ,
(CONST BYTE *)value, strlen(value)+1) != ERROR_SUCCESS)
return FALSE;
}
else {
if (newfile)
fprintf(newfile, reg_win32s_error);
return FALSE;
}
return TRUE;
}
void
reg_close_key(HKEY *hkey)
{
RegCloseKey(*hkey);
*hkey = HKEY_CLASSES_ROOT;
}
BOOL
create_registry_type(FILE *newfile, FILE *oldfile,
char *keyname, char *description)
{
HKEY hkey;
char buf[MAXSTR];
char kbuf[MAXSTR];
const char shellsubkey[]= "\\shell";
const char opensubkey[] = "\\open";
const char printsubkey[] = "\\print";
const char commandsubkey[] = "\\command";
BOOL flag = TRUE;
if (flag)
flag = reg_open_key(newfile, oldfile, keyname, &hkey);
if (flag) {
flag = reg_set_value(newfile, oldfile, hkey, NULL, description);
reg_close_key(&hkey);
}
strcpy(kbuf, keyname);
strcat(kbuf, shellsubkey);
if (flag)
flag = reg_open_key(newfile, oldfile, kbuf, &hkey);
if (flag)
reg_close_key(&hkey);
strcat(kbuf, opensubkey);
if (flag)
flag = reg_open_key(newfile, oldfile, kbuf, &hkey);
if (flag)
reg_close_key(&hkey);
strcat(kbuf, commandsubkey);
if (flag)
flag = reg_open_key(newfile, oldfile, kbuf, &hkey);
if (!is_win32s)
sprintf(buf, "\042%s%s\042 \042%%1\042", szExePath, GSVIEW_EXENAME);
else
sprintf(buf, "%s%s %%1", szExePath, GSVIEW_EXENAME);
if (flag) {
flag = reg_set_value(newfile, oldfile, hkey, NULL, buf);
reg_close_key(&hkey);
}
strcpy(kbuf, keyname);
strcat(kbuf, shellsubkey);
strcat(kbuf, printsubkey);
if (flag)
flag = reg_open_key(newfile, oldfile, kbuf, &hkey);
if (flag)
reg_close_key(&hkey);
strcat(kbuf, commandsubkey);
if (flag)
flag = reg_open_key(newfile, oldfile, kbuf, &hkey);
if (!is_win32s)
sprintf(buf, "\042%s%s\042 /p \042%%1\042", szExePath, GSVIEW_EXENAME);
else
sprintf(buf, "%s%s /p %%1", szExePath, GSVIEW_EXENAME);
if (flag) {
flag = reg_set_value(newfile, oldfile, hkey, NULL, buf);
reg_close_key(&hkey);
}
if (is_win4) {
strcpy(kbuf, keyname);
strcat(kbuf, "\\DefaultIcon");
if (flag)
flag = reg_open_key(newfile, oldfile, kbuf, &hkey);
sprintf(buf, "%s%s,3", szExePath, GSVIEW_EXENAME);
if (flag) {
flag = reg_set_value(newfile, oldfile, hkey, NULL, buf);
reg_close_key(&hkey);
}
}
return flag;
}
int
update_registry(BOOL ps, BOOL pdf)
{
char *psmime="application/postscript";
char *pdfmime="application/pdf";
char *contentname="Content Type";
char *extension="Extension";
char buf[MAXSTR];
HKEY hkey;
char *pskey="psfile";
char *pdfkey="pdffile";
char *psext=".ps";
char *epsext=".eps";
char *pdfext=".pdf";
char *p;
FILE *oldfile, *newfile;
BOOL flag = TRUE;
const char regheader[]="REGEDIT4\n";
if (!ps && !pdf)
return 0;
convert_widechar(buf, szExePath, sizeof(buf));
strcat(buf, GSVIEW_ZIP);
p = strrchr(buf, '.');
/* Write the old registry file, but only if it doesn't exist */
strcpy(p, "old.reg");
oldfile = fopen(buf, "r");
if (oldfile == (FILE *)NULL) {
oldfile = fopen(buf, "w");
/* If we failed to open the file, the destination is probably
* read only. Don't worry, just don't write to the log file.
*/
}
else {
fclose(oldfile);
oldfile = (FILE *)NULL;
}
/* Write the new registry file */
strcpy(p, "new.reg");
newfile = fopen(buf, "w");
if (oldfile != (FILE *)NULL)
fprintf(oldfile, regheader);
if (newfile != (FILE *)NULL)
fprintf(newfile, regheader);
if (ps) {
if (flag)
flag = reg_open_key(newfile, oldfile, psext, &hkey);
if (flag) {
flag = reg_set_value(newfile, oldfile, hkey, NULL, pskey);
if (flag && !is_win32s)
reg_set_value(newfile, oldfile, hkey, contentname, psmime);
reg_close_key(&hkey);
}
if (flag)
flag = reg_open_key(newfile, oldfile, epsext, &hkey);
if (flag) {
flag = reg_set_value(newfile, oldfile, hkey, NULL, pskey);
if (flag && !is_win32s)
flag = reg_set_value(newfile, oldfile, hkey,
contentname, psmime);
reg_close_key(&hkey);
}
/* Don't bother with undelete information for these */
if (!is_win32s) {
sprintf(buf, "MIME\\Database\\%s\\%s", contentname, psmime);
if (flag)
flag = reg_open_key(newfile, oldfile, buf, &hkey);
if (flag) {
flag = reg_set_value(newfile, oldfile, hkey, extension, psext);
reg_close_key(&hkey);
}
}
if (flag)
flag = create_registry_type(newfile, oldfile, pskey, "PostScript");
}
if (pdf) {
if (flag)
flag = reg_open_key(newfile, oldfile, pdfext, &hkey);
if (flag) {
flag = reg_set_value(newfile, oldfile, hkey, NULL, pdfkey);
if (flag && !is_win32s)
reg_set_value(newfile, oldfile, hkey, contentname, pdfmime);
reg_close_key(&hkey);
}
/* Don't bother with undelete information for these */
if (!is_win32s) {
sprintf(buf, "MIME\\Database\\%s\\%s", contentname, pdfmime);
if (flag)
flag = reg_open_key(newfile, oldfile, buf, &hkey);
if (flag) {
flag = reg_set_value(newfile, oldfile, hkey, extension, pdfext);
reg_close_key(&hkey);
}
}
if (flag)
flag = create_registry_type(newfile, oldfile, pdfkey, "Portable Document Format");
}
if (oldfile)
fclose(oldfile);
if (newfile)
fclose(newfile);
return !flag;
}
int
gsview_create_objects(char *groupname)
{
char gspath[MAXSTR];
char *p;
int rc;
char exepath[MAXSTR];
convert_widechar(exepath, szExePath, sizeof(exepath)-1);
strcpy(gspath, option.gsdll);
if ((p = strrchr(gspath,'\\')) != (char *)NULL)
p++;
else
p = gspath;
*p = '\0';
rc = gsview_progman(groupname, exepath,
option.gsversion, gspath, option.gsinclude);
if (rc)
gserror(IDS_NOPROGMAN, NULL, 0, SOUND_ERROR);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -