Is there an easy way to change the default printer from mfc or Win32
I was wondering someone could tell me how to change the default printer on my Windows XP system. I have a MFC program that I created and a custom printer dialog derived from CPrintDialog that I added an Apply button to. I would like to be able to change the default printer to the one that I have selected when I click on the apply button. I saw several examples on the Microsoft website using the GetPrinterDeviceDefaults fuction and the hDevMode variable, but I was unable to get them to work. Any help would be appreciated. This is what I have though it does not work because the dmDeviceName is expecting a WCHAR instead of a CString. It may not work anyway, but at least it almost compiles. If someone could give me a couple of pointers on how to fix this, that would be great.
/////////Convert CString to WCHAR///////////////////////////////////////////
LPWSTR lpszW_PrinterName = new WCHAR;
LPTSTR lpStr_PrinterName = printerName.GetBuffer(printerName.GetLength());
int nLen = MultiByteToWideChar(CP_ACP, 0, lpStr_PrinterName,-1,NULL,NULL);
// protect memory handle with ::GlobalLock and ::GlobalUnlock
DEVMODE FAR *pDevMode=(DEVMODE FAR *)::GlobalLock(pd.hDevMode);
// set orientation to landscape
pDevMode->dmDeviceName = lpszW_PrinterName;
|All times are GMT. The time now is 02:45 PM.|
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.