大虾们,帮我一下,把C++重写成C#

wawawo 2007-04-18 06:52:40
源址: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;

}

...全文
247 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yutaooo 2007-04-19
  • 打赏
  • 举报
回复
这个改成C#不太合适吧。顶 jiangsheng(蒋晟.Net[MVP]) 的方案。采用dll.
wawawo 2007-04-19
  • 打赏
  • 举报
回复
怎么没人帮忙啊?
jixingzhong 2007-04-19
  • 打赏
  • 举报
回复
工作量不是很大......
yixiao386 2007-04-19
  • 打赏
  • 举报
回复
这个还是要靠你自己的哦!
蒋晟 2007-04-19
  • 打赏
  • 举报
回复
自己写成DLL
CathySun118 2007-04-18
  • 打赏
  • 举报
回复
帮顶
celftj 2007-04-18
  • 打赏
  • 举报
回复
不懂C#者路过。。
内容概要:本文是一份系统性的Go语言并发编程实战教程,通过构建一个可运行的并发URL健康检查器项目,全面讲解了Go中goroutine、channel、select、WaitGroup、Mutex、context、超时控制、worker pool、限流、错误收集和优雅退出等核心并发机制。文章从基础概念入手,结合代码示例与实战项目,深入剖析常见并发模式如Worker Pool、Pipeline、Fan-out/Fan-in,并指出典型陷阱及修复方法,最后提供增强功能与测试建议,助开发者掌握生产级并发编程的最佳实践。; 适合人群:已掌握Go基础语法,具备一定开发经验(工作1-3年)的后端或云原生开发人员;希望深入理解Go并发模型并提升高并发系统设计能力的工程师。; 使用场景及目标:① 学习如何正确使用goroutine与channel进行任务调度和数据通信;② 掌握context在取消、超时和请求链路追踪中的应用;③ 构建可控并发度的worker pool避免资源耗尽;④ 实现错误汇总、限流、优雅退出等生产级特性;⑤ 避免goroutine泄漏、死锁、数据竞争等常见问题。; 阅读建议:建议边阅读边动手实现文中的URL健康检查器项目,结合-race检测工具验证并发安全性,并尝试完文末练习任务以深化理解;重点关注context传播、channel所有权、单一状态持有者等设计原则,在实践中体会“不要通过共享内存来通信”的Go哲学。

65,213

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧