⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gvwinit.c

📁 GSview 4.6 PostScript previewer。Ghostscript在MS-Windows, OS/2 and Unix下的图形化接口
💻 C
📖 第 1 页 / 共 5 页
字号:
char buf[MAXSTR];
int count;
char *p;
int language;
    /* if Window language doesn't match GSview language */
    GetProfileStringA("Intl", "sLanguage", "ENG", winlang, sizeof(winlang));
    LoadStringA(hlanguage, IDS_SLANGUAGE, buf, sizeof(buf)-1);
    /* buf contains valid language code and length */
    p = strtok(buf, ",");
    p = strtok(NULL, ",");
    count = atoi(p);
    if (count > 3)
	count = 3;

    if (strnicmp(winlang, buf, count) != 0) {
	language = DialogBoxParamL(hlanguage, MAKEINTRESOURCE(IDD_LANG), 
	    hwndimg, LanguageDlgProc, (LPARAM)NULL);
	if (language) 
	    gsview_language(language);
    }
}

void
post_args(void)
{
    PostMessage(hwndimg, WM_COMMAND, IDM_ARGS, (LPARAM)&args); 
}

void
system_colours(void)
{
LOGBRUSH lb;
    if (hpen_btnshadow)
	DeleteBrush(hpen_btnshadow);
    hpen_btnshadow = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNSHADOW));
    if (hpen_btnhighlight)
	DeleteBrush(hpen_btnhighlight);
    hpen_btnhighlight = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNHIGHLIGHT));
    lb.lbStyle = BS_SOLID;
    lb.lbHatch = 0;
    lb.lbColor = GetSysColor(COLOR_WINDOW);
    if (lb.lbColor == RGB(255,255,255))	/* don't allow white background */
	lb.lbColor = GetSysColor(COLOR_MENU);
    if (lb.lbColor == RGB(255,255,255))	/* don't allow white background */
	lb.lbColor = GetSysColor(COLOR_APPWORKSPACE);
    if (lb.lbColor == RGB(255,255,255))	/* don't allow white background */
	lb.lbColor = RGB(192,192,192);
    if (hbrush_window)
	DeleteBrush(hbrush_window);
    hbrush_window = CreateBrushIndirect(&lb);
    lb.lbColor = GetSysColor(COLOR_MENU);
    if (hbrush_menu)
	DeleteBrush(hbrush_menu);
    hbrush_menu =  CreateBrushIndirect(&lb);

    /* change class background brush of main and image windows */
    SetClassLong(hwndimg, GCL_HBRBACKGROUND, (LONG)hbrush_window);
    SetClassLong(hwndimgchild, GCL_HBRBACKGROUND, (LONG)hbrush_window);
}

/* main initialisation */
BOOL
gsview_init1(int argc, char *argv[])
{
WNDCLASS wndclass;
DWORD version = GetVersion();
int length = 64;
int badarg;
	getcwd(workdir, sizeof(workdir));

	while (length && !SetMessageQueue(length))
	    length--;	/* reduce size and try again */
	if (length == 0)
	    exit(0);	/* panic */
	
	/* figure out which version of Windows */
	/* Win32s: bit 15 HIWORD is 1 and bit 14 is 0 */
	/* Win95:  bit 15 HIWORD is 1 and bit 14 is 1 */
	/* WinNT:  bit 15 HIWORD is 0 and bit 14 is 0 */
	/* WinNT with Win95 shell recognised by WinNT + LOBYTE(LOWORD) >= 4 */
	/* check if Windows NT */
	if ((HIWORD(version) & 0x8000)==0)
	    is_winnt = TRUE;
	/* check if Windows 95 (Windows 4.0) */
	if ( ((HIWORD(version) & 0x8000)!=0) && ((HIWORD(version) & 0x4000)!=0) )
	    is_win95 = TRUE;
	/* Win32s */
	if ( ((HIWORD(version) & 0x8000)!=0) && ((HIWORD(version) & 0x4000)==0) )
	    is_win32s = TRUE;
	/* Windows 4.0 */
	if (LOBYTE(LOWORD(version)) >= 4)
	    is_win4 = TRUE;
	if (is_win95 && is_win4 && HIBYTE(LOWORD(version)) >= 10)
	    is_win98 = TRUE;

	if (is_win95 || is_winnt)
	    args.multithread = TRUE;

        init_displays();

	badarg = parse_argv(&args, argc, argv);
	parse_args(&args);

	if (args.exit_existing) {
	    dde_execute("[FileExit()]");
	    dde_exit = TRUE;
	}
	if (args.existing) {
	    int i;
	    LPSTR line;
	    int len = 0;
	    for (i=args.existing+1; i<argc; i++)
		len += strlen(argv[i]) + 3; /* "\042arg\042 " */
	    line = (LPSTR)malloc(len+1);
	    if (line == NULL)
		return FALSE;
	    line[0] = '\0';
	    for (i=args.existing+1; i<argc; i++) {
		strcat(line, "\042");
		strcat(line, argv[i]);
		strcat(line, "\042 ");
	    }
	    if (dde_execute_line(line))
		dde_exit = TRUE;
	    dde_execute("[ShowWindow(1)]");
	    free(line);
	    args.existing = FALSE;
	}

	if (dde_exit)
	    return FALSE;

	if (is_win32s) {
	    /* don't allow multiple copies under Win32s */
	    HWND hwnd = FindWindow(szClassName, NULL);
	    if (hwnd != (HWND)NULL) {
		gsview_init0(GetCommandLineA());
		return FALSE;
	    }
	}
	if (is_win95 || is_winnt) {
	    if (multithread) {
		display.event = CreateEvent(NULL, TRUE, FALSE, NULL);
		if (!display.event) {
		    multithread = FALSE;
		    error_message("Failed to create display.event object");
		}
		if (multithread)
		    InitializeCriticalSection(&crit_sec);

		if (multithread)
		    hmutex_ps = CreateMutex(NULL, FALSE, NULL);
		if (hmutex_ps == NULL) {
		    error_message("Failed to create mutex");
		    multithread = FALSE;
		}

		if (multithread)
		    image.hmutex = CreateMutex(NULL, FALSE, NULL);
		if (image.hmutex == NULL) {
		    error_message("Failed to create mutex");
		    multithread = FALSE;
		}
	    }
	}

	/* get path to EXE */
	GetModuleFileName(phInstance, szExePath, sizeof(szExePath));
	{ int i;
	  for (i=lstrlen(szExePath)-1; i>0; i--)
	    if (szExePath[i] == '\\') {
		szExePath[i+1] = '\0';
		break;
	    }
	}

	/* Find available language DLLs */
        language_find();

	/* get path to INI file */
	szIniFile[0] = '\0';
	/* strcpy(szIniFile, szExePath); */
	/* allow for user profiles */
	if (is_win4) {
	    LONG rc;
	    HKEY hkey;
	    DWORD keytype;
	    DWORD cbData;
	    DWORD fa;
	    /* Find the user profile directory */
	    rc = RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\ProfileReconciliation", 0, KEY_READ, &hkey);
	    if (rc == ERROR_SUCCESS) {
		cbData = sizeof(szIniFile)-sizeof(INIFILE);
		keytype =  REG_SZ;
		rc = RegQueryValueExA(hkey, "ProfileDirectory", 0, &keytype, (LPBYTE)szIniFile, &cbData);
		RegCloseKey(hkey);
	    }
	    if (rc == ERROR_SUCCESS) {
		fa = GetFileAttributesA(szIniFile);
		if ((fa != 0xffffffff) && (fa & FILE_ATTRIBUTE_DIRECTORY))
		    strcat(szIniFile, "\\");
		else
		    szIniFile[0] = '\0';
	    }
	    else {
		    /* If we didn't succeed, use the Windows directory */
		    szIniFile[0] = '\0';
	    }
	}
	if (szIniFile[0] == '\0') {
	    DWORD fa;
	    /* If we didn't succeed, try %USERPROFILE% */
	    char *p = getenv("USERPROFILE");
	    if (p && *p) {
		strcpy(szIniFile, p);
#ifdef __BORLANDC__
		OemToCharBuff(szIniFile, szIniFile, lstrlen(szIniFile));
#endif
		p = szIniFile + strlen(szIniFile) - 1;
		if ((*p == '\\') || (*p == '/'))
		    *p = '\0';
		/* check if USERPROFILE contains a directory name */
		fa = GetFileAttributesA(szIniFile);
		if ((fa != 0xffffffff) && (fa & FILE_ATTRIBUTE_DIRECTORY))
		    strcat(szIniFile, "\\");
		else
		    szIniFile[0] = '\0';
	    }
	}
	if (szIniFile[0] == '\0') {
	    TCHAR tbuf[MAXSTR];
	    GetWindowsDirectory(tbuf, 
		sizeof(tbuf)/sizeof(TCHAR)-2-sizeof(INIFILE));
	    convert_widechar(szIniFile, tbuf, sizeof(szIniFile));
	    strcat(szIniFile, "\\");
	}
	strcat(szIniFile, INIFILE);

	/* defaults if entry not in gsview.ini */
 	init_options();
	/* read entries from gsview.ini */
	read_profile(szIniFile);

 	use_args(&args);

	if (debug) {
	    gs_addmess("INI file is \042");
	    gs_addmess(szIniFile);
	    gs_addmess("\042\n");
	}

	if (!load_language(option.language)) {
	    message_box(TEXT("Couldn't load language specific resources.  Resetting to English."), 0);
	    option.language = IDM_LANGEN;
	    if (!load_language(option.language))
		message_box(TEXT("Couldn't load English resources.  Please reinstall GSview"), 0);
	}

	system_colours();

        view_init(&view);

	/* register the child image window class */
	wndclass.style = CS_HREDRAW | CS_VREDRAW;
	wndclass.lpfnWndProc = WndImgChildProc;
	wndclass.cbClsExtra = 0;
	wndclass.cbWndExtra = sizeof(LONG);
	wndclass.hInstance = phInstance;
	wndclass.hIcon = LoadIcon(phInstance,MAKEINTRESOURCE(ID_GSVIEW));
/*
	wndclass.hCursor = LoadCursor((HINSTANCE)NULL, IDC_CROSS);
*/
	wndclass.hCursor = hcCrossHair = LoadCursor(phInstance,MAKEINTRESOURCE(IDP_CROSSHAIR)); 
	wndclass.hbrBackground =  hbrush_window;
	wndclass.lpszMenuName = NULL;
	wndclass.lpszClassName = szImgClassName;
	RegisterClass(&wndclass);
	
	/* register the parent window class */
	wndclass.style = CS_HREDRAW | CS_VREDRAW;
	wndclass.lpfnWndProc = WndImgProc;
	wndclass.cbClsExtra = 0;
	wndclass.cbWndExtra = sizeof(LONG);
	wndclass.hInstance = phInstance;
	wndclass.hIcon = LoadIcon(phInstance,MAKEINTRESOURCE(ID_GSVIEW));
	wndclass.hCursor = LoadCursor((HINSTANCE)NULL, IDC_ARROW);
	wndclass.hbrBackground =  hbrush_window;
	wndclass.lpszMenuName = NULL;
	wndclass.lpszClassName = szClassName;
	RegisterClass(&wndclass);

	/* do not allow window to be entirely off-screen */
	if (option.img_size.x + option.img_origin.x < 16)
	    option.img_origin.x = 0;
	if (option.img_size.y + option.img_origin.y < 16)
	    option.img_origin.y = 0;

	/* create parent window */
	hwndimg = CreateWindow(szClassName, szAppName,
		  WS_OVERLAPPEDWINDOW,
		  option.img_origin.x, option.img_origin.y, 
		  option.img_size.x, option.img_size.y, 
		  NULL, NULL, phInstance, (void FAR *)NULL);

	/* help message for GetOpenFileName Dialog Box */
	help_message = RegisterWindowMessage(HELPMSGSTRING);

	change_language();
        load_string(IDS_WAIT, szWait, sizeof(szWait));	/* generic wait message */

	/* load DLL for sounds */
	/* MMSYSTEM.DLL requires Windows 3.1, so to allow gsview to run
	   under Windows 3.0 we can't use the import library */
	hlib_mmsystem = LoadLibrary(TEXT("WINMM.DLL"));
	if (hlib_mmsystem != NULL) {
#ifdef UNICODE
	    lpfnSndPlaySound = (FPSPS)GetProcAddress(hlib_mmsystem, 
		"sndPlaySoundW");
#else
	    lpfnSndPlaySound = (FPSPS)GetProcAddress(hlib_mmsystem, 
		"sndPlaySoundA");
#endif
	}
	else {
	    gserror(IDS_SOUNDNOMM, NULL, MB_ICONEXCLAMATION, -1);
	    hlib_mmsystem = (HINSTANCE)NULL;
	}


	gsview_initc(argc, argv);

	if (badarg) {
	    gs_addmessf("Unknown argument %d: %s\n", badarg, argv[badarg]);
	    gserror(IDS_PARSEERROR, NULL, 0, SOUND_ERROR);
	}
	return TRUE;
}

/* Platform specific preprocessing of arguments */
BOOL
parse_args(GSVIEW_ARGS *args)
{
    char *filename = args->filename;
    debug = args->debug;
    multithread = args->multithread;
    if (is_win32s)
	multithread = FALSE;
    if (args->print || args->convert) {
	print_silent = TRUE;
	print_exit = TRUE;
    }
    if (filename[0]) {
	/* make sure filename contains full path */
	char fullname[MAXSTR+MAXSTR];
	if (filename[0]=='\\' || filename[0]=='/') {
	    if (filename[1] && (filename[1]=='\\' ||  filename[1]=='/')) {
		/* UNC name */
		/* do nothing */
	    }
	    else {
		/* referenced from root directory, so add drive */
		fullname[0] = workdir[0];
		fullname[1] = workdir[1];
		strncpy(fullname+2, filename, sizeof(fullname)-2);
		strncpy(args->filename, fullname, sizeof(args->filename)-1);
	    }
	}
	else if ( ! (isalpha(*filename) && filename[1]==':')) {
	    /* Doesn't include drive code, so add work dir */
	    int j;
	    strcpy(fullname, workdir);
	    j = strlen(workdir) - 1;
	    if ((j >= 0) && !((fullname[j] == '\\') || (fullname[j] == '/')))
		strcat(fullname, "\\");
	    strcat(fullname, filename);
	    strncpy(args->filename, fullname, sizeof(args->filename)-1);
	}
	else {
	    /* contains full path */
	    /* make this the work dir */
	    char *t;
	    char filedir[MAXSTR];
	    strcpy(filedir, filename);
	    if ( (t = strrchr(filedir, '\\')) != (char *)NULL ) {
		*(++t) = '\0';
#ifndef _MSC_VER
		if (isalpha(filedir[0]) && (filedir[1]==':'))
		    (void) setdisk(toupper(filedir[0])-'A');
		if (!((strlen(filedir)==2) && isalpha(filedir[0]) && 
		    (filedir[1]==':')))
#endif
		    gs_chdir(filedir);
	    }
	}
    }


    return TRUE;
}


void
delete_buttons(void)
{
    struct buttonlist *bp = buttonhead;
    while (bp) {
	buttonhead = bp->next;
	free(bp);
	bp = buttonhead;
    }
}

POINT button_size, button_shift;

void
calc_info_button_areas(int width, int height)
{
    HDC hdc;
    TEXTMETRIC tm;
    LOGFONT lf;
    HFONT old_hfont;
    POINT char_size;		/* size of default text characters */

    /* get default text size */
    hdc = GetDC(hwndimg);
    memset(&lf, 0, sizeof(LOGFONT));
    lf.lfHeight = -MulDiv(8, GetDeviceCaps(hdc, LOGPIXELSY), 72);
    lstrcpy(lf.lfFaceName, TEXT("MS Shell Dlg"));
    lf.lfCharSet = ANSI_CHARSET;
    hFontAnsi = CreateFontIndirect(&lf);
    lf.lfCharSet = GREEK_CHARSET;
    hFontGreek = CreateFontIndirect(&lf);
    lf.lfCharSet = EASTEUROPE_CHARSET;
    hFontEastEurope = CreateFontIndirect(&lf);
    lf.lfCharSet = RUSSIAN_CHARSET;
    hFontCyrillic = CreateFontIndirect(&lf);
    old_hfont = (HFONT)SelectObject(hdc, hFontAnsi);
    GetTextMetrics(hdc,(LPTEXTMETRIC)&tm);
    display.planes = GetDeviceCaps(hdc, PLANES);
    display.bitcount = GetDeviceCaps(hdc, BITSPIXEL);
    SelectObject(hdc, old_hfont);
    ReleaseDC(hwndimg,hdc);
    char_size.x = tm.tmAveCharWidth;
    char_size.y = tm.tmHeight;

    if (nCodePageLanguage == 1253)
       info_font = hFontGreek;
    else if (nCodePageLanguage == 1250)
       info_font = hFontEastEurope;
    else if (nCodePageLanguage == 1251)
       info_font = hFontCyrillic;
    else
       info_font = hFontAnsi;

    button_size.x = 24;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -