diff options
| author | Jason Rumney | 2004-01-28 23:31:03 +0000 |
|---|---|---|
| committer | Jason Rumney | 2004-01-28 23:31:03 +0000 |
| commit | 39a0e1353fdf221ee7297edb643d7576a2090559 (patch) | |
| tree | f5b0164597108c5bdc3c6031761e7f81b854777c /src | |
| parent | 0e664bca59b30bd0e8cd1451eabd15daf3c10fe9 (diff) | |
| download | emacs-39a0e1353fdf221ee7297edb643d7576a2090559.tar.gz emacs-39a0e1353fdf221ee7297edb643d7576a2090559.zip | |
* makefile.w32-in, w32fns.c: Add `default-printer-name' function.
Diffstat (limited to 'src')
| -rw-r--r-- | src/makefile.w32-in | 1 | ||||
| -rw-r--r-- | src/w32fns.c | 72 |
2 files changed, 73 insertions, 0 deletions
diff --git a/src/makefile.w32-in b/src/makefile.w32-in index c8e9addff63..bd5ad98571c 100644 --- a/src/makefile.w32-in +++ b/src/makefile.w32-in | |||
| @@ -140,6 +140,7 @@ LIBS = $(TLIB0) \ | |||
| 140 | $(USER32) \ | 140 | $(USER32) \ |
| 141 | $(MPR) \ | 141 | $(MPR) \ |
| 142 | $(SHELL32) \ | 142 | $(SHELL32) \ |
| 143 | $(WINSPOOL) \ | ||
| 143 | $(libc) | 144 | $(libc) |
| 144 | 145 | ||
| 145 | # | 146 | # |
diff --git a/src/w32fns.c b/src/w32fns.c index 7bffea34a28..1854c3908bd 100644 --- a/src/w32fns.c +++ b/src/w32fns.c | |||
| @@ -51,6 +51,7 @@ Boston, MA 02111-1307, USA. */ | |||
| 51 | #include <commdlg.h> | 51 | #include <commdlg.h> |
| 52 | #include <shellapi.h> | 52 | #include <shellapi.h> |
| 53 | #include <ctype.h> | 53 | #include <ctype.h> |
| 54 | #include <winspool.h> | ||
| 54 | 55 | ||
| 55 | #include <dlgs.h> | 56 | #include <dlgs.h> |
| 56 | #define FILE_NAME_TEXT_FIELD edt1 | 57 | #define FILE_NAME_TEXT_FIELD edt1 |
| @@ -13921,6 +13922,76 @@ If the underlying system call fails, value is nil. */) | |||
| 13921 | return value; | 13922 | return value; |
| 13922 | } | 13923 | } |
| 13923 | 13924 | ||
| 13925 | DEFUN ("default-printer-name", Fdefault_printer_name, Sdefault_printer_name, | ||
| 13926 | 0, 0, 0, doc: /* Return the name of Windows default printer device. */) | ||
| 13927 | () | ||
| 13928 | { | ||
| 13929 | static char pname_buf[256]; | ||
| 13930 | int err; | ||
| 13931 | HANDLE hPrn; | ||
| 13932 | PRINTER_INFO_2 *ppi2 = NULL; | ||
| 13933 | DWORD dwNeeded = 0, dwReturned = 0; | ||
| 13934 | |||
| 13935 | /* Retrieve the default string from Win.ini (the registry). | ||
| 13936 | * String will be in form "printername,drivername,portname". | ||
| 13937 | * This is the most portable way to get the default printer. */ | ||
| 13938 | if (GetProfileString ("windows", "device", ",,", pname_buf, sizeof (pname_buf)) <= 0) | ||
| 13939 | return Qnil; | ||
| 13940 | /* printername precedes first "," character */ | ||
| 13941 | strtok (pname_buf, ","); | ||
| 13942 | /* We want to know more than the printer name */ | ||
| 13943 | if (!OpenPrinter (pname_buf, &hPrn, NULL)) | ||
| 13944 | return Qnil; | ||
| 13945 | GetPrinter (hPrn, 2, NULL, 0, &dwNeeded); | ||
| 13946 | if (dwNeeded == 0) | ||
| 13947 | { | ||
| 13948 | ClosePrinter (hPrn); | ||
| 13949 | return Qnil; | ||
| 13950 | } | ||
| 13951 | /* Allocate memory for the PRINTER_INFO_2 struct */ | ||
| 13952 | ppi2 = (PRINTER_INFO_2 *) xmalloc (dwNeeded); | ||
| 13953 | if (!ppi2) | ||
| 13954 | { | ||
| 13955 | ClosePrinter (hPrn); | ||
| 13956 | return Qnil; | ||
| 13957 | } | ||
| 13958 | /* Call GetPrinter() again with big enouth memory block */ | ||
| 13959 | err = GetPrinter (hPrn, 2, (LPBYTE)ppi2, dwNeeded, &dwReturned); | ||
| 13960 | ClosePrinter (hPrn); | ||
| 13961 | if (!err) | ||
| 13962 | { | ||
| 13963 | xfree(ppi2); | ||
| 13964 | return Qnil; | ||
| 13965 | } | ||
| 13966 | |||
| 13967 | if (ppi2) | ||
| 13968 | { | ||
| 13969 | if (ppi2->Attributes & PRINTER_ATTRIBUTE_SHARED && ppi2->pServerName) | ||
| 13970 | { | ||
| 13971 | /* a remote printer */ | ||
| 13972 | if (*ppi2->pServerName == '\\') | ||
| 13973 | _snprintf(pname_buf, sizeof (pname_buf), "%s\\%s", ppi2->pServerName, | ||
| 13974 | ppi2->pShareName); | ||
| 13975 | else | ||
| 13976 | _snprintf(pname_buf, sizeof (pname_buf), "\\\\%s\\%s", ppi2->pServerName, | ||
| 13977 | ppi2->pShareName); | ||
| 13978 | pname_buf[sizeof (pname_buf) - 1] = '\0'; | ||
| 13979 | } | ||
| 13980 | else | ||
| 13981 | { | ||
| 13982 | /* a local printer */ | ||
| 13983 | strncpy(pname_buf, ppi2->pPortName, sizeof (pname_buf)); | ||
| 13984 | pname_buf[sizeof (pname_buf) - 1] = '\0'; | ||
| 13985 | /* `pPortName' can include several ports, delimited by ','. | ||
| 13986 | * we only use the first one. */ | ||
| 13987 | strtok(pname_buf, ","); | ||
| 13988 | } | ||
| 13989 | xfree(ppi2); | ||
| 13990 | } | ||
| 13991 | |||
| 13992 | return build_string (pname_buf); | ||
| 13993 | } | ||
| 13994 | |||
| 13924 | /*********************************************************************** | 13995 | /*********************************************************************** |
| 13925 | Initialization | 13996 | Initialization |
| 13926 | ***********************************************************************/ | 13997 | ***********************************************************************/ |
| @@ -14373,6 +14444,7 @@ versions of Windows) characters. */); | |||
| 14373 | defsubr (&Sw32_find_bdf_fonts); | 14444 | defsubr (&Sw32_find_bdf_fonts); |
| 14374 | 14445 | ||
| 14375 | defsubr (&Sfile_system_info); | 14446 | defsubr (&Sfile_system_info); |
| 14447 | defsubr (&Sdefault_printer_name); | ||
| 14376 | 14448 | ||
| 14377 | /* Setting callback functions for fontset handler. */ | 14449 | /* Setting callback functions for fontset handler. */ |
| 14378 | get_font_info_func = w32_get_font_info; | 14450 | get_font_info_func = w32_get_font_info; |