用Rust調(diào)用winapi關(guān)閉顯示器
本文介紹如何在Rust語言中調(diào)用winapi,并發(fā)送關(guān)閉顯示器消息。相關(guān)程序代碼示例如下:
程序中:secound表示程序延時多少秒后,再發(fā)送關(guān)閉顯示的消息。
? ? ? ? ? ? ? 需要使用unself{}來執(zhí)行可能不安全的代碼。
? ? ? ? ? ? ? PostMessageA的解釋是:Places (posts) a message in the message queue associated with the thread that created the specified window and returns without waiting for the thread to process the message.
該段代碼 使用 cargo build --release 編譯后,生成的二進制可執(zhí)行文件大小為140K,相比用C++寫同樣功能的程序體積還是大的。后者僅為11K。
標簽: