Private Declare Function GetCurrentDirectoryA Lib "kernel32" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long Private Declare Function GetWindowsDirectoryA Lib "kernel32" (ByVal lpBuffer As String, ByVal nSize As Long) As Long Private Declare Function GetSystemDirectoryA Lib "kernel32" (ByVal lpBuffer As String, ByVal nSize As Long) As Long分别取到相关系统路径,再调用其计算器。
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long Const SW_SHOWNORMAL = 1Private Sub Form_Load() Dim sSave As String, Ret As Long sSave = Space(255) 'Get the system directory Ret = GetSystemDirectory(sSave, 255) sSave = Left$(sSave, Ret) Dim strCmd As String strCmd = sSave & "\CALC.EXE" ShellExecute Me.hwnd, vbNullString, strCmd, vbNullString, "C:\", SW_SHOWNORMAL End Sub
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long Const SW_SHOWNORMAL = 1Private Sub Form_Load() Dim sSave As String, Ret As Long sSave = Space(255) 'Get the system directory Ret = GetSystemDirectory(sSave, 255) sSave = Left$(sSave, Ret) Dim strCmd As String strCmd = sSave & "\CALC.EXE" ShellExecute Me.hwnd, vbNullString, strCmd, vbNullString, "", SW_SHOWNORMAL End Sub
Dim RetVal
RetVal = Shell(StartPath & "\CALC.EXE", 1)
Exit Sub
problem:
MsgBox "请确认系统中带有计算器吗?", vbOKOnly + vbInformation, "信息提示"
===如何把计算器嵌入到工具栏或对话框中===
ShellExecute(this->GetSafeHwnd(),"","calc",NULL,NULL,SW_SHOW);
HWND hWnd=::FindWindow(NULL,_T("计算器"));
if(hWnd)
{
::SetWindowLong(hWnd,GWL_EXSTYLE,WS_EX_TOPMOST);
::SetParent(hWnd,this->m_hWnd);
CRect rect;
GetDlgItem(IDC_STATIC)->GetWindowRect(&rect);
ScreenToClient(&rect);
CWnd* pWnd = new CWnd();
pWnd->Attach(hWnd);
pWnd->MoveWindow(&rect);
this->m_pWndCalc=pWnd;
CFrameWnd* pFrame=(CFrameWnd*) pWnd;
SetMenu(pWnd->GetMenu());
::SetWindowLong(hWnd,GWL_STYLE,WS_VISIBLE|WS_CHILD);
}
Private Declare Function GetWindowsDirectoryA Lib "kernel32" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function GetSystemDirectoryA Lib "kernel32" (ByVal lpBuffer As String, ByVal nSize As Long) As Long分别取到相关系统路径,再调用其计算器。
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1Private Sub Form_Load()
Dim sSave As String, Ret As Long
sSave = Space(255)
'Get the system directory
Ret = GetSystemDirectory(sSave, 255)
sSave = Left$(sSave, Ret)
Dim strCmd As String
strCmd = sSave & "\CALC.EXE"
ShellExecute Me.hwnd, vbNullString, strCmd, vbNullString, "C:\", SW_SHOWNORMAL
End Sub
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1Private Sub Form_Load()
Dim sSave As String, Ret As Long
sSave = Space(255)
'Get the system directory
Ret = GetSystemDirectory(sSave, 255)
sSave = Left$(sSave, Ret)
Dim strCmd As String
strCmd = sSave & "\CALC.EXE"
ShellExecute Me.hwnd, vbNullString, strCmd, vbNullString, "", SW_SHOWNORMAL
End Sub
shell "据算起的绝对路径",0(1或2)
数字代表运行状态
shell("calc.exe",1)
可以不用管什么路径。