Sign in to follow this  
Followers 0
sak

Mini Calculator

15 posts in this topic

#1 ·  Posted (edited)

Calculator. My idia. It's work.

#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

Global $Input, $Btn1, $Btn2, $Btn3, $Btn4, $Btn5, $Btn6, $Btn7
Global $Btn8, $Btn9, $Btn0, $Btn_add, $Btn_sub, $Btn_mul
Global $Btn_div, $Btn_clear, $Btn_dot, $Btn_ans_com, $Btn_ans_add
Global $Btn_ans_sub, $Btn_ans_mul, $Btn_ans_div, $nMsg, $read

main()
Func main()
GUICreate("Mini Calculator", 305, 103, -1, -1, -1, _
BitOR($WS_EX_OVERLAPPEDWINDOW,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$Input = GUICtrlCreateInput("", 8, 8, 290, 21, _
BitOR($ES_RIGHT,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN), _
BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Btn1 = GUICtrlCreateButton("1", 8, 40, 27, 25, $WS_GROUP)
$Btn2 = GUICtrlCreateButton("2", 40, 40, 27, 25, $WS_GROUP)
$Btn3 = GUICtrlCreateButton("3", 72, 40, 27, 25, $WS_GROUP)
$Btn4 = GUICtrlCreateButton("4", 104, 40, 27, 25, $WS_GROUP)
$Btn5 = GUICtrlCreateButton("5", 136, 40, 27, 25, $WS_GROUP)
$Btn6 = GUICtrlCreateButton("6", 8, 72, 27, 25, $WS_GROUP)
$Btn7 = GUICtrlCreateButton("7", 40, 72, 27, 25, $WS_GROUP)
$Btn8 = GUICtrlCreateButton("8", 72, 72, 27, 25, $WS_GROUP)
$Btn9 = GUICtrlCreateButton("9", 104, 72, 27, 25, $WS_GROUP)
$Btn0 = GUICtrlCreateButton("0", 136, 72, 27, 25, $WS_GROUP)
$Btn_add = GUICtrlCreateButton("+", 176, 40, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Btn_sub = GUICtrlCreateButton("-", 208, 40, 27, 25, $BS_BOTTOM)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Btn_mul = GUICtrlCreateButton("*", 176, 72, 27, 25, BitOR($BS_TOP,$WS_GROUP))
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Btn_div = GUICtrlCreateButton("/", 208, 72, 27, 25)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Btn_clear = GUICtrlCreateButton("c", 240, 40, 58, 25)
GUICtrlSetFont(-1, 11, 400, 0, "MS Sans Serif")
$Btn_dot = GUICtrlCreateButton(".", 240, 72, 27, 25, $BS_BOTTOM )
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Btn_ans_com = GUICtrlCreateButton("=", 272, 72, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Btn_ans_add = GUICtrlCreateButton("=", 272, 72, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_HIDE)
$Btn_ans_sub = GUICtrlCreateButton("=", 272, 72, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_HIDE)
$Btn_ans_mul = GUICtrlCreateButton("=", 272, 72, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_HIDE)
$Btn_ans_div = GUICtrlCreateButton("=", 272, 72, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_HIDE)
GUISetState(@SW_SHOW)

While 1
        $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Btn1
            GUICtrlSetData($Input, GUICtrlRead($Input)&1)
        Case $Btn2
            GUICtrlSetData($Input, GUICtrlRead($Input)&2)
        Case $Btn3
            GUICtrlSetData($Input, GUICtrlRead($Input)&3)
        Case $Btn4
            GUICtrlSetData($Input, GUICtrlRead($Input)&4)
        Case $Btn5
            GUICtrlSetData($Input, GUICtrlRead($Input)&5)
        Case $Btn6
            GUICtrlSetData($Input, GUICtrlRead($Input)&6)
        Case $Btn7
            GUICtrlSetData($Input, GUICtrlRead($Input)&7)
        Case $Btn8
            GUICtrlSetData($Input, GUICtrlRead($Input)&8)
        Case $Btn9
            GUICtrlSetData($Input, GUICtrlRead($Input)&9)
        Case $Btn0
            GUICtrlSetData($Input, GUICtrlRead($Input)&0)
        Case $Btn_dot
            GUICtrlSetData($Input, GUICtrlRead($Input)&'.')
        Case $Btn_add
            If GUICtrlRead($Input) <> '' Then
            GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_add, $GUI_SHOW)
            $read = GUICtrlRead($Input)
            GUICtrlSetData($Input, '')
            EndIf
        Case $Btn_sub
            If GUICtrlRead($Input) <> '' Then
            GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_SHOW)
            $read = GUICtrlRead($Input)
            GUICtrlSetData($Input, '')
            EndIf
        Case $Btn_mul
            If GUICtrlRead($Input) <> '' Then
            GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mul, $GUI_SHOW)
            $read = GUICtrlRead($Input)
            GUICtrlSetData($Input, '')
            EndIf
        Case $Btn_div
            If GUICtrlRead($Input) <> '' Then
            GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_SHOW)
            $read = GUICtrlRead($Input)
            GUICtrlSetData($Input, '')
            EndIf
        Case $Btn_ans_add
            GUICtrlSetData($Input, $read+GUICtrlRead($Input))
        Case $Btn_ans_sub
            GUICtrlSetData($Input, $read-GUICtrlRead($Input))
        Case $Btn_ans_mul
            GUICtrlSetData($Input, $read*GUICtrlRead($Input))
        Case $Btn_ans_div
            GUICtrlSetData($Input, $read/GUICtrlRead($Input))
        Case $Btn_clear
            GUICtrlSetState($Btn_ans_com, $GUI_SHOW)
            GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
            GUICtrlSetData($Input, '')
            ContinueLoop
    EndSwitch
WEnd
EndFunc

Posted Image

Edited by sak

Share this post


Link to post
Share on other sites



I think it's a good effort. The only thing I miss is not being able to type or paste the number into the input.

Share this post


Link to post
Share on other sites

I think it's a good effort. The only thing I miss is not being able to type or paste the number into the input.

Thank you for helping to slant

A single look.

Do not know what will work or not.

Share this post


Link to post
Share on other sites

Not as mini as mine :) I made a ridiculously small calculator years ago which was about 120x20 pixels, and was literally a bar which you typed in one side and got the answer out the other.

You also picked exactly the same name for it as I did... I thought this was my thread for a moment being resurrected like my other thread that was brought back from 2009 today :)

Share this post


Link to post
Share on other sites

sak

Do
Until Not Assign('sString', Eval('sString')) Or Not Assign('sString', InputBox('Calc', $sString & " = " & Execute($sString), $sString)) Or $sString = ''

Share this post


Link to post
Share on other sites

Thank you for guidance.

New updates to follow the instructions.

Keyboard instead of mouse already.

#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", 1)

HotKeySet("{ESC}", "send_close")
HotKeySet("1", "send_1")
HotKeySet("2", "send_2")
HotKeySet("3", "send_3")
HotKeySet("4", "send_4")
HotKeySet("5", "send_5")
HotKeySet("6", "send_6")
HotKeySet("7", "send_7")
HotKeySet("8", "send_8")
HotKeySet("9", "send_9")
HotKeySet("0", "send_0")
HotKeySet(".", "send_dot")
HotKeySet("{+}", "send_add")
HotKeySet("{-}", "send_sub")
HotKeySet("{*}", "send_mul")
HotKeySet("{/}", "send_div")
HotKeySet("{BS}", "send_back")
HotKeySet("{DEL}", "send_clear")
HotKeySet("{Numpad1}", "send_num_1")
HotKeySet("{Numpad2}", "send_num_2")
HotKeySet("{Numpad3}", "send_num_3")
HotKeySet("{Numpad4}", "send_num_4")
HotKeySet("{Numpad5}", "send_num_5")
HotKeySet("{Numpad6}", "send_num_6")
HotKeySet("{Numpad7}", "send_num_7")
HotKeySet("{Numpad8}", "send_num_8")
HotKeySet("{Numpad9}", "send_num_9")
HotKeySet("{Numpad0}", "send_num_0")
HotKeySet("{NumpadDot}", "send_num_dot")
HotKeySet("{NumpadAdd}", "send_num_add")
HotKeySet("{NumpadSub}", "send_num_sub")
HotKeySet("{NumpadMult}", "send_num_mul")
HotKeySet("{NumpadDiv}", "send_num_div")

Global $Input, $Btn1, $Btn2, $Btn3, $Btn4, $Btn5, $Btn6, $Btn7
Global $Btn8, $Btn9, $Btn0, $Btn_add, $Btn_sub, $Btn_mul
Global $Btn_div, $Btn_clear, $Btn_dot, $Btn_ans_com, $Btn_ans_add
Global $Btn_ans_sub, $Btn_ans_mul, $Btn_ans_div, $nMsg, $read
Global $title = "Mini Calculator", $cid = "Edit1", $sread, $thim
Global $sFile = @SystemDir&'\Calc.exe', $hForm, $sFile, $Btn_back
main()
Func main()
$hForm = GUICreate("Mini Calculator     (Esc=Exit)", 305, 103, -1, -1, -1, _
BitOR($WS_EX_OVERLAPPEDWINDOW,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
GUISetBkColor(0xA6CAF0)
GUISetIcon($sFile, -1, $hForm)
$Input = GUICtrlCreateInput("0", 8, 8, 290, 21, _
BitOR($ES_RIGHT,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN), _
BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Btn1 = GUICtrlCreateButton("1", 8, 40, 27, 25, $WS_GROUP)
$Btn2 = GUICtrlCreateButton("2", 40, 40, 27, 25, $WS_GROUP)
$Btn3 = GUICtrlCreateButton("3", 72, 40, 27, 25, $WS_GROUP)
$Btn4 = GUICtrlCreateButton("4", 104, 40, 27, 25, $WS_GROUP)
$Btn5 = GUICtrlCreateButton("5", 136, 40, 27, 25, $WS_GROUP)
$Btn6 = GUICtrlCreateButton("6", 8, 72, 27, 25, $WS_GROUP)
$Btn7 = GUICtrlCreateButton("7", 40, 72, 27, 25, $WS_GROUP)
$Btn8 = GUICtrlCreateButton("8", 72, 72, 27, 25, $WS_GROUP)
$Btn9 = GUICtrlCreateButton("9", 104, 72, 27, 25, $WS_GROUP)
$Btn0 = GUICtrlCreateButton("0", 136, 72, 27, 25, $WS_GROUP)
$Btn_add = GUICtrlCreateButton("+", 176, 40, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Btn_sub = GUICtrlCreateButton("-", 208, 40, 27, 25, $BS_BOTTOM)
GUICtrlSetFont(-1, 15, 400, 0, "MS Sans Serif")
$Btn_mul = GUICtrlCreateButton("*", 176, 72, 27, 25, BitOR($BS_TOP,$WS_GROUP))
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Btn_div = GUICtrlCreateButton("/", 208, 72, 27, 25)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Btn_clear = GUICtrlCreateButton("c", 240, 40, 27, 25)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Btn_back = GUICtrlCreateButton("BS", 270, 40, 27, 25)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Btn_dot = GUICtrlCreateButton(".", 240, 72, 27, 25, $BS_BOTTOM )
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
$Btn_ans_com = GUICtrlCreateButton("=", 272, 72, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Btn_ans_add = GUICtrlCreateButton("=", 272, 72, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_HIDE)
$Btn_ans_sub = GUICtrlCreateButton("=", 272, 72, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_HIDE)
$Btn_ans_mul = GUICtrlCreateButton("=", 272, 72, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_HIDE)
$Btn_ans_div = GUICtrlCreateButton("=", 272, 72, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetState(-1, $GUI_HIDE)
GUISetState(@SW_SHOW)


While 1
        $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Btn1
            GUICtrlSetData($Input, GUICtrlRead($Input)&1)
        Case $Btn2
            GUICtrlSetData($Input, GUICtrlRead($Input)&2)
        Case $Btn3
            GUICtrlSetData($Input, GUICtrlRead($Input)&3)
        Case $Btn4
            GUICtrlSetData($Input, GUICtrlRead($Input)&4)
        Case $Btn5
            GUICtrlSetData($Input, GUICtrlRead($Input)&5)
        Case $Btn6
            GUICtrlSetData($Input, GUICtrlRead($Input)&6)
        Case $Btn7
            GUICtrlSetData($Input, GUICtrlRead($Input)&7)
        Case $Btn8
            GUICtrlSetData($Input, GUICtrlRead($Input)&8)
        Case $Btn9
            GUICtrlSetData($Input, GUICtrlRead($Input)&9)
        Case $Btn0
            GUICtrlSetData($Input, GUICtrlRead($Input)&0)
        Case $Btn_dot
            GUICtrlSetData($Input, GUICtrlRead($Input)&'.')
        Case $Btn_back
            $thim = StringTrimRight(GUICtrlRead($Input), 1)
            GUICtrlSetData($Input, $thim)
        Case $Btn_add
            If GUICtrlRead($Input) <> '' Then
            GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_add, $GUI_SHOW)
            $read = GUICtrlRead($Input)
            GUICtrlSetData($Input, '')
            EndIf
        Case $Btn_sub
            If GUICtrlRead($Input) <> '' Then
            GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_SHOW)
            $read = GUICtrlRead($Input)
            GUICtrlSetData($Input, '')
            EndIf
        Case $Btn_mul
            If GUICtrlRead($Input) <> '' Then
            GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mul, $GUI_SHOW)
            $read = GUICtrlRead($Input)
            GUICtrlSetData($Input, '')
            EndIf
        Case $Btn_div
            If GUICtrlRead($Input) <> '' Then
            GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_SHOW)
            $read = GUICtrlRead($Input)
            GUICtrlSetData($Input, '')
            EndIf
        Case $Btn_ans_add
            GUICtrlSetData($Input, $read+GUICtrlRead($Input))
        Case $Btn_ans_sub
            GUICtrlSetData($Input, $read-GUICtrlRead($Input))
        Case $Btn_ans_mul
            GUICtrlSetData($Input, $read*GUICtrlRead($Input))
        Case $Btn_ans_div
            GUICtrlSetData($Input, $read/GUICtrlRead($Input))
        Case $Btn_clear
            GUICtrlSetState($Btn_ans_com, $GUI_SHOW)
            GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
            GUICtrlSetData($Input, '')
            ContinueLoop
    EndSwitch
WEnd
EndFunc

Func send_1()

    GUICtrlSetData($Input, GUICtrlRead($Input)&1)
EndFunc

Func send_2()
    GUICtrlSetData($Input, GUICtrlRead($Input)&2)
EndFunc

Func send_3()
    GUICtrlSetData($Input, GUICtrlRead($Input)&3)
EndFunc

Func send_4()
    GUICtrlSetData($Input, GUICtrlRead($Input)&4)
EndFunc

Func send_5()
    GUICtrlSetData($Input, GUICtrlRead($Input)&5)
EndFunc

Func send_6()
    GUICtrlSetData($Input, GUICtrlRead($Input)&6)
EndFunc

Func send_7()
    GUICtrlSetData($Input, GUICtrlRead($Input)&7)
EndFunc

Func send_8()
    GUICtrlSetData($Input, GUICtrlRead($Input)&8)
EndFunc

Func send_9()
    GUICtrlSetData($Input, GUICtrlRead($Input)&9)
EndFunc

Func send_0()
    GUICtrlSetData($Input, GUICtrlRead($Input)&0)
EndFunc

Func send_dot()
    GUICtrlSetData($Input, GUICtrlRead($Input)&".")
EndFunc

Func send_back()
    $thim = StringTrimRight(GUICtrlRead($Input), 1)
    GUICtrlSetData($Input, $thim)
EndFunc

Func send_add()
    If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_add, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_add, $GUI_FOCUS)
        $read = GUICtrlRead($Input)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_sub()
    If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_sub, $GUI_FOCUS)
        $read = GUICtrlRead($Input)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_mul()
    If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_mul, $GUI_FOCUS)
        $read = GUICtrlRead($Input)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_div()
    If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_div, $GUI_FOCUS)
        $read = GUICtrlRead($Input)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_clear()
    If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func enter()
    WinWaitActive($title, "", 1)
    Send("{ENTER}")
EndFunc

Func send_num_1()
    GUICtrlSetData($Input, GUICtrlRead($Input)&1)
EndFunc

Func send_num_2()
    GUICtrlSetData($Input, GUICtrlRead($Input)&2)
EndFunc

Func send_num_3()
    GUICtrlSetData($Input, GUICtrlRead($Input)&3)
EndFunc

Func send_num_4()
    GUICtrlSetData($Input, GUICtrlRead($Input)&4)
EndFunc

Func send_num_5()
    GUICtrlSetData($Input, GUICtrlRead($Input)&5)
EndFunc

Func send_num_6()
    GUICtrlSetData($Input, GUICtrlRead($Input)&6)
EndFunc

Func send_num_7()
    GUICtrlSetData($Input, GUICtrlRead($Input)&7)
EndFunc

Func send_num_8()
    GUICtrlSetData($Input, GUICtrlRead($Input)&8)
EndFunc

Func send_num_9()
    GUICtrlSetData($Input, GUICtrlRead($Input)&9)
EndFunc

Func send_num_0()
    GUICtrlSetData($Input, GUICtrlRead($Input)&0)
EndFunc

Func send_num_dot()
    GUICtrlSetData($Input, GUICtrlRead($Input)&".")
EndFunc


Func send_num_add()
    If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_add, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_add, $GUI_FOCUS)
        $read = GUICtrlRead($Input)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_num_sub()
    If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_sub, $GUI_FOCUS)
        $read = GUICtrlRead($Input)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_num_mul()
    If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_mul, $GUI_FOCUS)
        $read = GUICtrlRead($Input)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_num_div()
   If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_div, $GUI_FOCUS)
        $read = GUICtrlRead($Input)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_close()
    Exit
EndFunc

Posted Image

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hi,

I like it. !!!!

Here is another version using the 'execute' command

Enjoy and add more buttons.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 233, 350, 255, 147)
GUISetBkColor(0xA6CAF0)
$Input1 = GUICtrlCreateInput("", 40, 104, 145, 21)
$Input2 = GUICtrlCreateInput("", 40, 144, 145, 21)
$Label1 = GUICtrlCreateLabel("                                              ", 16, 32, 200, 29)
GUICtrlSetFont(-1, 16, 800, 0, "Bell MT")
GUICtrlSetBkColor(-1, 0xFFFFFF)

$Label2 = GUICtrlCreateLabel("C", 0, 38, 15, 29) ;<<C>>
GUICtrlSetFont(-1, 16, 800, 0, "Bell MT")

$Label3 = GUICtrlCreateLabel("A", 20, 104, 15, 21) ;<<A>>
GUICtrlSetFont(-1, 16, 800, 0, "Bell MT")

$Label3 = GUICtrlCreateLabel("B", 20, 144, 15, 21) ;<<b>>
GUICtrlSetFont(-1, 16, 800, 0, "Bell MT")


$Root = GUICtrlCreateButton("Root", 10, 208, 50, 25, $WS_GROUP)
$recip = GUICtrlCreateButton("Recip", 60, 208, 50, 25, $WS_GROUP)
$Mult = GUICtrlCreateButton("Mult", 110, 208, 50, 25, $WS_GROUP)
$Div = GUICtrlCreateButton("Div", 160, 208, 50, 25, $WS_GROUP)
$Add = GUICtrlCreateButton("Add", 10, 180, 50, 25, $WS_GROUP)
$Sub = GUICtrlCreateButton("Sub", 60, 180, 50, 25, $WS_GROUP)
$Per = GUICtrlCreateButton("%", 110, 180, 50, 25, $WS_GROUP)
$Sin = GUICtrlCreateButton("Sin", 160, 180, 50, 25, $WS_GROUP)
$Clr = GUICtrlCreateButton("Clr", 10, 234, 50, 25, $WS_GROUP)
$rad2deg = GUICtrlCreateButton("r2d", 60, 234, 50, 25, $WS_GROUP)
$c2a = GUICtrlCreateButton("c2a", 110, 234, 50, 25, $WS_GROUP)
$c2b = GUICtrlCreateButton("c2b", 160, 234, 50, 25, $WS_GROUP)
$Pi = GUICtrlCreateButton("PI", 10, 260, 50, 25, $WS_GROUP)



GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $a = 0, $b = 0, $c = 0
Func display()
    $Label1 = GUICtrlCreateLabel($c, 16, 32, 200, 29)
    GUICtrlSetFont(-1, 16, 800, 0, "Bell MT")
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    Return
EndFunc   ;==>display

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

            ;Case $Form1

        Case $Input1
            $a = GUICtrlRead($Input1)
        Case $Input2
            $b = GUICtrlRead($Input2)
        Case $Root
            $c = Execute("$a^$b")
            Display()
        Case $recip
            $c = Execute("1 / $a")
            Display()
        Case $Mult
            $c = Execute("$a*$b")
            Display()
        Case $Div
            $c = Execute("$a/$b")
            Display()
        Case $Add
            $c = Execute("$a+$b")
            Display()
        Case $Sub
            $c = Execute("$a-$b")
            Display()
        Case $Per
            $c = Execute("($a*$b)/100")
            Display()
        Case $Sin
            $c = Execute("Sin($a)")
            Display()
        Case $Clr
            $c = ""
            Display()

        Case $rad2deg
            $pi = 4 * ATan(1) ;equals 3.14159265358979
            $radToDeg = 180 / $pi
            $c = Execute("$c * $radToDeg")
            Display()

        Case $c2a
            $a = $c
            $Input1 = GUICtrlCreateInput($a, 40, 104, 145, 21)

        Case $c2b
            $b = $c
            $Input2 = GUICtrlCreateInput($b, 40, 144, 145, 21)

        Case $Pi
            $a = 4 * ATan(1) ;equals 3.14159265358979
            $Input1 = GUICtrlCreateInput($a, 40, 104, 145, 21)




    EndSwitch

WEnd

post-38053-0-62494500-1302494347_thumb.j

Edited by DaveB

Share this post


Link to post
Share on other sites

Update New Modify. Mini Calculator Glass.

#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <WinAPIEx.au3>

Opt("MustDeclareVars", 1)

HotKeySet("{ESC}", "send_close")
HotKeySet("1", "send_1")
HotKeySet("2", "send_2")
HotKeySet("3", "send_3")
HotKeySet("4", "send_4")
HotKeySet("5", "send_5")
HotKeySet("6", "send_6")
HotKeySet("7", "send_7")
HotKeySet("8", "send_8")
HotKeySet("9", "send_9")
HotKeySet("0", "send_0")
HotKeySet(".", "send_dot")
HotKeySet("=", "send_ans")
HotKeySet("{+}", "send_add")
HotKeySet("{-}", "send_sub")
HotKeySet("{*}", "send_mul")
HotKeySet("{/}", "send_div")
HotKeySet("{BS}", "send_back")
HotKeySet("{DEL}", "send_clear")
HotKeySet("{Numpad1}", "send_num_1")
HotKeySet("{Numpad2}", "send_num_2")
HotKeySet("{Numpad3}", "send_num_3")
HotKeySet("{Numpad4}", "send_num_4")
HotKeySet("{Numpad5}", "send_num_5")
HotKeySet("{Numpad6}", "send_num_6")
HotKeySet("{Numpad7}", "send_num_7")
HotKeySet("{Numpad8}", "send_num_8")
HotKeySet("{Numpad9}", "send_num_9")
HotKeySet("{Numpad0}", "send_num_0")
HotKeySet("{NumpadDot}", "send_num_dot")
HotKeySet("{NumpadAdd}", "send_num_add")
HotKeySet("{NumpadSub}", "send_num_sub")
HotKeySet("{NumpadMult}", "send_num_mul")
HotKeySet("{NumpadDiv}", "send_num_div")

Global $Input, $Btn1, $Btn2, $Btn3, $Btn4, $Btn5, $Btn6, $Btn7
Global $Btn8, $Btn9, $Btn0, $Btn_add, $Btn_sub, $Btn_mul
Global $Btn_div, $Btn_clear, $Btn_dot, $Btn_ans_com, $Btn_ans_add
Global $Btn_ans_sub, $Btn_ans_mul, $Btn_ans_div, $nMsg, $read
Global $title = "Mini Calculator", $cid = "Edit1", $sread, $thim
Global $sFile = @SystemDir&'\Calc.exe', $hForm, $sFile, $Btn_back
main()
Func main()
$hForm = GUICreate("Mini Calculator", 305, 103, -1, -1, -1, $WS_EX_LAYERED)
GUISetBkColor(0xABABAB)
GUISetIcon($sFile, -1, $hForm)
$Input = GUICtrlCreateInput("0", 8, 8, 290, 21, _
BitOR($ES_RIGHT,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN), _
BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Btn1 = GUICtrlCreateButton("1", 8, 40, 27, 25, $WS_GROUP)
$Btn2 = GUICtrlCreateButton("2", 40, 40, 27, 25, $WS_GROUP)
$Btn3 = GUICtrlCreateButton("3", 72, 40, 27, 25, $WS_GROUP)
$Btn4 = GUICtrlCreateButton("4", 104, 40, 27, 25, $WS_GROUP)
$Btn5 = GUICtrlCreateButton("5", 136, 40, 27, 25, $WS_GROUP)
$Btn6 = GUICtrlCreateButton("6", 8, 72, 27, 25, $WS_GROUP)
$Btn7 = GUICtrlCreateButton("7", 40, 72, 27, 25, $WS_GROUP)
$Btn8 = GUICtrlCreateButton("8", 72, 72, 27, 25, $WS_GROUP)
$Btn9 = GUICtrlCreateButton("9", 104, 72, 27, 25, $WS_GROUP)
$Btn0 = GUICtrlCreateButton("0", 136, 72, 27, 25, $WS_GROUP)
$Btn_add = GUICtrlCreateButton("+", 176, 40, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Btn_sub = GUICtrlCreateButton("-", 208, 40, 27, 25, $BS_BOTTOM)
GUICtrlSetFont(-1, 15, 400, 0, "Arial")
$Btn_mul = GUICtrlCreateButton("*", 176, 72, 27, 25, BitOR($BS_TOP,$WS_GROUP))
GUICtrlSetFont(-1, 18, 400, 0, "Arial")
$Btn_div = GUICtrlCreateButton("/", 208, 72, 27, 25)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
$Btn_clear = GUICtrlCreateButton("c", 240, 40, 27, 25)
GUICtrlSetFont(-1, 11, 400, 0, "Arial")
$Btn_back = GUICtrlCreateButton("BS", 270, 40, 27, 25)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Btn_dot = GUICtrlCreateButton(".", 240, 72, 27, 25, $BS_BOTTOM )
GUICtrlSetFont(-1, 18, 400, 0, "Arial")
$Btn_ans_com = GUICtrlCreateButton("=", 272, 72, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Btn_ans_add = GUICtrlCreateButton("=", 272, 72, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetState(-1, $GUI_HIDE)
$Btn_ans_sub = GUICtrlCreateButton("=", 272, 72, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetState(-1, $GUI_HIDE)
$Btn_ans_mul = GUICtrlCreateButton("=", 272, 72, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetState(-1, $GUI_HIDE)
$Btn_ans_div = GUICtrlCreateButton("=", 272, 72, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetState(-1, $GUI_HIDE)
GUISetState(@SW_SHOW)
_WinAPI_SetLayeredWindowAttributes($hForm, 0xABABAB, 255, BitOR($LWA_COLORKEY, $LWA_ALPHA))
While 1
        $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Btn1
            GUICtrlSetData($Input, GUICtrlRead($Input)&1)
        Case $Btn2
            GUICtrlSetData($Input, GUICtrlRead($Input)&2)
        Case $Btn3
            GUICtrlSetData($Input, GUICtrlRead($Input)&3)
        Case $Btn4
            GUICtrlSetData($Input, GUICtrlRead($Input)&4)
        Case $Btn5
            GUICtrlSetData($Input, GUICtrlRead($Input)&5)
        Case $Btn6
            GUICtrlSetData($Input, GUICtrlRead($Input)&6)
        Case $Btn7
            GUICtrlSetData($Input, GUICtrlRead($Input)&7)
        Case $Btn8
            GUICtrlSetData($Input, GUICtrlRead($Input)&8)
        Case $Btn9
            GUICtrlSetData($Input, GUICtrlRead($Input)&9)
        Case $Btn0
            GUICtrlSetData($Input, GUICtrlRead($Input)&0)
        Case $Btn_dot
            GUICtrlSetData($Input, GUICtrlRead($Input)&'.')
        Case $Btn_back
            $thim = StringTrimRight(GUICtrlRead($Input), 1)
            GUICtrlSetData($Input, $thim)
        Case $Btn_add
            If GUICtrlRead($Input) <> '' Then
            GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_add, $GUI_SHOW)
            $read = GUICtrlRead($Input)
            GUICtrlSetData($Input, '')
            EndIf
        Case $Btn_sub
            If GUICtrlRead($Input) <> '' Then
            GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_SHOW)
            $read = GUICtrlRead($Input)
            GUICtrlSetData($Input, '')
            EndIf
        Case $Btn_mul
            If GUICtrlRead($Input) <> '' Then
            GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mul, $GUI_SHOW)
            $read = GUICtrlRead($Input)
            GUICtrlSetData($Input, '')
            EndIf
        Case $Btn_div
            If GUICtrlRead($Input) <> '' Then
            GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_SHOW)
            $read = GUICtrlRead($Input)
            GUICtrlSetData($Input, '')
            EndIf
        Case $Btn_ans_add
            GUICtrlSetData($Input, $read+GUICtrlRead($Input))
        Case $Btn_ans_sub
            GUICtrlSetData($Input, $read-GUICtrlRead($Input))
        Case $Btn_ans_mul
            GUICtrlSetData($Input, $read*GUICtrlRead($Input))
        Case $Btn_ans_div
            GUICtrlSetData($Input, $read/GUICtrlRead($Input))
        Case $Btn_clear
            GUICtrlSetState($Btn_ans_com, $GUI_SHOW)
            GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
            GUICtrlSetData($Input, '')
            ContinueLoop
    EndSwitch
WEnd
EndFunc

Func send_1()

    GUICtrlSetData($Input, GUICtrlRead($Input)&1)
EndFunc

Func send_2()
    GUICtrlSetData($Input, GUICtrlRead($Input)&2)
EndFunc

Func send_3()
    GUICtrlSetData($Input, GUICtrlRead($Input)&3)
EndFunc

Func send_4()
    GUICtrlSetData($Input, GUICtrlRead($Input)&4)
EndFunc

Func send_5()
    GUICtrlSetData($Input, GUICtrlRead($Input)&5)
EndFunc

Func send_6()
    GUICtrlSetData($Input, GUICtrlRead($Input)&6)
EndFunc

Func send_7()
    GUICtrlSetData($Input, GUICtrlRead($Input)&7)
EndFunc

Func send_8()
    GUICtrlSetData($Input, GUICtrlRead($Input)&8)
EndFunc

Func send_9()
    GUICtrlSetData($Input, GUICtrlRead($Input)&9)
EndFunc

Func send_0()
    GUICtrlSetData($Input, GUICtrlRead($Input)&0)
EndFunc

Func send_dot()
    GUICtrlSetData($Input, GUICtrlRead($Input)&".")
EndFunc

Func send_back()
    $thim = StringTrimRight(GUICtrlRead($Input), 1)
    GUICtrlSetData($Input, $thim)
EndFunc

Func send_add()
    If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_add, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_add, $GUI_FOCUS)
        $read = GUICtrlRead($Input)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_sub()
    If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_sub, $GUI_FOCUS)
        $read = GUICtrlRead($Input)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_mul()
    If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_mul, $GUI_FOCUS)
        $read = GUICtrlRead($Input)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_div()
    If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_div, $GUI_FOCUS)
        $read = GUICtrlRead($Input)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_clear()
    If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_ans()
    WinWaitActive($title, "", 1)
    Send("{ENTER}")
EndFunc

Func enter()
    WinWaitActive($title, "", 1)
    Send("{ENTER}")
EndFunc

Func send_num_1()
    GUICtrlSetData($Input, GUICtrlRead($Input)&1)
EndFunc

Func send_num_2()
    GUICtrlSetData($Input, GUICtrlRead($Input)&2)
EndFunc

Func send_num_3()
    GUICtrlSetData($Input, GUICtrlRead($Input)&3)
EndFunc

Func send_num_4()
    GUICtrlSetData($Input, GUICtrlRead($Input)&4)
EndFunc

Func send_num_5()
    GUICtrlSetData($Input, GUICtrlRead($Input)&5)
EndFunc

Func send_num_6()
    GUICtrlSetData($Input, GUICtrlRead($Input)&6)
EndFunc

Func send_num_7()
    GUICtrlSetData($Input, GUICtrlRead($Input)&7)
EndFunc

Func send_num_8()
    GUICtrlSetData($Input, GUICtrlRead($Input)&8)
EndFunc

Func send_num_9()
    GUICtrlSetData($Input, GUICtrlRead($Input)&9)
EndFunc

Func send_num_0()
    GUICtrlSetData($Input, GUICtrlRead($Input)&0)
EndFunc

Func send_num_dot()
    GUICtrlSetData($Input, GUICtrlRead($Input)&".")
EndFunc


Func send_num_add()
    If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_add, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_add, $GUI_FOCUS)
        $read = GUICtrlRead($Input)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_num_sub()
    If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_sub, $GUI_FOCUS)
        $read = GUICtrlRead($Input)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_num_mul()
    If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_mul, $GUI_FOCUS)
        $read = GUICtrlRead($Input)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_num_div()
   If GUICtrlRead($Input) <> '' Then
        GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_mul, $GUI_HIDE)
        GUICtrlSetState($Btn_ans_div, $GUI_SHOW)
        GUICtrlSetState($Btn_ans_div, $GUI_FOCUS)
        $read = GUICtrlRead($Input)
        GUICtrlSetData($Input, '')
    EndIf
EndFunc

Func send_close()
    Exit
EndFunc

post-63570-0-79052500-1302529189_thumb.j

Share this post


Link to post
Share on other sites

See my listing of all maths stuff in AutoIt I have found from various users: http://code.google.com/p/m-a-t/wiki/Maths

It's pretty complete, though I'm sure its missing some... 12 UDFs, 19 programs (12 of which are calculators).

Mat

Share this post


Link to post
Share on other sites

AZJIO

Thanks for the code and program.

Thanks Sam for combat worthiness.

I will be developed in writing better code. :unsure:

Share this post


Link to post
Share on other sites

SAK: I get two errors when I try to run your script. Did I do something wrong?

: ERROR: can't open include file <WinAPIEx.au3>

C:\Documents and Settings\Program Files\AutoIt\Calculator.au3(6,10) : ERROR: can't open include file <WinAPIEx.au3>

#Include <WinAPIEx.au3>

~~~~~~~~~^

C:\Documents and Settings\Program Files\AutoIt\Calculator.au3(100,91) : ERROR: _WinAPI_SetLayeredWindowAttributes(): undefined function.

_WinAPI_SetLayeredWindowAttributes($hForm, 0xABABAB, 255, BitOR($LWA_COLORKEY, $LWA_ALPHA))

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

You can find the

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Great! Where do they need to be placed?

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Last modify update. Calculator desktop. :unsure:

Forget includ file WinAPIEx.au3

#NoTrayIcon
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <WinAPIEx.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "guiclose")
Opt("MustDeclareVars", 1)

main()
Func main()
Local $title = "MiniCalcDesktop", $cid = "Edit1"
Local $sFile = @SystemDir&'\Calc.exe'
Local $hForm, $Inp_disp, $Btn_back, $Btn_clear, $Btn7, $Btn8, $Btn9
Local $Btn4, $Btn5, $Btn6, $Btn1, $Btn2, $Btn3, $Btn0, $Btn_dot
Local $Btn_mult, $Btn_div, $Btn_sub, $Btn_add, $Btn_ans_div, $Btn_ans_mult
Local $Btn_ans_sub, $Btn_ans_add, $Btn_ans_com, $Menu1, $Submenu1a
Local $Submenu1b, $Menu2, $Submenu2a, $Submenu2b, $Menu3, $Submenu_about
Local $Submenu3b, $Submenu1_exit, $nMsg, $i, $read, $trim, $sFile, $Btn_back

$hForm = GUICreate($title, @DesktopWidth, @DesktopHeight, -1, -1, _
BitOR($WS_POPUP,$WS_CLIPSIBLINGS), BitOR($WS_EX_WINDOWEDGE,$WS_EX_LAYERED))
GUISetBkColor(0xABABAB)
WinSetOnTop($title, "", 1)
GUISetIcon($sFile, -1, $hForm)
$Menu1 = GUICtrlCreateMenu("Edit")
$Submenu1a = GUICtrlCreateMenuItem("Copy  Ctrl+C", $Menu1)
$Submenu1b = GUICtrlCreateMenuItem("Paste  Ctrl+V", $Menu1)
GUICtrlCreateMenuItem("", $Menu1, 2)
$Submenu1_exit = GUICtrlCreateMenuItem("Exit     ESC", $Menu1)
$Menu2 = GUICtrlCreateMenu("View")
$Submenu2a = GUICtrlCreateMenuItem("Standard", $Menu2)
$Submenu2b = GUICtrlCreateMenuItem("Classic", $Menu2)
$Menu3 = GUICtrlCreateMenu("About")
$Submenu_about = GUICtrlCreateMenuItem("About", $Menu3)
$Submenu3b = GUICtrlCreateMenuItem("Help", $Menu3)
$Inp_disp = GUICtrlCreateInput("0", 8, 10, 120, 20, _
BitOR($ES_RIGHT,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN), _
BitOR($WS_EX_CLIENTEDGE,$WS_EX_STATICEDGE))
GUICtrlSetFont(-1, 9, 400, 0, "Arial")
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Btn7 = GUICtrlCreateButton("7", 8, 70, 27, 25, $WS_GROUP)
$Btn8 = GUICtrlCreateButton("8", 40, 70, 27, 25, $WS_GROUP)
$Btn9 = GUICtrlCreateButton("9", 72, 70, 27, 25, $WS_GROUP)
$Btn4 = GUICtrlCreateButton("4", 8, 100, 27, 25, $WS_GROUP)
$Btn5 = GUICtrlCreateButton("5", 40, 100, 27, 25, $WS_GROUP)
$Btn6 = GUICtrlCreateButton("6", 72,100, 27, 25, $WS_GROUP)
$Btn1 = GUICtrlCreateButton("1", 8, 130, 27, 25, $WS_GROUP)
$Btn2 = GUICtrlCreateButton("2", 40, 130, 27, 25, $WS_GROUP)
$Btn3 = GUICtrlCreateButton("3", 72, 130, 27, 25, $WS_GROUP)
$Btn0 = GUICtrlCreateButton("0", 8, 160, 27, 25, $WS_GROUP)
$Btn_dot = GUICtrlCreateButton(".", 40, 160, 27, 25, $BS_BOTTOM )
GUICtrlSetFont(-1, 18, 400, 0, "Arial")
$Btn_back = GUICtrlCreateButton("BS", 8, 40, 27, 25)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Btn_clear = GUICtrlCreateButton("c", 103, 40, 27, 25)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
$Btn_div = GUICtrlCreateButton("/", 104, 70, 27, 25)
GUICtrlSetFont(-1, 10, 400, 0, "Arial")
$Btn_mult = GUICtrlCreateButton("*", 104, 100, 27, 25, BitOR($BS_TOP,$WS_GROUP))
GUICtrlSetFont(-1, 18, 400, 0, "Arial")
$Btn_sub = GUICtrlCreateButton("-", 104, 130, 27, 25, $BS_BOTTOM)
GUICtrlSetFont(-1, 15, 400, 0, "Arial")
$Btn_add = GUICtrlCreateButton("+", 104, 160, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Btn_ans_com = GUICtrlCreateButton("=", 72, 160, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
$Btn_ans_add = GUICtrlCreateButton("=", 72, 160, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetState(-1, $GUI_HIDE)
$Btn_ans_sub = GUICtrlCreateButton("=", 72, 160, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetState(-1, $GUI_HIDE)
$Btn_ans_mult = GUICtrlCreateButton("=", 72, 160, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetState(-1, $GUI_HIDE)
$Btn_ans_div = GUICtrlCreateButton("=", 72, 160, 27, 25)
GUICtrlSetFont(-1, 12, 400, 0, "Arial")
GUICtrlSetState(-1, $GUI_HIDE)
GUISetState(@SW_SHOW)
WinMove($title, "", 890, 5)
_WinAPI_SetLayeredWindowAttributes($hForm, 0xABABAB, 255, BitOR($LWA_COLORKEY, $LWA_ALPHA))

While 1
        $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Submenu1_exit
            ExitLoop
        Case $Submenu_about
            ToolTip("Design by:Sak2005"&@CRLF&"CopyRight:2011", 820, 120, "About", 1, 2)
            Sleep(3000)
            ToolTip("")
        Case $Btn1
            GUICtrlSetData($Inp_disp, GUICtrlRead($Inp_disp)&1)
        Case $Btn2
            GUICtrlSetData($Inp_disp, GUICtrlRead($Inp_disp)&2)
        Case $Btn3
            GUICtrlSetData($Inp_disp, GUICtrlRead($Inp_disp)&3)
        Case $Btn4
            GUICtrlSetData($Inp_disp, GUICtrlRead($Inp_disp)&4)
        Case $Btn5
            GUICtrlSetData($Inp_disp, GUICtrlRead($Inp_disp)&5)
        Case $Btn6
            GUICtrlSetData($Inp_disp, GUICtrlRead($Inp_disp)&6)
        Case $Btn7
            GUICtrlSetData($Inp_disp, GUICtrlRead($Inp_disp)&7)
        Case $Btn8
            GUICtrlSetData($Inp_disp, GUICtrlRead($Inp_disp)&8)
        Case $Btn9
            GUICtrlSetData($Inp_disp, GUICtrlRead($Inp_disp)&9)
        Case $Btn0
            GUICtrlSetData($Inp_disp, GUICtrlRead($Inp_disp)&0)
        Case $Btn_dot
            GUICtrlSetData($Inp_disp, GUICtrlRead($Inp_disp)&'.')
        Case $Btn_back
            $trim = StringTrimRight(GUICtrlRead($Inp_disp), 1)
            GUICtrlSetData($Inp_disp, $trim)
        Case $Btn_add
            If GUICtrlRead($Inp_disp) <> '' Then
            GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mult, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_add, $GUI_SHOW)
            $read = GUICtrlRead($Inp_disp)
            GUICtrlSetData($Inp_disp, '')
            EndIf
        Case $Btn_sub
            If GUICtrlRead($Inp_disp) <> '' Then
            GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mult, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_SHOW)
            $read = GUICtrlRead($Inp_disp)
            GUICtrlSetData($Inp_disp, '')
            EndIf
        Case $Btn_mult
            If GUICtrlRead($Inp_disp) <> '' Then
            GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mult, $GUI_SHOW)
            $read = GUICtrlRead($Inp_disp)
            GUICtrlSetData($Inp_disp, '')
            EndIf
        Case $Btn_div
            If GUICtrlRead($Inp_disp) <> '' Then
            GUICtrlSetState($Btn_ans_com, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mult, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_SHOW)
            $read = GUICtrlRead($Inp_disp)
            GUICtrlSetData($Inp_disp, '')
            EndIf
        Case $Btn_ans_add
            GUICtrlSetData($Inp_disp, $read+GUICtrlRead($Inp_disp))
        Case $Btn_ans_sub
            GUICtrlSetData($Inp_disp, $read-GUICtrlRead($Inp_disp))
        Case $Btn_ans_mult
            GUICtrlSetData($Inp_disp, $read*GUICtrlRead($Inp_disp))
        Case $Btn_ans_div
            GUICtrlSetData($Inp_disp, $read/GUICtrlRead($Inp_disp))
        Case $Btn_clear
            GUICtrlSetState($Btn_ans_com, $GUI_SHOW)
            GUICtrlSetState($Btn_ans_add, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_sub, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_mult, $GUI_HIDE)
            GUICtrlSetState($Btn_ans_div, $GUI_HIDE)
            GUICtrlSetData($Inp_disp, '')
            ContinueLoop
    EndSwitch
WEnd
EndFunc

Func guiclose()
    Exit
EndFunc
Edited by sak

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0