Jump to content

problems Automating metastock program


Recommended Posts

Hi All

This is my first post to this forum, It is early days for me using Autoit as well so I guess I am asking pretty basic questions. Anyway I hope someone may be able to point me in the right direction.

I tried the following: (However I am at a loss to determine how 5782 was found)

If ProcessExists('MsWin.exe') Then
If WinWait("[CLASS:MetaStockMainWnd]", "", 2) Then ;
    $hWin = WinGetHandle("[CLASS:MetaStockMainWnd]") ;

;ControlCommand("", "", "ToolbarWindow324", "SendCommandID", "5782")
ControlCommand("", "", "ToolbarWindow324", "SendCommandID", "580")

    EndIf
Else
    MsgBox(48, " Error", "Does not work")
EndIf
Sleep(3000)

The code above is base on Atanik's post, it runs without error although Metastock did no show any response. That may be correct as the data I am using to feed the chart is static so a refresh would not show any change.

I was hoping that using Ataniks example I could get to the all important "Hello world moment" for those that can remember GW basic way back it was always the first example. (These days I am Ok with Visual basic and Happy with MS Access VBA) However API coding I am not familiar with.

A data service I have subscribed to is closing down and Autoit will be perfect to connect Metastock my existing program providing charting.

Below is 2 screenshots of Metastock that shows the file menu and the window that opens when open (Using [ctrl]+O) is used As I understand it Autoit requires ^0 for this command Closing is just as simple Using ^C or ^E

When manually driving metastock you do not even have to open a menu

As long as the program has the focus as soon as it is opened hotkeys will work.

 [ctrl]+O will open the file dialogue with the code selection box already focussed
The same applies to closing a chart ctrl+C or Ctrl+E (for more than one) will work without opening a menu.

I have tried send() and ControlSend() but have not been able to get them working
I can see the menu items using using inspection tools.

The only interaction I need at this stage is being able to send those hotkey combinations to the Metastock program, Once this is working be able to call the scripts from VBA. with one parameter the stock code. I will work on that once the basics are done.

I can see it is going to be a steep learning curve at the start and that there are several ways for Autoit to achieve the result. using mouse positions and clicks, opening combo boxes or using the available hot keys within metastock. 

All I need to do is display and replace charts. as selected in another program one at a time.

Any suggestions would be most appreciated.

Regards
John

See below 4 screenshot images plus a B&W image uploaded in error I cant delete.image.png.aed931e82fe3738e1da1856ca602c024.png

image.png.8966c49218b30bf802a39307e5df89e8.png
image.thumb.png.0818d32f5de9a4264d3e6c497a68cee6.pngimage.thumb.png.b49323ed8d0997956fdc48b438ce8e4c.png

image.png

Link to comment
Share on other sites

Hi All
I know it is bad etiquette to multi post the same post on a forum, However I posted in Atanik,s  post in error not having noticed that it was marked SOLVED. Alas my problem is not solved. Any thoughts would be appreciated.
Regards
John
 

-snipped link as the post is now above this post-

Edited by Jos
Link to comment
Share on other sites

On 5/24/2019 at 10:12 PM, Zedna said:

Look at my posts in this topic

 

Soluton is to use Winspector to identify CommandID and in AutoIt use _SendMessage() + WM_COMMAND + this CommandID as wparam

Hi All

Firstly Thank you for your help.

The following code works!
From  a cold start Autoit has made a bumpy road for me. Note the warning about message boxes.  What got me was that the file open dialogue box did not stay open as it normally does by waiting for the stock code when used manually. Put a message box after it and it will close in a blink.

Yes the code contains lots and lots of tests, and it is not pretty!
I found that testing every single line was the only way to progress while learning. 

Does the editor have a code tidy up util?
Anyway I put it up so that maybe someone else in similar circumstances to me with Metastock in mind might find it useful.

In order to make it run from the command line for testing only I made two windows shortcuts. The path will need to be changed to fit the users computer.
Later this will be replaced by a call from Visual Basic in my app.

"C:\Users\your youserID\Desktop\AUTOIT\Meta test 10 first working.exe" "CBA"
"C:\Users\your youserID\Desktop\AUTOIT\Meta test 10 first working.exe" "ANZ"

Anyway it's rather late my bio battery needs charging.
Will pop in here with an update soon.
Any thoughts would be welcome.

Regards
John

Code starts here

;Opt ("WinTitleMatchMode", 2)
;Message boxes will stop your program flow and you may not see opening windows, Use Consol;e write
;In File properties disable digital signatures for MsWin.exe needs to be tested to stop the pop up

#include <MsgBoxConstants.au3>
#requireadmin

ConsoleWrite('****** Here 1 ******   ' &  @crlf)

if WinActivate("[CLASS:MetaStockMainWnd]","") Then
ConsoleWrite('****** Metastock Window Activated ******   ' &  @crlf)
;MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "Warning", "Window activated" & @CRLF & @CRLF & "May be your system is pretty fast.")
Else
        ConsoleWrite('****** Metastock Window not activated ******   ' &  @crlf)
        ; Notepad will be displayed as MsgBox introduce a delay and allow it.
           ;MsgBox($MB_SYSTEMMODAL, "", "Window not activated" & @CRLF & @CRLF & "....", 5)
EndIf
ConsoleWrite('****** The main window of metastock is open and it will accept control key commands ******    ' &  @crlf)
;So we know it is activated at this point.
;Sleep(2000)

;Code below will close all open charts
;We need to trap error

#include <MsgBoxConstants.au3>

Global $sText

Example() ;Just a test

Func Example()
    ; Retrieve the window title of the active window.
    $sText = WinGetTitle("[ACTIVE]")
    ; Display the window title.
    ;MsgBox($MB_SYSTEMMODAL, "", $sText)
EndFunc   ;==>Example

if $sText = "Metastock" Then ; there was no chart open in title
Else
Send("!F")
Send("clos&e all")
endIf

;Code below will open a chart
Send("^o")

local $Var1
$var1 = $CmdLine[1]
send($var1)
;Send("BHP")
Send("{enter}")

sleep(3000)

ConsoleWrite('****** Works to here ******    ' &  @crlf)

;This test works also
;MsgBox(64, "Passed Parameters", $CmdLine[0] & " parameters have been passed to this script:")
For $i = 1 To $CmdLine[0]
    ;MsgBox(64, "Passed Parameters", "Parameter " & $i & ": " & $CmdLine[$i])
Next

Link to comment
Share on other sites

On 5/24/2019 at 10:12 PM, Zedna said:

Look at my posts in this topic

 

Soluton is to use Winspector to identify CommandID and in AutoIt use _SendMessage() + WM_COMMAND + this CommandID as wparam

Hi All

Firstly Thank you for your help.

The following code works!
From  a cold start Autoit has made a bumpy road for me. Note the warning about message boxes.  What got me was that the file open dialogue box did not stay open as it normally does by waiting for the stock code when used manually. Put a message box after it and it will close in a blink.

Yes the code contains lots and lots of tests, and it is not pretty!
I found that testing every single line was the only way to progress while learning. 

Does the editor have a code tidy up util?
Anyway I put it up so that maybe someone else in similar circumstances to me with Metastock in mind might find it useful.

In order to make it run from the command line for testing only I made two windows shortcuts. The path will need to be changed to fit the users computer.
Later this will be replaced by a call from Visual Basic in my app.

"C:\Users\your youserID\Desktop\AUTOIT\Meta test 10 first working.exe" "CBA"
"C:\Users\your youserID\Desktop\AUTOIT\Meta test 10 first working.exe" "ANZ"

Anyway it's rather late my bio battery needs charging.
Will pop in here with an update soon.
Any thoughts would be welcome.

Regards
John

Code starts here

;Opt ("WinTitleMatchMode", 2)
;Message boxes will stop your program flow and you may not see opening windows, Use Consol;e write
;In File properties disable digital signatures for MsWin.exe needs to be tested to stop the pop up

#include <MsgBoxConstants.au3>
#requireadmin

ConsoleWrite('****** Here 1 ******   ' &  @crlf)

if WinActivate("[CLASS:MetaStockMainWnd]","") Then
ConsoleWrite('****** Metastock Window Activated ******   ' &  @crlf)
;MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "Warning", "Window activated" & @CRLF & @CRLF & "May be your system is pretty fast.")
Else
        ConsoleWrite('****** Metastock Window not activated ******   ' &  @crlf)
        ; Notepad will be displayed as MsgBox introduce a delay and allow it.
           ;MsgBox($MB_SYSTEMMODAL, "", "Window not activated" & @CRLF & @CRLF & "....", 5)
EndIf
ConsoleWrite('****** The main window of metastock is open and it will accept control key commands ******    ' &  @crlf)
;So we know it is activated at this point.
;Sleep(2000)

;Code below will close all open charts
;We need to trap error

#include <MsgBoxConstants.au3>

Global $sText

Example() ;Just a test

Func Example()
    ; Retrieve the window title of the active window.
    $sText = WinGetTitle("[ACTIVE]")
    ; Display the window title.
    ;MsgBox($MB_SYSTEMMODAL, "", $sText)
EndFunc   ;==>Example

if $sText = "Metastock" Then ; there was no chart open in title
Else
Send("!F")
Send("clos&e all")
endIf

;Code below will open a chart
Send("^o")

local $Var1
$var1 = $CmdLine[1]
send($var1)
;Send("BHP")
Send("{enter}")

sleep(3000)

ConsoleWrite('****** Works to here ******    ' &  @crlf)

;This test works also
;MsgBox(64, "Passed Parameters", $CmdLine[0] & " parameters have been passed to this script:")
For $i = 1 To $CmdLine[0]
    ;MsgBox(64, "Passed Parameters", "Parameter " & $i & ": " & $CmdLine[$i])
Next

*****************

Hi All

I am really impressed by Autoit and I have only scratched the surface! 

A further update, There are still some bugs to sort out but I now have the code running from My MS Access VBA App Using the Shell command.
The Path is hard coded, not good practice but fine for testing.

stAppName = "C:\Users\JCM\Desktop\AUTOIT\Meta test 10 first working.exe " & code
    Call Shell(stAppName, 1)
    'MsgBox ("here")'Test only

This code is part of a Sub that is run when scrolling through a list using the mouse or scroll keys & Code is appended as a parameter Code a string contains a stock code to display with Metastock.

I did find the Tidy code switch.

Its not finished work yet. The speed needs to be improved if possible and there will no doubt be a few gremlins that come out of the woodwork. These will show up when I use the program. I will report back as they show up.

In the mean time any thoughts on improving the efficiency of the code would be welcome.

Regards
John

 

Autoit code starts here:****************************

#AutoIt3Wrapper_Run_Obfuscator=Y
#Obfuscator_Parameters=/SF /SV /OM /CS=0 /CN=0

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;Opt ("WinTitleMatchMode", 2)
;Message boxes will stop your program flow and you may not see opening windows, Use Consol;e write
;In File properties diaable digital signatures for MsWin.exe

#include <MsgBoxConstants.au3>

ConsoleWrite('****** Here 1 ******   ' & @CRLF)

If WinActivate("[CLASS:MetaStockMainWnd]", "") Then
    ConsoleWrite('****** Metastock Window Activated ******   ' & @CRLF)
    ;MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "Warning", "Window activated" & @CRLF & @CRLF & "May be your system is pretty fast.")
Else
    ConsoleWrite('****** Metastock Window not activated ******   ' & @CRLF)
    ; Notepad will be displayed as MsgBox introduce a delay and allow it.
    ;MsgBox($MB_SYSTEMMODAL, "", "Window not activated" & @CRLF & @CRLF & "....", 5)
EndIf
ConsoleWrite('****** The main window of metastock is open and it will accept control key commands ******    ' & @CRLF)
;So we know it is activated at this point.
;Sleep(2000)

;Code below will close all open charts
;We need to trap error

#include <MsgBoxConstants.au3>

Global $sText

Example() ;Just a test

Func Example()
    ; Retrieve the window title of the active window.
    $sText = WinGetTitle("[ACTIVE]")
    ; Display the window title.
    ;MsgBox($MB_SYSTEMMODAL, "", $sText)
EndFunc   ;==>Example

If $sText = "Metastock" Then ; there was no chart open in title
Else
    Send("!F")
    Send("clos&e all")
EndIf

;Code below will open a chart
Send("^o")

Local $Var1
$Var1 = $CmdLine[1]
Send($Var1)
;Send("BHP")
Send("{enter}")

send("Auto Tile") ;Makes Chart fill window
;send("Maximize"); Not working
;sleep(3000)

ConsoleWrite('****** Works to here ******    ' & @CRLF)

;This test works
;MsgBox(64, "Passed Parameters", $CmdLine[0] & " parameters have been passed to this script:")
;For $i = 1 To $CmdLine[0]
    ;MsgBox(64, "Passed Parameters", "Parameter " & $i & ": " & $CmdLine[$i])
;Next


;****** part of example found in the Metastock forum ******
;Hello Everybody Here is the code for switching periodicity automaticly using AutoIt the period start from 1 minute it increases by one untile 10 minute
;WinMenuSelectItem("[CLASS:MetaStockMainWnd]", "Metastock", "Periodicity")

;WinMenuSelectItem("[CLASS:MetaStockMainWnd]", "", "File", "O&pen")

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...