Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Система";
Текущий архив: 2002.11.04;
Скачать: [xml.tar.bz2];

Вниз

Принтер по умолчанию   Найти похожие ветки 

 
compsr   (2002-09-03 09:58) [0]

Уважаемые мастера подскажите пожалуйста, как программно выбрать и поменять принтер "по умолчанию"


 
Ученик   (2002-09-03 10:00) [1]

>compsr (03.09.02 09:58)
Для всей системы или для своего приложения ?


 
compsr   (2002-09-03 10:17) [2]

Для всей системы


 
Anatoly Podgoretsky   (2002-09-03 10:29) [3]

Мой компьютер/Принтера правая кнопка
Это чисто пользовательская привелегия


 
compsr   (2002-09-03 10:35) [4]

А если для своего приложения ?


 
Anatoly Podgoretsky   (2002-09-03 10:43) [5]

Для своего никак, это глобальная вещь.
Но зачем тебе это?
Такие вещи делаются так, делается диалог выбора принтера и пусть пользователь решит на какой ему выводить.


 
compsr   (2002-09-03 10:53) [6]

Это нужно для следующего:
1. Есть локальная сеть с несколькими принтерами;
2. Есть несколько женщин, которым уже надоело объяснять, как переключить принтер и настроить порт;
3. Есть Dos программа с которой надо под Win выводить на печать отчеты на разные принтера;

Хочется сделать простенькую программу , в которой можно было выбрать на какой принтер в данный момент пойдет печать, а также переназначить порт LPT1 на этот принтер.


 
Ученик   (2002-09-03 11:07) [7]

HOWTO: Get and Set the Default Printer in Windows
ID: Q135387



--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Windows Software Development Kit (SDK) 3.1
Microsoft Win32 Application Programming Interface (API), used with:
Microsoft Windows NT, versions 3.5, 3.51, 4.0
Microsoft Windows 95

--------------------------------------------------------------------------------


SUMMARY
In all versions of Windows, the appropriate way to get the default printer is to use GetProfileString, and the appropriate way to set the default printer is to use WriteProfileString. This works whether the default printer information is stored in the WIN.ini file or in the registry.



MORE INFORMATION

Notes to Keep in Mind
The Device value you get or set actually contains three elements separated by commas as follows:

<printer name>,<driver name>,<port>

For example:

My Printer,HPPCL5MS,lpt1:



When setting the default printer, you must specify valid names for these elements. That is, you must specify a valid printer, driver, and port. If not, programs such as Print Manager may set the printer back to the previous valid printer, and other programs may become very confused. You can use the EnumPrinters API to retrieve the printer name, driver name, and port name of all available printers.


Windows 95 and Windows NT map most .INI file references to the registry. Because of this mapping, GetProfileString and WriteProfileString still function as they do under 16-bit Windows (Microsoft Windows and Windows for Workgroups).


After setting the default printer, notify all other applications of the change by broadcasting the WM_WININICHANGE message.


Sample Code

// This code uses a sample profile string of "My Printer,HPPCL5MS,lpt1:"
// To get the default printer for Windows 3.1, Windows 3.11,
// Windows 95, and Windows NT use:
GetProfileString("windows", "device", ",,,", buffer, sizeof(buffer));

-----

// To set the default printer for Windows 3.1 and Windows 3.11 use:
WriteProfileString("windows", "device", "My Printer,HPPCL5MS,lpt1:");
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, 0L);

-----

// To set the default printer for Windows 95 use:
WriteProfileString("windows", "device", "My Printer,HPPCL5MS,lpt1:");
SendMessageTimeout(HWND_BROADCAST, WM_WININICHANGE, 0L,
(LPARAM)(LPCTSTR)"windows", SMTO_NORMAL, 1000, NULL);

-----

// To set the default printer for Windows NT use:
/* Note printer driver is usually WINSPOOL under Windows NT */
WriteProfileString("windows", "device", "My Printer,WINSPOOL,lpt1:");

SendMessageTimeout(HWND_BROADCAST, WM_WININICHANGE, 0L, 0L,
SMTO_NORMAL, 1000, NULL);
There are two circumstances where the code won"t work:
If the customer leaves out the SendMessage, no other application will recognize the change in the .ini settings.


If a different 32-bit application does not handle the win.ini change message, then it will appear to that application as if the default printer has not been changed. The user will need to exit and re-enter Windows 95 to have the other application recognize the printer change.




This is the preferred method of changing the printer if the code is to be platform independent; this method will work on Windows 3.1, Windows 95 and Windows NT.

For additional information, please see the following article in the Microsoft Knowledge Base:
Q140560 How to Set the Default Printer Programmatically in Windows 95

Additional query words: 3.11


Keywords : kbcode kbprint kbNTOS350 kbNTOS351 kbNTOS400 kbSDKWin32 kbDSupport
Version : WINDOWS:3.1,95; winnt:3.5,3.51,4.0
Platform : WINDOWS winnt
Issue type : kbhowto



 
Anatoly Podgoretsky   (2002-09-03 11:20) [8]

Ученик © (03.09.02 11:07)
Это для всей системы, пользователи матюгаются, кроме того

If a different 32-bit application does not handle the win.ini change message, then it will appear to that application as if the default printer has not been changed. The user will need to exit and re-enter Windows 95 to have the other application recognize the printer change.

Здесь же дело обстоит просто, не програмное, а чисто административное действие по обучению пользователей.



Страницы: 1 вся ветка

Форум: "Система";
Текущий архив: 2002.11.04;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.47 MB
Время: 0.009 c
1-11164
basic
2002-10-24 10:27
2002.11.04
Должен ли Click отрабатываться в tRadioGroup


1-11157
BofA
2002-10-24 13:03
2002.11.04
Проблемы с кодировкой в TEdit


4-11544
d-coder
2002-09-22 14:15
2002.11.04
Перемещение текста синхронно с прокручиванием скрола


1-11151
lensky
2002-10-24 10:46
2002.11.04
kak sdelat check box s kartinkoi?... ili dashe proshe....


1-11206
Di_wind
2002-10-24 22:34
2002.11.04
Class Eplorer





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский