public declare sub sleep lib "kernel32" (byval dwmilliseconds as long)
public declare function findwindow lib "user32" alias "findwindowa" (byval lpclassname as string, byval lpwindowname as string) as long
public declare function findwindowex lib "user32" alias "findwindowexa" (byval hwnd1 as long, byval hwnd2 as long, byval lpsz1 as string, byval lpsz2 as string) as long
public declare function setforegroundwindow lib "user32" (byval hwnd as long) as long
public declare function showwindow lib "user32" (byval hwnd as long, byval ncmdshow as long) as long
public declare function sendmessage lib "user32" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long
public declare function postmessage lib "user32" alias "postmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, byval lparam as long) as long
public const wm_close = &h10
public const wm_keydown = &h100
public const wm_keyup = &h101
public const wm_settext = &hc
sub work()
shell "calc.exe" '開啟計算器
hwnd = findwindow("calcframe", "計算器") '查詢控制代碼
showwindow hwnd, 1 '顯示視窗
setforegroundwindow hwnd '切換為前置活動視窗(需和上一條搭配使用)
sleep 1000 '休息1秒鐘
hwnd_txt = findwindowex(hwnd, 0, "calcframe", "")
postmessage hwnd, wm_keyup, 54, 0 '數字6
sleep 1000 '休息1秒鐘
postmessage hwnd, wm_keyup, 189, 0 '-
sleep 1000 '休息1秒鐘
postmessage hwnd, wm_keyup, 49, 0 '數字1
sleep 1000 '休息1秒鐘
postmessage hwnd, wm_keyup, 187, 0 '=
sleep 1000 '休息1秒鐘
sendmessage hwnd, wm_close, 0&, 0& '關閉計算器
end sub
呼叫計算器並返回結果的例子
api呼叫計算器的例子,實現不同程式的資料交換。此方法同樣適用其他office元件的呼叫 可能要稍作修改 基本原理 尋找計算器的edit控制代碼,用sendmessage返回結果,並不算複雜。模組 private declare function findwindow lib user32 alia...
Delphi之小應用 計算器
主要應用了 1.手動建立控制項及釋放 2.繫結控制項事件 如下 unit uformmain inte ce uses windows,messages,sysutils,variants,classes,graphics,controls,forms,dialogs,stdctrls,extctr...
字串應用(計算器)
給定乙個包含正整數 加 減 乘 除 的算數表示式 括號除外 計算其結果。表示式僅包含非負整數,四種運算子和空格。整數除法僅保留整數部分。示例 輸入 3 2 2 輸出 7 答案 思路 1.碰到數字直接入棧 2.碰到空格,直接下一步 3.碰到 碰到 下乙個數字直接入棧 碰到 num入棧 num num ...