📄 gvwprn.c
字号:
p = q;
}
if (desc != (LPSTR)NULL)
SendDlgItemMessageA(hDlg, UPP_LIST, LB_SELECTSTRING,
0, (LPARAM)desc);
SetDlgItemTextA(hDlg, UPP_NAME, uppname);
EnableWindow(GetDlgItem(hDlg, UPP_LIST), TRUE);
return TRUE; /* we processed the message */
case ID_HELP:
get_help();
return FALSE;
case UPP_LIST:
if (notify_message == LBN_SELCHANGE) {
char dname[MAXSTR];
if (ubuf == NULL)
return FALSE;
i = (int)SendDlgItemMessage(hDlg, UPP_LIST,
LB_GETCURSEL, 0, 0L);
if (i == LB_ERR)
return FALSE;
if (SendDlgItemMessage(hDlg, UPP_LIST, LB_GETTEXTLEN,
i, (LPARAM)0) + 1 > (int)sizeof(dname))
return FALSE;
SendDlgItemMessageA(hDlg, UPP_LIST, LB_GETTEXT,
i, (LPARAM)(LPSTR)dname);
SetDlgItemTextA(hDlg, UPP_NAME,
uppmodel_to_name(ubuf, dname));
}
else if (notify_message == LBN_DBLCLK) {
PostMessage(hDlg, WM_COMMAND, IDOK, (LPARAM)0);
}
return FALSE;
case IDOK:
/* select uniprint device in parent dialog */
{char buf[MAXSTR];
GetDlgItemTextA(GetParent(hDlg), DEVICE_NAME,
buf, sizeof(buf));
if (strcmp(buf, "uniprint") != 0) {
/* select uniprint device */
if (SendDlgItemMessageA(GetParent(hDlg), DEVICE_NAME,
CB_SELECTSTRING, 0,
(LPARAM)(LPSTR)"uniprint")
== CB_ERR) {
play_sound(SOUND_ERROR);
return FALSE; /* can't select uniprint */
}
SendDlgNotification(GetParent(hDlg), DEVICE_NAME,
CBN_SELCHANGE);
}
SetDlgItemTextA(GetParent(hDlg), DEVICE_RES, "");
}
/* select uniprint option in parent dialog */
if (GetDlgItemTextA(hDlg, UPP_NAME, uppname+2,
sizeof(uppname)-3) != 0) {
uppname[0] = '"';
uppname[1] = '@';
strcat(uppname, "\042");
SetDlgItemTextA(GetParent(hDlg),
DEVICE_OPTIONS, uppname);
}
if (ubuf)
free(ubuf);
EndDialog(hDlg, TRUE);
return TRUE;
case IDCANCEL:
if (ubuf)
free(ubuf);
EndDialog(hDlg, FALSE);
return TRUE;
}
break;
}
return FALSE;
}
/* dialog box for selecting PostScript prolog/epilog and Ctrl+D */
#ifdef __BORLANDC__
#pragma argsused
#endif
BOOL CALLBACK _export
AdvPSDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam)
{
switch (wmsg) {
case WM_INITDIALOG:
{
/* for PostScript printers, provide options for sending
* Ctrl+D before and after job, and sending a prolog
* and epilog file.
* These are set using the Advanced button on the Printer
* Setup dialog, only enabled for PostScript printer.
*/
PROFILE *prf;
char buf[MAXSTR];
char section[MAXSTR];
int prectrld=0;
int postctrld=0;
#ifndef cmb4
#define cmb4 0x0473
#endif
GetDlgItemTextA(GetParent(hDlg), cmb4, section, sizeof(section));
if ( (prf = profile_open(szIniFile)) != (PROFILE *)NULL ) {
profile_read_string(prf, section, "PreCtrlD", "0", buf,
sizeof(buf)-2);
if (sscanf(buf, "%d", &prectrld) != 1)
prectrld = 0;
SendDlgItemMessage(hDlg, ADVPS_PRECTRLD, BM_SETCHECK,
prectrld ? 1 : 0, 0);
profile_read_string(prf, section, "PostCtrlD", "0", buf,
sizeof(buf)-2);
if (sscanf(buf, "%d", &postctrld) != 1)
postctrld = 0;
SendDlgItemMessage(hDlg, ADVPS_POSTCTRLD, BM_SETCHECK,
postctrld ? 1 : 0, 0);
profile_read_string(prf, section, "Prolog", "", buf,
sizeof(buf)-2);
SetDlgItemTextA(hDlg, ADVPS_PROLOG, buf);
profile_read_string(prf, section, "Epilog", "", buf,
sizeof(buf)-2);
SetDlgItemTextA(hDlg, ADVPS_EPILOG, buf);
profile_close(prf);
}
}
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case ADVPS_PROLOGBROWSE:
{ char buf[MAXSTR];
GetDlgItemTextA(hDlg, ADVPS_PROLOG, buf, sizeof(buf)-1);
if (get_filename(buf, FALSE, FILTER_ALL,
0, IDS_TOPICPRINT)) {
SetDlgItemTextA(hDlg, ADVPS_PROLOG, buf);
}
}
return FALSE;
case ADVPS_EPILOGBROWSE:
{ char buf[MAXSTR];
GetDlgItemTextA(hDlg, ADVPS_EPILOG, buf, sizeof(buf)-1);
if (get_filename(buf, FALSE, FILTER_ALL,
0, IDS_TOPICPRINT)) {
SetDlgItemTextA(hDlg, ADVPS_EPILOG, buf);
}
}
return FALSE;
case ID_HELP:
get_help();
return FALSE;
case IDOK:
{
char buf[MAXSTR];
char section[MAXSTR];
int prectrld;
int postctrld;
PROFILE *prf;
/* save settings */
if ( (prf = profile_open(szIniFile)) != (PROFILE *)NULL ) {
GetDlgItemTextA(GetParent(hDlg), cmb4,
section, sizeof(section));
prectrld = (int)SendDlgItemMessage(hDlg, ADVPS_PRECTRLD,
BM_GETCHECK, 0, 0);
profile_write_string(prf, section, "PreCtrlD",
prectrld ? "1" : "0");
postctrld = (int)SendDlgItemMessage(hDlg, ADVPS_POSTCTRLD,
BM_GETCHECK, 0, 0);
profile_write_string(prf, section, "PostCtrlD",
postctrld ? "1" : "0");
GetDlgItemTextA(hDlg, ADVPS_PROLOG, buf, sizeof(buf)-1);
profile_write_string(prf, section, "Prolog", buf);
GetDlgItemTextA(hDlg, ADVPS_EPILOG, buf, sizeof(buf)-1);
profile_write_string(prf, section, "Epilog", buf);
profile_close(prf);
}
EndDialog(hDlg, TRUE);
}
return TRUE;
case IDCANCEL:
EndDialog(hDlg, FALSE);
return TRUE;
}
break;
}
return FALSE;
}
char *device_queue_list;
int device_queue_index;
BOOL
get_device(void)
{
int result;
#define DEVICE_BUF_SIZE 4096
device_queue_list = get_queues();
if (device_queue_list == (char *)NULL)
return FALSE;
nHelpTopic = IDS_TOPICPRINT;
result = DialogBoxParamL(hlanguage, MAKEINTRESOURCE(IDD_PRINTGS), hwndimg,
NewDeviceDlgProc, (LPARAM)NULL);
free(device_queue_list);
device_queue_list = NULL;
if (result != IDOK)
return FALSE;
return TRUE;
}
#ifdef __BORLANDC__
#pragma argsused
#endif
/* Modeless dialog box - Cancel printing */
BOOL CALLBACK _export
CancelDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message) {
case WM_INITDIALOG:
SetWindowText(hDlg, szAppName);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDCANCEL:
DestroyWindow(hDlg);
hDlgModeless = 0;
EndDialog(hDlg, 0);
return TRUE;
}
}
return FALSE;
}
/* Dialog box to select printer port */
/* For Win32s this selects a port */
/* For Win95 or WinNT, this selects a queue */
BOOL CALLBACK _export
SpoolDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
LPSTR entry;
switch(message) {
case WM_INITDIALOG:
entry = (LPSTR)lParam;
while (*entry) {
SendDlgItemMessageA(hDlg, SPOOL_PORT, LB_ADDSTRING, 0, (LPARAM)entry);
entry += strlen(entry)+1;
}
if ( (is_win32s ? (*option.printer_port=='\0') : (*option.printer_queue=='\0') ) ||
(SendDlgItemMessageA(hDlg, SPOOL_PORT, LB_SELECTSTRING, 0, (LPARAM)(LPSTR)(is_win32s ? option.printer_port : option.printer_queue))
== LB_ERR) )
SendDlgItemMessage(hDlg, SPOOL_PORT, LB_SETCURSEL, 0, (LPARAM)0);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case SPOOL_PORT:
if (HIWORD(wParam) == LBN_DBLCLK)
PostMessage(hDlg, WM_COMMAND, IDOK, 0L);
return FALSE;
case IDOK:
SendDlgItemMessageA(hDlg, SPOOL_PORT, LB_GETTEXT,
(int)SendDlgItemMessage(hDlg, SPOOL_PORT, LB_GETCURSEL, 0, 0L),
(LPARAM)(LPSTR)(is_win32s ? option.printer_port : option.printer_queue));
EndDialog(hDlg, 1+(int)SendDlgItemMessage(hDlg, SPOOL_PORT, LB_GETCURSEL, 0, 0L));
return TRUE;
case IDCANCEL:
EndDialog(hDlg, 0);
return TRUE;
}
}
return FALSE;
}
char *
get_queues(void)
{
int i;
DWORD count, needed;
PRINTER_INFO_1 *prinfo;
char *enumbuffer;
char *buffer;
char *p;
char *s;
if (is_win32s) {
if ((buffer = (char *)malloc(PORT_BUF_SIZE)) == (char *)NULL)
return NULL;
GetProfileStringA("Devices", NULL, "", buffer, PORT_BUF_SIZE);
return buffer;
}
/* EnumPrintersW is not supported MSLU, so use ANSI version.
* Because PRINTER_INFO_1 is still Unicode, we need to cast
* the string pointers back to ANSI.
*/
/* enumerate all available printers */
EnumPrintersA(PRINTER_ENUM_CONNECTIONS | PRINTER_ENUM_LOCAL,
NULL, 1, NULL, 0, &needed, &count);
if (needed == 0) {
/* no printers */
enumbuffer = (char *)malloc(4);
if (enumbuffer == (char *)NULL)
return NULL;
memset(enumbuffer, 0, 4);
return enumbuffer;
}
enumbuffer = (char *)malloc(needed);
if (enumbuffer == (char *)NULL)
return NULL;
if (!EnumPrintersA(PRINTER_ENUM_CONNECTIONS | PRINTER_ENUM_LOCAL,
NULL, 1, (LPBYTE)enumbuffer, needed, &needed, &count)) {
char buf[256];
free(enumbuffer);
sprintf(buf, "EnumPrintersA() failed, error code = %d", GetLastError());
gserror(0, buf, MB_ICONHAND, SOUND_ERROR);
return NULL;
}
prinfo = (PRINTER_INFO_1 *)enumbuffer;
if ((buffer = (char *)malloc(PORT_BUF_SIZE)) == (char *)NULL) {
free(enumbuffer);
return NULL;
}
/* copy printer names to single buffer */
p = buffer;
for (i=0; i<(int)count; i++) {
/* We used ANSI version of EnumPrinters, so cast string back to ANSI */
s = (char *)prinfo[i].pName;
if ((int)(strlen(s) + 1) < (PORT_BUF_SIZE- (p-buffer))) {
strncpy(p, s, (PORT_BUF_SIZE- (p-buffer)));
p += strlen(p) + 1;
}
}
*p = '\0'; /* double null at end */
free(enumbuffer);
return buffer;
}
/* return TRUE if queuename available */
/* return FALSE if cancelled or error */
/* if queue non-NULL, use as suggested queue */
BOOL
get_queuename(char *portname, char *queue)
{
char *buffer;
char *p;
int i, iport;
buffer = get_queues();
if (buffer == (char *)NULL)
return FALSE;
if ( (queue == (char *)NULL) || (strlen(queue)==0) ) {
/* select a queue */
iport = DialogBoxParamL(hlanguage, MAKEINTRESOURCE(IDD_QUEUE), hwndimg,
SpoolDlgProc, (LPARAM)buffer);
if (!iport) {
free(buffer);
return FALSE;
}
p = buffer;
for (i=1; i<iport && strlen(p)!=0; i++)
p += strlen(p)+1;
/* prepend \\spool\ which is used by Ghostscript to distinguish */
/* real files from queues */
strcpy(portname, "\\\\spool\\");
strcat(portname, p);
}
else {
strcpy(portname, "\\\\spool\\");
strcat(portname, queue);
}
free(buffer);
return TRUE;
}
/* return TRUE if portname available */
/* return FALSE if cancelled or error */
/* if port non-NULL, use as suggested port */
BOOL
get_portname(char *portname, char *port)
{
char *buffer;
char *p;
int i, iport;
char filename[MAXSTR];
char device[MAXSTR];
if (is_win95 || is_winnt)
return get_queuename(portname, port);
if (port && strlen(port)) {
/* check if it is a queue name */
GetProfileStringA("Devices", port, "", device, sizeof(device));
if (strlen(device)) {
/* map it to a port name */
strtok(device, ",");
port = strtok(NULL, ",");
}
}
buffer = get_ports();
if ( (port == (char *)NULL) || (strlen(port)==0) ) {
if (buffer == (char *)NULL)
return FALSE;
/* select a port */
iport = DialogBoxParamL(hlanguage, MAKEINTRESOURCE(IDD_SPOOL),
hwndimg, SpoolDlgProc, (LPARAM)buffer);
if (!iport) {
free(buffer);
return FALSE;
}
p = buffer;
for (i=1; i<iport && strlen(p)!=0; i++)
p += strlen(p)+1;
strcpy(portname, p);
}
else
strcpy(portname, port);
if (strlen(portname) == 0)
return FALSE;
if (strcmp(portname,"FILE:") == 0) {
strcpy(filename, "*.prn");
if (!get_filename(filename, TRUE, FILTER_ALL, IDS_PRINTFILE, IDS_TOPICPRINT)) {
free(buffer);
return FALSE;
}
strcpy(portname, filename);
}
free(buffer);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -