UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> GetWinCalcVal2    

Through a google search, any number of calculators built for use in Access may be found. However, the majority of these do not include keypad functionality and/or scientific calculation as the standard windows calculator does. The following module and function GetWinCalcVal2() returns the value of the current number in the windows calculator, or Null if the calculator is not open. The windows calculator can be started by shelling "calc.exe". Note that this does not work with the Windows 7 calculator.


' GetWinCalcVal2
' http://www.utteraccess.com/wiki/index.php/GetwinCalcVal2
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
' You are free to use this code in any application,
' provided this notice is left unchanged.
' rev  date                          brief descripton
' 1.0  2010-11-09  

Option Compare Database
Option Explicit

Private Declare Function FindWindow _
 Lib "user32" Alias "FindWindowA" _
   (ByVal lpClassName As String, _
    ByVal lpWindowName As String _
    ) As Long

Private 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

Private Declare Function SendMessage _
 Lib "user32" Alias "SendMessageA" _
   (ByVal hWnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Integer, _
    ByVal lParam As Any _
   ) As Long

Public Function GetWinCalcVal2() As Variant
 Dim s As String
 Dim hWnd As Long
 Dim Res As Long
 Dim Ret As Variant
 hWnd = FindWindow("SciCalc", "Calculator")
 If hWnd = 0 Then
   MsgBox "Calc is not open!"
   Ret = Null
   hWnd = FindWindowEx(hWnd, 0, "Edit", vbNullString)
   s = Space(260)
   Res = SendMessage(hWnd, &HD, 260, s)
   Ret = CDbl(s)
 End If
 GetWinCalcVal2 = Ret
End Function

Creative Commons License
GetWinCalcVal2 by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search

Thank you for your support!
This page has been accessed 8,793 times.  This page was last modified 11:44, 21 January 2012 by Jack Leach.   Disclaimers