1、如何vb直接调用windows自带的计算器?最好能写出代码。

解决方案 »

  1.   

    On Error GoTo problem
        Dim RetVal
        RetVal = Shell(StartPath & "\CALC.EXE", 1)
        Exit Sub
    problem:
        MsgBox "请确认系统中带有计算器吗?", vbOKOnly + vbInformation, "信息提示"
      

  2.   

    你可以参考下面的代码,是VC版讨论的,改成VB相应代码就行了,不会很困难的。
    ===如何把计算器嵌入到工具栏或对话框中=== 
    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);
    }
      

  3.   

    Win98 和Win2k 里的计算器的存放位置不一样的。win98在windows目录里,Win2k则在WINNT\System32里。所以还要判断这里的
      

  4.   

    就是因为系统不一样所以才进行判断的,还有winxp的情况。有的电脑还用我win95那,那怎么判断啊?
      

  5.   

    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分别取到相关系统路径,再调用其计算器。
      

  6.   

    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
      

  7.   

    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
      

  8.   

    shell语句
    shell "据算起的绝对路径",0(1或2)
    数字代表运行状态
      

  9.   

    安装程序时直接安装一个calc.exe到你的程序安装目录下,直接调用
    shell("calc.exe",1)
    可以不用管什么路径。
      

  10.   

    haal(haa)方法简单,而且是正确的