读书人

们帮小弟我一下把C++重写成C

发布时间: 2012-03-30 17:32:10 作者: rapoo

大虾们,帮我一下,把C++重写成C#
源址:http://blogs.msdn.com/fyuan/archive/2007/02/24/printing-documents-to-microsoft-xps-document-writer-without-user-interaction.aspx

谁帮我用C#重写一下,谢谢了。
(Printing documents to Microsoft XPS Document Writer without user interaction)

#include <windows.h>

#include <strsafe.h>



const wchar_t * Dialog_Class = L "#32770 ";





HRESULT PrintHTML(const wchar_t * pUri, const wchar_t * pFileName)

{

HRESULT hr;



STARTUPINFO si = { sizeof(si) };

PROCESS_INFORMATION pi;



wchar_t command[MAX_PATH];



hr = StringCchPrintf(command, _countof(command),

L "rundll32.exe mshtml.dll,PrintHTML \ "%s\ " ", pUri);



if (FAILED(hr))

{

return hr;

}



if (CreateProcess(0, command, 0, 0, FALSE, 0, 0, 0, &si, &pi))

{

printf( "\r\nStarting '%S '\r\n ", command);



CloseHandle(pi.hProcess);

CloseHandle(pi.hThread);

}



DWORD size = _countof(command);

GetDefaultPrinter(command, & size);

printf( " Default printer: '%S '\r\n ", command);



printf( "\r\nWaiting for Print dialog box\r\n ");

Sleep(5 * 1000);



// Find Print Dialog box

HWND hWnd = FindWindow(Dialog_Class, L "Print ");



// Print button

HWND hChild = FindWindowEx(hWnd, NULL, NULL, L "&Print ");



GetWindowText(hChild, command, _countof(command));



printf( " hwnd = %p %p( '%S ')\r\n ", hWnd, hChild, command);



// Press Print button

SendMessage (hChild, WM_IME_KEYDOWN, 'P ', 0);



printf( "\r\nWaiting for File Save dialog box\r\n ");

Sleep(5 * 1000);



// Find Save File Dialog Box



hWnd = FindWindow(Dialog_Class, L "Save the file as ");



hChild = FindWindowEx(hWnd, NULL, L "ComboBoxEx32 ", NULL);

hChild = FindWindowEx(hChild, NULL, L "ComboBox ", NULL);

hChild = FindWindowEx(hChild, NULL, L "Edit ", NULL); // File name edit control



printf( " hwnd = %p %p\r\n ", hWnd, hChild);



// Enter file name

SendMessage(hChild, WM_SETTEXT, NULL, (LPARAM) pFileName);



Sleep(1000);



// Find Save button

hChild = FindWindowEx(hWnd, NULL, NULL, L "&Save ");



GetWindowText(hChild, command, _countof(command));



printf( " hwnd = %p %p( '%S ')\r\n ", hWnd, hChild, command);



// Press Save button

SendMessage (hChild, WM_IME_KEYDOWN, 'S ', 0);



printf( "\r\nSaving to '%S '\r\n ", pFileName);



return hr;

}



[解决办法]
不懂C#者路过。。
[解决办法]
帮顶
[解决办法]
自己写成DLL
[解决办法]
这个还是要靠你自己的哦!
[解决办法]
工作量不是很大......
[解决办法]
这个改成C#不太合适吧。顶 jiangsheng(蒋晟.Net[MVP]) 的方案。采用dll.

读书人网 >C++

热点推荐