├── config.csv ├── THSTrader ├── packages.config ├── Win32MemoryAPI.cs ├── Properties │ └── AssemblyInfo.cs ├── Win32ClipboardAPI.cs ├── App.config ├── ClipData.cs ├── Program.cs ├── THSTrader.csproj ├── ClipboardHelper.cs ├── Utility.cs └── THSClient.cs ├── .gitattributes ├── THSTrader.sln └── .gitignore /config.csv: -------------------------------------------------------------------------------- 1 | MainWindowTitle,SHAccount,SZAccount 2 | 网上股票交易系统5.0,A573272915,0110008379 -------------------------------------------------------------------------------- /THSTrader/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /THSTrader/Win32MemoryAPI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | 4 | 5 | namespace THSTrader 6 | { 7 | internal class Win32MemoryAPI 8 | { 9 | [DllImport("Kernel32.dll", EntryPoint = "RtlMoveMemory", SetLastError = false)] 10 | public static extern void CopyMemory(IntPtr dest, IntPtr src, int size); 11 | 12 | [DllImport("kernel32.dll")] 13 | public static extern IntPtr GlobalAlloc(uint uFlags, UIntPtr dwBytes); 14 | 15 | [DllImport("kernel32.dll")] 16 | public static extern IntPtr GlobalLock(IntPtr hMem); 17 | 18 | [DllImport("kernel32.dll")] 19 | public static extern IntPtr GlobalUnlock(IntPtr hMem); 20 | 21 | [DllImport("kernel32.dll")] 22 | public static extern IntPtr GlobalFree(IntPtr hMem); 23 | 24 | [DllImport("kernel32.dll")] 25 | public static extern UIntPtr GlobalSize(IntPtr hMem); 26 | 27 | public const uint GMEM_DDESHARE = 0x2000; 28 | public const uint GMEM_MOVEABLE = 0x2; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /THSTrader.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "THSTrader", "THSTrader\THSTrader.csproj", "{E44B7E02-319D-4D8A-B09A-6DA1B93D3133}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {E44B7E02-319D-4D8A-B09A-6DA1B93D3133}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E44B7E02-319D-4D8A-B09A-6DA1B93D3133}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E44B7E02-319D-4D8A-B09A-6DA1B93D3133}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E44B7E02-319D-4D8A-B09A-6DA1B93D3133}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /THSTrader/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("THSTrader")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("THSTrader")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | //将 ComVisible 设置为 false 将使此程序集中的类型 18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("e44b7e02-319d-4d8a-b09a-6da1b93d3133")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /THSTrader/Win32ClipboardAPI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Text; 4 | 5 | 6 | namespace THSTrader 7 | { 8 | internal class Win32ClipboardAPI 9 | { 10 | [DllImport("user32.dll")] 11 | public static extern bool OpenClipboard(IntPtr hWndNewOwner); 12 | 13 | [DllImport("user32.dll")] 14 | public static extern bool EmptyClipboard(); 15 | 16 | [DllImport("user32.dll")] 17 | public static extern IntPtr GetClipboardData(uint uFormat); 18 | 19 | [DllImport("user32.dll")] 20 | public static extern IntPtr SetClipboardData(uint uFormat, IntPtr hMem); 21 | 22 | [DllImport("user32.dll")] 23 | public static extern bool CloseClipboard(); 24 | 25 | [DllImport("user32.dll")] 26 | public static extern uint EnumClipboardFormats(uint format); 27 | 28 | [DllImport("user32.dll")] 29 | public static extern int GetClipboardFormatName(uint format, [Out] StringBuilder lpszFormatName, int cchMaxCount); 30 | 31 | [DllImport("user32.dll", SetLastError = true)] 32 | public static extern uint RegisterClipboardFormat(string lpszFormat); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /THSTrader/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 | 42 | -------------------------------------------------------------------------------- /THSTrader/ClipData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Collections.ObjectModel; 5 | 6 | namespace THSTrader 7 | { 8 | /// 9 | /// Holds clipboard data of a single data format. 10 | /// 11 | [Serializable] 12 | public class DataClip 13 | { 14 | private uint format; 15 | 16 | /// 17 | /// Get or Set the format code of the data 18 | /// 19 | public uint Format 20 | { 21 | get { return format; } 22 | set { format = value; } 23 | } 24 | 25 | private string formatName; 26 | /// 27 | /// Get or Set the format name of the data 28 | /// 29 | public string FormatName 30 | { 31 | get { return formatName; } 32 | set { formatName = value; } 33 | } 34 | private byte[] buffer; 35 | 36 | private int size; 37 | 38 | /// 39 | /// Get or Set the buffer data 40 | /// 41 | public byte[] Buffer 42 | { 43 | get { return buffer; } 44 | set { buffer = value; } 45 | } 46 | /// 47 | /// Get the data buffer lenght 48 | /// 49 | public UIntPtr Size 50 | { 51 | get 52 | { 53 | if (buffer != null) 54 | { 55 | //Read the correct size from buffer, if it is not null 56 | return new UIntPtr(Convert.ToUInt32(buffer.GetLength(0))); 57 | } 58 | else 59 | { 60 | //else return the optional set size 61 | return new UIntPtr(Convert.ToUInt32(size)); 62 | } 63 | } 64 | } 65 | /// 66 | /// Init a Clip Data object, containing one clipboard data and its format 67 | /// 68 | /// 69 | /// 70 | /// 71 | public DataClip(uint format, string formatName, byte[] buffer) 72 | { 73 | this.format = format; 74 | this.formatName = formatName; 75 | this.buffer = buffer; 76 | this.size = 0; 77 | } 78 | /// 79 | /// Init an empty Clip Data object, used for serialize object 80 | /// 81 | public DataClip() { } 82 | } 83 | 84 | 85 | } 86 | -------------------------------------------------------------------------------- /THSTrader/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using Nancy.Hosting.Self; 7 | using Nancy; 8 | using System.Diagnostics; 9 | using System.Threading; 10 | 11 | namespace THSTrader 12 | { 13 | class Program : NancyModule 14 | { 15 | static THSClient client = new THSClient(); 16 | 17 | [STAThread] 18 | static void Main(string[] args) 19 | { 20 | string ip = "localhost"; 21 | string port = "9000"; 22 | string uri = string.Format(@"http://{0}:{1}", ip, port); 23 | 24 | using (var host = new NancyHost(new Uri(uri))) 25 | { 26 | 27 | double a = 0, b = 0, c = 0; 28 | client.GetAccountStat(ref a, ref b, ref c); 29 | 30 | var xxx1 = client.GetHoldingDetail(); 31 | var xxx2 = client.GetCommissionDetail(); 32 | 33 | string xxs = client.Cancel("", "all"); 34 | uint t1 = Utility.GetTickCount(); 35 | for (int i = 0; i < 1; i++) 36 | { 37 | string xx = ""; 38 | xx = client.Buy_Money("000725", 1000); 39 | if (xx != "") 40 | ; 41 | xx = client.Buy_Level("600401", 100, "b5"); 42 | if (xx != "") 43 | ; 44 | xx = client.Sell("601398", 1, 4.56); 45 | if (xx != "") 46 | ; 47 | xx = client.Buy("000725", 100, 2.78); 48 | if (xx != "") 49 | ; 50 | xx = client.Sell_Level("000002", 2, "b5"); 51 | if (xx != "") 52 | ; 53 | xx = client.Sell_Percent("159915", 0.1); 54 | if (xx != "") 55 | ; 56 | } 57 | uint t2 = Utility.GetTickCount(); 58 | uint t3 = t2 - t1; 59 | 60 | client.GetAccountStat(ref a, ref b, ref c); 61 | 62 | 63 | host.Start(); 64 | Console.WriteLine("Running on " + uri); 65 | 66 | string ipt = ""; 67 | while (ipt.Trim().ToLower() != "exit") 68 | { 69 | ipt = Console.ReadLine(); 70 | } 71 | } 72 | } 73 | } 74 | 75 | public class THSModule : NancyModule 76 | { 77 | static private int i = 0; 78 | //static THSClient client = new THSClient(); 79 | public THSModule() 80 | { 81 | Get["/"] = r => 82 | { 83 | //client.hWnd++; 84 | return Response.AsJson(new { result = true, message = 111 }); 85 | }; 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /THSTrader/THSTrader.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {E44B7E02-319D-4D8A-B09A-6DA1B93D3133} 8 | Exe 9 | Properties 10 | THSTrader 11 | THSTrader 12 | v4.5.2 13 | 512 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | ..\packages\Castle.Core.3.3.0\lib\net45\Castle.Core.dll 38 | True 39 | 40 | 41 | ..\packages\UIAComWrapper.1.1.0.14\lib\net40\Interop.UIAutomationClient.dll 42 | False 43 | 44 | 45 | ..\packages\Nancy.1.4.3\lib\net40\Nancy.dll 46 | True 47 | 48 | 49 | ..\packages\Nancy.Hosting.Self.1.4.1\lib\net40\Nancy.Hosting.Self.dll 50 | True 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 85 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | *.vcxproj.filters 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | bld/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | [Ll]og/ 27 | 28 | # Visual Studio 2015 cache/options directory 29 | .vs/ 30 | # Uncomment if you have tasks that create the project's static files in wwwroot 31 | #wwwroot/ 32 | 33 | # MSTest test Results 34 | [Tt]est[Rr]esult*/ 35 | [Bb]uild[Ll]og.* 36 | 37 | # NUNIT 38 | *.VisualState.xml 39 | TestResult.xml 40 | 41 | # Build Results of an ATL Project 42 | [Dd]ebugPS/ 43 | [Rr]eleasePS/ 44 | dlldata.c 45 | 46 | # .NET Core 47 | project.lock.json 48 | project.fragment.lock.json 49 | artifacts/ 50 | **/Properties/launchSettings.json 51 | 52 | *_i.c 53 | *_p.c 54 | *_i.h 55 | *.ilk 56 | *.meta 57 | *.obj 58 | *.pch 59 | *.pdb 60 | *.pgc 61 | *.pgd 62 | *.rsp 63 | *.sbr 64 | *.tlb 65 | *.tli 66 | *.tlh 67 | *.tmp 68 | *.tmp_proj 69 | *.log 70 | *.vspscc 71 | *.vssscc 72 | .builds 73 | *.pidb 74 | *.svclog 75 | *.scc 76 | 77 | # Chutzpah Test files 78 | _Chutzpah* 79 | 80 | # Visual C++ cache files 81 | ipch/ 82 | *.aps 83 | *.ncb 84 | *.opendb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | *.VC.db 89 | *.VC.VC.opendb 90 | 91 | # Visual Studio profiler 92 | *.psess 93 | *.vsp 94 | *.vspx 95 | *.sap 96 | 97 | # TFS 2012 Local Workspace 98 | $tf/ 99 | 100 | # Guidance Automation Toolkit 101 | *.gpState 102 | 103 | # ReSharper is a .NET coding add-in 104 | _ReSharper*/ 105 | *.[Rr]e[Ss]harper 106 | *.DotSettings.user 107 | 108 | # JustCode is a .NET coding add-in 109 | .JustCode 110 | 111 | # TeamCity is a build add-in 112 | _TeamCity* 113 | 114 | # DotCover is a Code Coverage Tool 115 | *.dotCover 116 | 117 | # Visual Studio code coverage results 118 | *.coverage 119 | *.coveragexml 120 | 121 | # NCrunch 122 | _NCrunch_* 123 | .*crunch*.local.xml 124 | nCrunchTemp_* 125 | 126 | # MightyMoose 127 | *.mm.* 128 | AutoTest.Net/ 129 | 130 | # Web workbench (sass) 131 | .sass-cache/ 132 | 133 | # Installshield output folder 134 | [Ee]xpress/ 135 | 136 | # DocProject is a documentation generator add-in 137 | DocProject/buildhelp/ 138 | DocProject/Help/*.HxT 139 | DocProject/Help/*.HxC 140 | DocProject/Help/*.hhc 141 | DocProject/Help/*.hhk 142 | DocProject/Help/*.hhp 143 | DocProject/Help/Html2 144 | DocProject/Help/html 145 | 146 | # Click-Once directory 147 | publish/ 148 | 149 | # Publish Web Output 150 | *.[Pp]ublish.xml 151 | *.azurePubxml 152 | # TODO: Comment the next line if you want to checkin your web deploy settings 153 | # but database connection strings (with potential passwords) will be unencrypted 154 | *.pubxml 155 | *.publishproj 156 | 157 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 158 | # checkin your Azure Web App publish settings, but sensitive information contained 159 | # in these scripts will be unencrypted 160 | PublishScripts/ 161 | 162 | # NuGet Packages 163 | *.nupkg 164 | # The packages folder can be ignored because of Package Restore 165 | **/packages/* 166 | # except build/, which is used as an MSBuild target. 167 | !**/packages/build/ 168 | # Uncomment if necessary however generally it will be regenerated when needed 169 | #!**/packages/repositories.config 170 | # NuGet v3's project.json files produces more ignoreable files 171 | *.nuget.props 172 | *.nuget.targets 173 | 174 | # Microsoft Azure Build Output 175 | csx/ 176 | *.build.csdef 177 | 178 | # Microsoft Azure Emulator 179 | ecf/ 180 | rcf/ 181 | 182 | # Windows Store app package directories and files 183 | AppPackages/ 184 | BundleArtifacts/ 185 | Package.StoreAssociation.xml 186 | _pkginfo.txt 187 | 188 | # Visual Studio cache files 189 | # files ending in .cache can be ignored 190 | *.[Cc]ache 191 | # but keep track of directories ending in .cache 192 | !*.[Cc]ache/ 193 | 194 | # Others 195 | ClientBin/ 196 | ~$* 197 | *~ 198 | *.dbmdl 199 | *.dbproj.schemaview 200 | *.jfm 201 | *.pfx 202 | *.publishsettings 203 | node_modules/ 204 | orleans.codegen.cs 205 | 206 | # Since there are multiple workflows, uncomment next line to ignore bower_components 207 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 208 | #bower_components/ 209 | 210 | # RIA/Silverlight projects 211 | Generated_Code/ 212 | 213 | # Backup & report files from converting an old project file 214 | # to a newer Visual Studio version. Backup files are not needed, 215 | # because we have git ;-) 216 | _UpgradeReport_Files/ 217 | Backup*/ 218 | UpgradeLog*.XML 219 | UpgradeLog*.htm 220 | 221 | # SQL Server files 222 | *.mdf 223 | *.ldf 224 | 225 | # Business Intelligence projects 226 | *.rdl.data 227 | *.bim.layout 228 | *.bim_*.settings 229 | 230 | # Microsoft Fakes 231 | FakesAssemblies/ 232 | 233 | # GhostDoc plugin setting file 234 | *.GhostDoc.xml 235 | 236 | # Node.js Tools for Visual Studio 237 | .ntvs_analysis.dat 238 | 239 | # Visual Studio 6 build log 240 | *.plg 241 | 242 | # Visual Studio 6 workspace options file 243 | *.opt 244 | 245 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 246 | *.vbw 247 | 248 | # Visual Studio LightSwitch build output 249 | **/*.HTMLClient/GeneratedArtifacts 250 | **/*.DesktopClient/GeneratedArtifacts 251 | **/*.DesktopClient/ModelManifest.xml 252 | **/*.Server/GeneratedArtifacts 253 | **/*.Server/ModelManifest.xml 254 | _Pvt_Extensions 255 | 256 | # Paket dependency manager 257 | .paket/paket.exe 258 | paket-files/ 259 | 260 | # FAKE - F# Make 261 | .fake/ 262 | 263 | # JetBrains Rider 264 | .idea/ 265 | *.sln.iml 266 | 267 | # CodeRush 268 | .cr/ 269 | 270 | # Python Tools for Visual Studio (PTVS) 271 | __pycache__/ 272 | *.pyc 273 | 274 | # Cake - Uncomment if you are using it 275 | # tools/ -------------------------------------------------------------------------------- /THSTrader/ClipboardHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Collections.ObjectModel; 5 | using System.Runtime.InteropServices; 6 | using System.IO; 7 | using System.Xml.Serialization; 8 | using System.Xml; 9 | 10 | namespace THSTrader 11 | { 12 | /// 13 | /// Manage the Clipboard backup 14 | /// 15 | 16 | public class ClipboardHelper 17 | { 18 | static ReadOnlyCollection mClipData = null; 19 | 20 | /// 21 | /// Remove all data from Clipboard 22 | /// 23 | /// 24 | public static bool EmptyClipboard() 25 | { 26 | return Win32ClipboardAPI.EmptyClipboard(); 27 | } 28 | 29 | /// 30 | /// Empty the Clipboard and Restore to system clipboard data contained in a collection of ClipData objects 31 | /// 32 | /// The collection of ClipData containing data stored from clipboard 33 | /// 34 | private static bool SetClipboard(ReadOnlyCollection clipData) 35 | { 36 | //Open clipboard to allow its manipulation 37 | if (!Win32ClipboardAPI.OpenClipboard(IntPtr.Zero)) 38 | return false; 39 | 40 | //Clear the clipboard 41 | EmptyClipboard(); 42 | 43 | //Get an Enumerator to iterate into each ClipData contained into the collection 44 | IEnumerator cData = clipData.GetEnumerator(); 45 | while(cData.MoveNext()) 46 | { 47 | DataClip cd = cData.Current; 48 | 49 | //Get the pointer for inserting the buffer data into the clipboard 50 | IntPtr alloc = Win32MemoryAPI.GlobalAlloc(Win32MemoryAPI.GMEM_MOVEABLE | Win32MemoryAPI.GMEM_DDESHARE, cd.Size); 51 | IntPtr gLock = Win32MemoryAPI.GlobalLock(alloc); 52 | 53 | //Copy the buffer of the ClipData into the clipboard 54 | if ((int)cd.Size>0) 55 | { 56 | Marshal.Copy(cd.Buffer, 0, gLock, cd.Buffer.GetLength(0)); 57 | } 58 | 59 | //Release pointers 60 | Win32MemoryAPI.GlobalUnlock(alloc); 61 | Win32ClipboardAPI.SetClipboardData(cd.Format, alloc); 62 | }; 63 | 64 | //Close the clipboard to release unused resources 65 | Win32ClipboardAPI.CloseClipboard(); 66 | return true; 67 | } 68 | 69 | 70 | /// 71 | /// Get data from clipboard and save it to Hard Disk 72 | /// 73 | /// The name of the file 74 | public static void Save() 75 | { 76 | mClipData = GetClipboard(); 77 | } 78 | 79 | /// 80 | /// Get data from hard disk and put them into the clipboard 81 | /// 82 | /// 83 | /// 84 | public static bool Restore() 85 | { 86 | return SetClipboard(mClipData); 87 | } 88 | 89 | /// 90 | /// Convert to a DataClip collection all data present in the clipboard 91 | /// 92 | /// 93 | private static ReadOnlyCollection GetClipboard() 94 | { 95 | //Init a list of ClipData, which will contain each Clipboard Data 96 | List clipData = new List(); 97 | 98 | //Open Clipboard to allow us to read from it 99 | if (!Win32ClipboardAPI.OpenClipboard(IntPtr.Zero)) 100 | return new ReadOnlyCollection(clipData); 101 | 102 | //Loop for each clipboard data type 103 | uint format = 0; 104 | while ((format = Win32ClipboardAPI.EnumClipboardFormats(format)) != 0) 105 | { 106 | //Check if clipboard data type is recognized, and get its name 107 | string formatName = "0"; 108 | DataClip cd; 109 | if (format > 14) 110 | { 111 | StringBuilder res = new StringBuilder(); 112 | if (Win32ClipboardAPI.GetClipboardFormatName(format, res, 100) > 0) 113 | { 114 | formatName = res.ToString(); 115 | } 116 | 117 | } 118 | //Get the pointer for the current Clipboard Data 119 | IntPtr pos = Win32ClipboardAPI.GetClipboardData(format); 120 | //Goto next if it's unreachable 121 | if (pos == IntPtr.Zero) 122 | continue; 123 | //Get the clipboard buffer data properties 124 | UIntPtr lenght = Win32MemoryAPI.GlobalSize(pos); 125 | IntPtr gLock = Win32MemoryAPI.GlobalLock(pos); 126 | byte[] buffer; 127 | if ((int)lenght > 0) 128 | { 129 | //Init a buffer which will contain the clipboard data 130 | buffer = new byte[(int)lenght]; 131 | int l = Convert.ToInt32(lenght.ToString()); 132 | //Copy data from clipboard to our byte[] buffer 133 | Marshal.Copy(gLock, buffer, 0, l); 134 | } 135 | else 136 | { 137 | buffer = new byte[0]; 138 | } 139 | //Create a ClipData object that represtens current clipboard data 140 | cd = new DataClip(format, formatName, buffer); 141 | cd.FormatName = formatName; 142 | //Add current Clipboard Data to the list 143 | 144 | 145 | clipData.Add(cd); 146 | } 147 | 148 | //Close the clipboard and realese unused resources 149 | Win32ClipboardAPI.CloseClipboard(); 150 | //Returns the list of Clipboard Datas as a ReadOnlyCollection of ClipData 151 | return new ReadOnlyCollection(clipData); 152 | } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /THSTrader/Utility.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.InteropServices; 3 | using System.Text; 4 | using System.Collections.Generic; 5 | 6 | namespace THSTrader 7 | { 8 | public enum SendMessageTimeoutFlags : uint 9 | { 10 | SMTO_NORMAL = 0x0, 11 | SMTO_BLOCK = 0x1, 12 | SMTO_ABORTIFHUNG = 0x2, 13 | SMTO_NOTIMEOUTIFNOTHUNG = 0x8, 14 | SMTO_ERRORONEXIT = 0x20 15 | } 16 | 17 | public class Utility 18 | { 19 | #region const 20 | public const int timeout = 30000; 21 | 22 | //Windows 使用的256个虚拟键码 23 | public const int VK_LBUTTON = 0x1; 24 | public const int VK_RBUTTON = 0x2; 25 | public const int VK_CANCEL = 0x3; 26 | public const int VK_MBUTTON = 0x4; 27 | public const int VK_BACK = 0x8; 28 | public const int VK_TAB = 0x9; 29 | public const int VK_CLEAR = 0xC; 30 | public const int VK_RETURN = 0xD; 31 | public const int VK_SHIFT = 0x10; 32 | public const int VK_CONTROL = 0x11; 33 | public const int VK_MENU = 0x12; 34 | public const int VK_PAUSE = 0x13; 35 | public const int VK_CAPITAL = 0x14; 36 | public const int VK_ESCAPE = 0x1B; 37 | public const int VK_SPACE = 0x20; 38 | public const int VK_PRIOR = 0x21; 39 | public const int VK_NEXT = 0x22; 40 | public const int VK_END = 0x23; 41 | public const int VK_HOME = 0x24; 42 | public const int VK_LEFT = 0x25; 43 | public const int VK_UP = 0x26; 44 | public const int VK_RIGHT = 0x27; 45 | public const int VK_DOWN = 0x28; 46 | public const int VK_Select = 0x29; 47 | public const int VK_PRINT = 0x2A; 48 | public const int VK_EXECUTE = 0x2B; 49 | public const int VK_SNAPSHOT = 0x2C; 50 | public const int VK_Insert = 0x2D; 51 | public const int VK_Delete = 0x2E; 52 | public const int VK_HELP = 0x2F; 53 | public const int VK_0 = 0x30; 54 | public const int VK_1 = 0x31; 55 | public const int VK_2 = 0x32; 56 | public const int VK_3 = 0x33; 57 | public const int VK_4 = 0x34; 58 | public const int VK_5 = 0x35; 59 | public const int VK_6 = 0x36; 60 | public const int VK_7 = 0x37; 61 | public const int VK_8 = 0x38; 62 | public const int VK_9 = 0x39; 63 | public const int VK_A = 0x41; 64 | public const int VK_B = 0x42; 65 | public const int VK_C = 0x43; 66 | public const int VK_D = 0x44; 67 | public const int VK_E = 0x45; 68 | public const int VK_F = 0x46; 69 | public const int VK_G = 0x47; 70 | public const int VK_H = 0x48; 71 | public const int VK_I = 0x49; 72 | public const int VK_J = 0x4A; 73 | public const int VK_K = 0x4B; 74 | public const int VK_L = 0x4C; 75 | public const int VK_M = 0x4D; 76 | public const int VK_N = 0x4E; 77 | public const int VK_O = 0x4F; 78 | public const int VK_P = 0x50; 79 | public const int VK_Q = 0x51; 80 | public const int VK_R = 0x52; 81 | public const int VK_S = 0x53; 82 | public const int VK_T = 0x54; 83 | public const int VK_U = 0x55; 84 | public const int VK_V = 0x56; 85 | public const int VK_W = 0x57; 86 | public const int VK_X = 0x58; 87 | public const int VK_Y = 0x59; 88 | public const int VK_Z = 0x5A; 89 | public const int VK_STARTKEY = 0x5B; 90 | public const int VK_CONTEXTKEY = 0x5D; 91 | public const int VK_NUMPAD0 = 0x60; 92 | public const int VK_NUMPAD1 = 0x61; 93 | public const int VK_NUMPAD2 = 0x62; 94 | public const int VK_NUMPAD3 = 0x63; 95 | public const int VK_NUMPAD4 = 0x64; 96 | public const int VK_NUMPAD5 = 0x65; 97 | public const int VK_NUMPAD6 = 0x66; 98 | public const int VK_NUMPAD7 = 0x67; 99 | public const int VK_NUMPAD8 = 0x68; 100 | public const int VK_NUMPAD9 = 0x69; 101 | public const int VK_MULTIPLY = 0x6A; 102 | public const int VK_ADD = 0x6B; 103 | public const int VK_SEPARATOR = 0x6C; 104 | public const int VK_SUBTRACT = 0x6D; 105 | public const int VK_DECIMAL = 0x6E; 106 | public const int VK_DIVIDE = 0x6F; 107 | public const int VK_F1 = 0x70; 108 | public const int VK_F2 = 0x71; 109 | public const int VK_F3 = 0x72; 110 | public const int VK_F4 = 0x73; 111 | public const int VK_F5 = 0x74; 112 | public const int VK_F6 = 0x75; 113 | public const int VK_F7 = 0x76; 114 | public const int VK_F8 = 0x77; 115 | public const int VK_F9 = 0x78; 116 | public const int VK_F10 = 0x79; 117 | public const int VK_F11 = 0x7A; 118 | public const int VK_F12 = 0x7B; 119 | public const int VK_F13 = 0x7C; 120 | public const int VK_F14 = 0x7D; 121 | public const int VK_F15 = 0x7E; 122 | public const int VK_F16 = 0x7F; 123 | public const int VK_F17 = 0x80; 124 | public const int VK_F18 = 0x81; 125 | public const int VK_F19 = 0x82; 126 | public const int VK_F20 = 0x83; 127 | public const int VK_F21 = 0x84; 128 | public const int VK_F22 = 0x85; 129 | public const int VK_F23 = 0x86; 130 | public const int VK_F24 = 0x87; 131 | public const int VK_NUMLOCK = 0x90; 132 | public const int VK_OEM_SCROLL = 0x91; 133 | public const int VK_OEM_1 = 0xBA; 134 | public const int VK_OEM_PLUS = 0xBB; 135 | public const int VK_OEM_COMMA = 0xBC; 136 | public const int VK_OEM_MINUS = 0xBD; 137 | public const int VK_OEM_PERIOD = 0xBE; 138 | public const int VK_OEM_2 = 0xBF; 139 | public const int VK_OEM_3 = 0xC0; 140 | public const int VK_OEM_4 = 0xDB; 141 | public const int VK_OEM_5 = 0xDC; 142 | public const int VK_OEM_6 = 0xDD; 143 | public const int VK_OEM_7 = 0xDE; 144 | public const int VK_OEM_8 = 0xDF; 145 | public const int VK_ICO_F17 = 0xE0; 146 | public const int VK_ICO_F18 = 0xE1; 147 | public const int VK_OEM102 = 0xE2; 148 | public const int VK_ICO_HELP = 0xE3; 149 | public const int VK_ICO_00 = 0xE4; 150 | public const int VK_ICO_CLEAR = 0xE6; 151 | public const int VK_OEM_RESET = 0xE9; 152 | public const int VK_OEM_JUMP = 0xEA; 153 | public const int VK_OEM_PA1 = 0xEB; 154 | public const int VK_OEM_PA2 = 0xEC; 155 | public const int VK_OEM_PA3 = 0xED; 156 | public const int VK_OEM_WSCTRL = 0xEE; 157 | public const int VK_OEM_CUSEL = 0xEF; 158 | public const int VK_OEM_ATTN = 0xF0; 159 | public const int VK_OEM_FINNISH = 0xF1; 160 | public const int VK_OEM_COPY = 0xF2; 161 | public const int VK_OEM_AUTO = 0xF3; 162 | public const int VK_OEM_ENLW = 0xF4; 163 | public const int VK_OEM_BACKTAB = 0xF5; 164 | public const int VK_ATTN = 0xF6; 165 | public const int VK_CRSEL = 0xF7; 166 | public const int VK_EXSEL = 0xF8; 167 | public const int VK_EREOF = 0xF9; 168 | public const int VK_PLAY = 0xFA; 169 | public const int VK_ZOOM = 0xFB; 170 | public const int VK_NONAME = 0xFC; 171 | public const int VK_PA1 = 0xFD; 172 | public const int VK_OEM_CLEAR = 0xFE; 173 | 174 | 175 | //创建一个窗口 176 | public const int WM_CREATE = 0x01; 177 | 178 | //当一个窗口被破坏时发送 179 | public const int WM_DESTROY = 0x02; 180 | 181 | //移动一个窗口 182 | public const int WM_MOVE = 0x03; 183 | 184 | //改变一个窗口的大小 185 | public const int WM_SIZE = 0x05; 186 | 187 | //一个窗口被激活或失去激活状态 188 | public const int WM_ACTIVATE = 0x06; 189 | 190 | //一个窗口获得焦点 191 | public const int WM_SETFOCUS = 0x07; 192 | 193 | //一个窗口失去焦点 194 | public const int WM_KILLFOCUS = 0x08; 195 | 196 | //一个窗口改变成Enable状态 197 | public const int WM_ENABLE = 0x0A; 198 | 199 | //设置窗口是否能重画 200 | public const int WM_SETREDRAW = 0x0B; 201 | 202 | //应用程序发送此消息来设置一个窗口的文本 203 | public const int WM_SETTEXT = 0x0C; 204 | 205 | //应用程序发送此消息来复制对应窗口的文本到缓冲区 206 | public const int WM_GETTEXT = 0x0D; 207 | 208 | //得到与一个窗口有关的文本的长度(不包含空字符) 209 | public const int WM_GETTEXTLENGTH = 0x0E; 210 | 211 | //要求一个窗口重画自己 212 | public const int WM_PAINT = 0x0F; 213 | 214 | //当一个窗口或应用程序要关闭时发送一个信号 215 | public const int WM_CLOSE = 0x10; 216 | 217 | //当用户选择结束对话框或程序自己调用ExitWindows函数 218 | public const int WM_QUERYENDSESSION = 0x11; 219 | 220 | //用来结束程序运行 221 | public const int WM_QUIT = 0x12; 222 | 223 | //当用户窗口恢复以前的大小位置时,把此消息发送给某个图标 224 | public const int WM_QUERYOPEN = 0x13; 225 | 226 | //当窗口背景必须被擦除时(例在窗口改变大小时) 227 | public const int WM_ERASEBKGND = 0x14; 228 | 229 | //当系统颜色改变时,发送此消息给所有顶级窗口 230 | public const int WM_SYSCOLORCHANGE = 0x15; 231 | 232 | //当系统进程发出WM_QUERYENDSESSION消息后,此消息发送给应用程序,通知它对话是否结束 233 | public const int WM_ENDSESSION = 0x16; 234 | 235 | //当隐藏或显示窗口是发送此消息给这个窗口 236 | public const int WM_SHOWWINDOW = 0x18; 237 | 238 | //发此消息给应用程序哪个窗口是激活的,哪个是非激活的 239 | public const int WM_ACTIVATEAPP = 0x1C; 240 | 241 | //当系统的字体资源库变化时发送此消息给所有顶级窗口 242 | public const int WM_FONTCHANGE = 0x1D; 243 | 244 | //当系统的时间变化时发送此消息给所有顶级窗口 245 | public const int WM_TIMECHANGE = 0x1E; 246 | 247 | //发送此消息来取消某种正在进行的摸态(操作) 248 | public const int WM_CANCELMODE = 0x1F; 249 | 250 | //如果鼠标引起光标在某个窗口中移动且鼠标输入没有被捕获时,就发消息给某个窗口 251 | public const int WM_SETCURSOR = 0x20; 252 | 253 | //当光标在某个非激活的窗口中而用户正按着鼠标的某个键发送此消息给//当前窗口 254 | public const int WM_MOUSEACTIVATE = 0x21; 255 | 256 | //发送此消息给MDI子窗口//当用户点击此窗口的标题栏,或//当窗口被激活,移动,改变大小 257 | public const int WM_CHILDACTIVATE = 0x22; 258 | 259 | //此消息由基于计算机的训练程序发送,通过WH_JOURNALPALYBACK的hook程序分离出用户输入消息 260 | public const int WM_QUEUESYNC = 0x23; 261 | 262 | //此消息发送给窗口当它将要改变大小或位置 263 | public const int WM_GETMINMAXINFO = 0x24; 264 | 265 | //发送给最小化窗口当它图标将要被重画 266 | public const int WM_PAINTICON = 0x26; 267 | 268 | //此消息发送给某个最小化窗口,仅//当它在画图标前它的背景必须被重画 269 | public const int WM_ICONERASEBKGND = 0x27; 270 | 271 | //发送此消息给一个对话框程序去更改焦点位置 272 | public const int WM_NEXTDLGCTL = 0x28; 273 | 274 | //每当打印管理列队增加或减少一条作业时发出此消息 275 | public const int WM_SPOOLERSTATUS = 0x2A; 276 | 277 | //当button,combobox,listbox,menu的可视外观改变时发送 278 | public const int WM_DRAWITEM = 0x2B; 279 | 280 | //当button, combo box, list box, list view control, or menu item 被创建时 281 | public const int WM_MEASUREITEM = 0x2C; 282 | 283 | //此消息有一个LBS_WANTKEYBOARDINPUT风格的发出给它的所有者来响应WM_KEYDOWN消息 284 | public const int WM_VKEYTOITEM = 0x2E; 285 | 286 | //此消息由一个LBS_WANTKEYBOARDINPUT风格的列表框发送给他的所有者来响应WM_CHAR消息 287 | public const int WM_CHARTOITEM = 0x2F; 288 | 289 | //当绘制文本时程序发送此消息得到控件要用的颜色 290 | public const int WM_SETFONT = 0x30; 291 | 292 | //应用程序发送此消息得到当前控件绘制文本的字体 293 | public const int WM_GETFONT = 0x31; 294 | 295 | //应用程序发送此消息让一个窗口与一个热键相关连 296 | public const int WM_SETHOTKEY = 0x32; 297 | 298 | //应用程序发送此消息来判断热键与某个窗口是否有关联 299 | public const int WM_GETHOTKEY = 0x33; 300 | 301 | //此消息发送给最小化窗口,当此窗口将要被拖放而它的类中没有定义图标,应用程序能返回一个图标或光标的句柄,当用户拖放图标时系统显示这个图标或光标 302 | public const int WM_QUERYDRAGICON = 0x37; 303 | 304 | //发送此消息来判定combobox或listbox新增加的项的相对位置 305 | public const int WM_COMPAREITEM = 0x39; 306 | 307 | //显示内存已经很少了 308 | public const int WM_COMPACTING = 0x41; 309 | 310 | //发送此消息给那个窗口的大小和位置将要被改变时,来调用setwindowpos函数或其它窗口管理函数 311 | public const int WM_WINDOWPOSCHANGING = 0x46; 312 | 313 | //发送此消息给那个窗口的大小和位置已经被改变时,来调用setwindowpos函数或其它窗口管理函数 314 | public const int WM_WINDOWPOSCHANGED = 0x47; 315 | 316 | //当系统将要进入暂停状态时发送此消息 317 | public const int WM_POWER = 0x48; 318 | 319 | //当一个应用程序传递数据给另一个应用程序时发送此消息 320 | public const int WM_COPYDATA = 0x4A; 321 | 322 | //当某个用户取消程序日志激活状态,提交此消息给程序 323 | public const int WM_CANCELJOURNA = 0x4B; 324 | 325 | //当某个控件的某个事件已经发生或这个控件需要得到一些信息时,发送此消息给它的父窗口 326 | public const int WM_NOTIFY = 0x4E; 327 | 328 | //当用户选择某种输入语言,或输入语言的热键改变 329 | public const int WM_INPUTLANGCHANGEREQUEST = 0x50; 330 | 331 | //当平台现场已经被改变后发送此消息给受影响的最顶级窗口 332 | public const int WM_INPUTLANGCHANGE = 0x51; 333 | 334 | //当程序已经初始化windows帮助例程时发送此消息给应用程序 335 | public const int WM_TCARD = 0x52; 336 | 337 | //此消息显示用户按下了F1,如果某个菜单是激活的,就发送此消息个此窗口关联的菜单,否则就发送给有焦点的窗口,如果//当前都没有焦点,就把此消息发送给//当前激活的窗口 338 | public const int WM_HELP = 0x53; 339 | 340 | //当用户已经登入或退出后发送此消息给所有的窗口,//当用户登入或退出时系统更新用户的具体设置信息,在用户更新设置时系统马上发送此消息 341 | public const int WM_USERCHANGED = 0x54; 342 | 343 | //公用控件,自定义控件和他们的父窗口通过此消息来判断控件是使用ANSI还是UNICODE结构 344 | public const int WM_NOTIFYFORMAT = 0x55; 345 | 346 | //当用户某个窗口中点击了一下右键就发送此消息给这个窗口 347 | //public const int WM_CONTEXTMENU = ??; 348 | //当调用SETWINDOWLONG函数将要改变一个或多个 窗口的风格时发送此消息给那个窗口 349 | public const int WM_STYLECHANGING = 0x7C; 350 | 351 | //当调用SETWINDOWLONG函数一个或多个 窗口的风格后发送此消息给那个窗口 352 | public const int WM_STYLECHANGED = 0x7D; 353 | 354 | //当显示器的分辨率改变后发送此消息给所有的窗口 355 | public const int WM_DISPLAYCHANGE = 0x7E; 356 | 357 | //此消息发送给某个窗口来返回与某个窗口有关连的大图标或小图标的句柄 358 | public const int WM_GETICON = 0x7F; 359 | 360 | //程序发送此消息让一个新的大图标或小图标与某个窗口关联 361 | public const int WM_SETICON = 0x80; 362 | 363 | //当某个窗口第一次被创建时,此消息在WM_CREATE消息发送前发送 364 | public const int WM_NCCREATE = 0x81; 365 | 366 | //此消息通知某个窗口,非客户区正在销毁 367 | public const int WM_NCDESTROY = 0x82; 368 | 369 | //当某个窗口的客户区域必须被核算时发送此消息 370 | public const int WM_NCCALCSIZE = 0x83; 371 | 372 | //移动鼠标,按住或释放鼠标时发生 373 | public const int WM_NCHITTEST = 0x84; 374 | 375 | //程序发送此消息给某个窗口当它(窗口)的框架必须被绘制时 376 | public const int WM_NCPAINT = 0x85; 377 | 378 | //此消息发送给某个窗口仅当它的非客户区需要被改变来显示是激活还是非激活状态 379 | public const int WM_NCACTIVATE = 0x86; 380 | 381 | //发送此消息给某个与对话框程序关联的控件,widdows控制方位键和TAB键使输入进入此控件通过应 382 | public const int WM_GETDLGCODE = 0x87; 383 | 384 | //当光标在一个窗口的非客户区内移动时发送此消息给这个窗口 非客户区为:窗体的标题栏及窗 的边框体 385 | public const int WM_NCMOUSEMOVE = 0xA0; 386 | 387 | //当光标在一个窗口的非客户区同时按下鼠标左键时提交此消息 388 | public const int WM_NCLBUTTONDOWN = 0xA1; 389 | 390 | //当用户释放鼠标左键同时光标某个窗口在非客户区十发送此消息 391 | public const int WM_NCLBUTTONUP = 0xA2; 392 | 393 | //当用户双击鼠标左键同时光标某个窗口在非客户区十发送此消息 394 | public const int WM_NCLBUTTONDBLCLK = 0xA3; 395 | 396 | //当用户按下鼠标右键同时光标又在窗口的非客户区时发送此消息 397 | public const int WM_NCRBUTTONDOWN = 0xA4; 398 | 399 | //当用户释放鼠标右键同时光标又在窗口的非客户区时发送此消息 400 | public const int WM_NCRBUTTONUP = 0xA5; 401 | 402 | //当用户双击鼠标右键同时光标某个窗口在非客户区十发送此消息 403 | public const int WM_NCRBUTTONDBLCLK = 0xA6; 404 | 405 | //当用户按下鼠标中键同时光标又在窗口的非客户区时发送此消息 406 | public const int WM_NCMBUTTONDOWN = 0xA7; 407 | 408 | //当用户释放鼠标中键同时光标又在窗口的非客户区时发送此消息 409 | public const int WM_NCMBUTTONUP = 0xA8; 410 | 411 | //当用户双击鼠标中键同时光标又在窗口的非客户区时发送此消息 412 | public const int WM_NCMBUTTONDBLCLK = 0xA9; 413 | 414 | public const int WM_CLICK = 0xF5; 415 | 416 | //WM_KEYDOWN 按下一个键 417 | public const int WM_KEYDOWN = 0x0100; 418 | 419 | //释放一个键 420 | public const int WM_KEYUP = 0x0101; 421 | 422 | //按下某键,并已发出WM_KEYDOWN, WM_KEYUP消息 423 | public const int WM_CHAR = 0x102; 424 | 425 | //当用translatemessage函数翻译WM_KEYUP消息时发送此消息给拥有焦点的窗口 426 | public const int WM_DEADCHAR = 0x103; 427 | 428 | //当用户按住ALT键同时按下其它键时提交此消息给拥有焦点的窗口 429 | public const int WM_SYSKEYDOWN = 0x104; 430 | 431 | //当用户释放一个键同时ALT 键还按着时提交此消息给拥有焦点的窗口 432 | public const int WM_SYSKEYUP = 0x105; 433 | 434 | //当WM_SYSKEYDOWN消息被TRANSLATEMESSAGE函数翻译后提交此消息给拥有焦点的窗口 435 | public const int WM_SYSCHAR = 0x106; 436 | 437 | //当WM_SYSKEYDOWN消息被TRANSLATEMESSAGE函数翻译后发送此消息给拥有焦点的窗口 438 | public const int WM_SYSDEADCHAR = 0x107; 439 | 440 | //在一个对话框程序被显示前发送此消息给它,通常用此消息初始化控件和执行其它任务 441 | public const int WM_INITDIALOG = 0x110; 442 | 443 | //当用户选择一条菜单命令项或当某个控件发送一条消息给它的父窗口,一个快捷键被翻译 444 | public const int WM_COMMAND = 0x111; 445 | 446 | //当用户选择窗口菜单的一条命令或//当用户选择最大化或最小化时那个窗口会收到此消息 447 | public const int WM_SYSCOMMAND = 0x112; 448 | 449 | //发生了定时器事件 450 | public const int WM_TIMER = 0x113; 451 | 452 | //当一个窗口标准水平滚动条产生一个滚动事件时发送此消息给那个窗口,也发送给拥有它的控件 453 | public const int WM_HSCROLL = 0x114; 454 | 455 | //当一个窗口标准垂直滚动条产生一个滚动事件时发送此消息给那个窗口也,发送给拥有它的控件 456 | public const int WM_VSCROLL = 0x115; 457 | 458 | //当一个菜单将要被激活时发送此消息,它发生在用户菜单条中的某项或按下某个菜单键,它允许程序在显示前更改菜单 459 | public const int WM_INITMENU = 0x116; 460 | 461 | //当一个下拉菜单或子菜单将要被激活时发送此消息,它允许程序在它显示前更改菜单,而不要改变全部 462 | public const int WM_INITMENUPOPUP = 0x117; 463 | 464 | //当用户选择一条菜单项时发送此消息给菜单的所有者(一般是窗口) 465 | public const int WM_MENUSELECT = 0x11F; 466 | 467 | //当菜单已被激活用户按下了某个键(不同于加速键),发送此消息给菜单的所有者 468 | public const int WM_MENUCHAR = 0x120; 469 | 470 | //当一个模态对话框或菜单进入空载状态时发送此消息给它的所有者,一个模态对话框或菜单进入空载状态就是在处理完一条或几条先前的消息后没有消息它的列队中等待 471 | public const int WM_ENTERIDLE = 0x121; 472 | 473 | //在windows绘制消息框前发送此消息给消息框的所有者窗口,通过响应这条消息,所有者窗口可以通过使用给定的相关显示设备的句柄来设置消息框的文本和背景颜色 474 | public const int WM_CTLCOLORMSGBOX = 0x132; 475 | 476 | //当一个编辑型控件将要被绘制时发送此消息给它的父窗口通过响应这条消息,所有者窗口可以通过使用给定的相关显示设备的句柄来设置编辑框的文本和背景颜色 477 | public const int WM_CTLCOLOREDIT = 0x133; 478 | 479 | //当一个列表框控件将要被绘制前发送此消息给它的父窗口通过响应这条消息,所有者窗口可以通过使用给定的相关显示设备的句柄来设置列表框的文本和背景颜色 480 | public const int WM_CTLCOLORLISTBOX = 0x134; 481 | 482 | //当一个按钮控件将要被绘制时发送此消息给它的父窗口通过响应这条消息,所有者窗口可以通过使用给定的相关显示设备的句柄来设置按纽的文本和背景颜色 483 | public const int WM_CTLCOLORBTN = 0x135; 484 | 485 | //当一个对话框控件将要被绘制前发送此消息给它的父窗口通过响应这条消息,所有者窗口可以通过使用给定的相关显示设备的句柄来设置对话框的文本背景颜色 486 | public const int WM_CTLCOLORDLG = 0x136; 487 | 488 | //当一个滚动条控件将要被绘制时发送此消息给它的父窗口通过响应这条消息,所有者窗口可以通过使用给定的相关显示设备的句柄来设置滚动条的背景颜色 489 | public const int WM_CTLCOLORSCROLLBAR = 0x137; 490 | 491 | //当一个静态控件将要被绘制时发送此消息给它的父窗口通过响应这条消息,所有者窗口可以 通过使用给定的相关显示设备的句柄来设置静态控件的文本和背景颜色 492 | public const int WM_CTLCOLORSTATIC = 0x138; 493 | 494 | //当鼠标轮子转动时发送此消息个当前有焦点的控件 495 | public const int WM_MOUSEWHEEL = 0x20A; 496 | 497 | //双击鼠标中键 498 | public const int WM_MBUTTONDBLCLK = 0x209; 499 | 500 | //释放鼠标中键 501 | public const int WM_MBUTTONUP = 0x208; 502 | 503 | //移动鼠标时发生,同WM_MOUSEFIRST 504 | public const int WM_MOUSEMOVE = 0x200; 505 | 506 | //按下鼠标左键 507 | public const int WM_LBUTTONDOWN = 0x201; 508 | 509 | //释放鼠标左键 510 | public const int WM_LBUTTONUP = 0x202; 511 | 512 | //双击鼠标左键 513 | public const int WM_LBUTTONDBLCLK = 0x203; 514 | 515 | //按下鼠标右键 516 | public const int WM_RBUTTONDOWN = 0x204; 517 | 518 | //释放鼠标右键 519 | public const int WM_RBUTTONUP = 0x205; 520 | 521 | //双击鼠标右键 522 | public const int WM_RBUTTONDBLCLK = 0x206; 523 | 524 | //按下鼠标中键 525 | public const int WM_MBUTTONDOWN = 0x207; 526 | 527 | public const int WM_USER = 0x0400; 528 | 529 | public const int MK_LBUTTON = 0x0001; 530 | 531 | public const int MK_RBUTTON = 0x0002; 532 | 533 | public const int MK_SHIFT = 0x0004; 534 | 535 | public const int MK_CONTROL = 0x0008; 536 | 537 | public const int MK_MBUTTON = 0x0010; 538 | 539 | public const int MK_XBUTTON1 = 0x0020; 540 | 541 | public const int MK_XBUTTON2 = 0x0040; 542 | 543 | private const int GW_HWNDFIRST = 0; 544 | private const int GW_HWNDNEXT = 2; 545 | private const int GWL_STYLE = (-16); 546 | private const int WS_VISIBLE = 268435456; 547 | private const int WS_BORDER = 8388608; 548 | 549 | #endregion 550 | 551 | //API回调函数(在c#中,一个委托实例代表一个函数的指针(入口地址)) 552 | public delegate bool WNDENUMPROC(int hwnd, int lParam); 553 | 554 | #region tools 555 | //static public string getCode(string strCode) 556 | //{ 557 | // if (strCode.Length == 0) 558 | // return "000001"; 559 | 560 | // strCode = strCode.ToLower(); 561 | 562 | // if (strCode.Length > 6) 563 | // return strCode; 564 | 565 | // else if (strCode.Substring(0, 1) == "0") 566 | // strCode = "sz" + strCode; 567 | // else if (strCode.Substring(0, 1) == "6" || strCode.Substring(0, 1) == "5") 568 | // strCode = "sh" + strCode; 569 | // else 570 | // strCode = "sz" + strCode; 571 | 572 | // return strCode; 573 | //} 574 | 575 | static public string getItemText(int hWnd) 576 | { 577 | int result = 0; 578 | StringBuilder stringBuilder = new StringBuilder(256); 579 | Utility.SendMessageTimeoutText(hWnd, Utility.WM_GETTEXT, 256, stringBuilder, SendMessageTimeoutFlags.SMTO_BLOCK, timeout, out result); 580 | string strCaption = stringBuilder.ToString(); 581 | return strCaption; 582 | } 583 | #endregion 584 | 585 | 586 | #region P/Invoke USER32 587 | 588 | [StructLayout(LayoutKind.Sequential)] 589 | public struct RECT 590 | { 591 | public RECT(int _left, int _top, int _right, int _bottom) 592 | { 593 | Left = _left; 594 | Top = _top; 595 | Right = _right; 596 | Bottom = _bottom; 597 | } 598 | public int Left; 599 | public int Top; 600 | public int Right; 601 | public int Bottom; 602 | } 603 | 604 | //Declare wrapper managed POINT class. 605 | [StructLayout(LayoutKind.Sequential)] 606 | public struct POINT 607 | { 608 | public POINT(int _x, int _y) 609 | { 610 | X = _x; 611 | Y = _y; 612 | } 613 | public int X; 614 | public int Y; 615 | } 616 | 617 | [StructLayout(LayoutKind.Sequential)] 618 | public struct PAINTSTRUCT 619 | { 620 | public int hdc; 621 | public bool fErase; 622 | public RECT rcPaint; 623 | public bool fRestore; 624 | public bool fIncUpdate; 625 | public byte[] rgbReserved; 626 | } 627 | 628 | [StructLayout(LayoutKind.Sequential)] 629 | public struct LOGPEN 630 | { 631 | public uint lopnStyle; 632 | POINT lopnWidth; 633 | int lopnColor; 634 | } 635 | 636 | /// 637 | /// 判断一个点是否位于矩形内 638 | /// 639 | /// 640 | /// 641 | /// 642 | [DllImport("user32")] 643 | public static extern bool PtInRect( 644 | ref RECT lprc, 645 | POINT pt 646 | ); 647 | 648 | [DllImport("user32", EntryPoint = "SetParent")] 649 | public static extern int SetParent( 650 | IntPtr hwndChild, 651 | int hwndNewParent 652 | ); 653 | 654 | [DllImport("user32", EntryPoint = "FindWindowA")] 655 | public static extern int FindWindow( 656 | string lpClassName, 657 | string lpWindowName 658 | ); 659 | 660 | [DllImport("user32", EntryPoint = "FindWindowExA")] 661 | public static extern int FindWindowEx( 662 | int hwndParent, 663 | int hwndChildAfter, 664 | string lpszClass, //窗口类 665 | string lpszWindow //窗口标题 666 | ); 667 | 668 | public static List FindWindowRe( 669 | int hwndParent, 670 | int hwndChildAfter, 671 | string lpszClass, //窗口类 672 | string lpszWindow, //窗口标题 673 | int depth 674 | ) 675 | { 676 | List rets = new List(); 677 | if (depth == 0) 678 | return rets; 679 | 680 | int handle = FindWindowEx(hwndParent, hwndChildAfter, lpszClass, lpszWindow); 681 | if (handle > 0) 682 | { 683 | rets.Add(handle); 684 | rets.AddRange(FindWindowRe(hwndParent, handle, lpszClass, lpszWindow, depth)); 685 | } 686 | else 687 | { 688 | int ch = FindWindowEx(hwndParent, 0, null, null); 689 | while (ch > 0) 690 | { 691 | rets.AddRange(FindWindowRe(ch, 0, lpszClass, lpszWindow, depth - 1)); 692 | ch = FindWindowEx(hwndParent, ch, null, null); 693 | } 694 | } 695 | 696 | return rets; 697 | } 698 | public static int FindWindowVisibleEx( 699 | int hwndParent, 700 | int hwndChildAfter, 701 | string lpszClass, //窗口类 702 | string lpszWindow //窗口标题 703 | ) 704 | { 705 | while ((hwndChildAfter = FindWindowEx(hwndParent, hwndChildAfter, lpszClass, lpszWindow)) > 0) 706 | { 707 | uint result = GetWindowLong(new IntPtr(hwndChildAfter), GWL_STYLE); 708 | if ((result & WS_VISIBLE) != 0) 709 | return hwndChildAfter; 710 | } 711 | 712 | return 0; 713 | } 714 | 715 | [DllImport("user32.dll", EntryPoint = "SendMessage")] 716 | public static extern int SendMessage( 717 | int hWnd, 718 | int wMsg, 719 | int wParam, 720 | IntPtr lParam 721 | ); 722 | 723 | [DllImport("user32.dll", EntryPoint = "SendMessage")] 724 | public static extern int SendMessage( 725 | int hWnd, 726 | int wMsg, 727 | int wParam, 728 | uint lParam 729 | ); 730 | 731 | [DllImport("user32.dll", EntryPoint = "SendMessageA")] 732 | public static extern int SendMessage( 733 | int hWnd, 734 | int wMsg, 735 | int wParam, 736 | string lParam 737 | ); 738 | 739 | [DllImport("user32.dll", EntryPoint = "SendMessageA")] 740 | public static extern int SendMessage( 741 | int hWnd, 742 | int wMsg, 743 | int wParam, 744 | StringBuilder lParam 745 | ); 746 | 747 | 748 | [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] 749 | public static extern int SendMessageTimeout( 750 | int hWnd, 751 | uint Msg, 752 | int wParam, 753 | string lParam, 754 | SendMessageTimeoutFlags fuFlags, 755 | uint timeout, 756 | out int result); 757 | 758 | [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] 759 | public static extern int SendMessageTimeout( 760 | int windowHandle, 761 | uint Msg, 762 | int wParam, 763 | int lParam, 764 | SendMessageTimeoutFlags flags, 765 | uint timeout, 766 | out int result); 767 | 768 | /* Version specifically setup for use with WM_GETTEXT message */ 769 | 770 | [DllImport("user32.dll", EntryPoint = "SendMessageTimeout", SetLastError = true, CharSet = CharSet.Auto)] 771 | public static extern uint SendMessageTimeoutText( 772 | int hWnd, 773 | int Msg, // Use WM_GETTEXT 774 | int countOfChars, 775 | StringBuilder text, 776 | SendMessageTimeoutFlags flags, 777 | uint uTImeoutj, 778 | out int result); 779 | 780 | /* Version for a message which returns an int, such as WM_GETTEXTLENGTH. */ 781 | 782 | [DllImport("user32.dll", EntryPoint = "SendMessageTimeout", CharSet = CharSet.Auto)] 783 | public static extern int SendMessageTimeout( 784 | int hwnd, 785 | uint Msg, 786 | int wParam, 787 | int lParam, 788 | uint fuFlags, 789 | uint uTimeout, 790 | out int lpdwResult); 791 | 792 | [DllImport("user32", SetLastError = true)] 793 | public static extern bool PostMessage( 794 | int hWnd, 795 | uint Msg, 796 | int wParam, 797 | uint lParam 798 | ); 799 | 800 | [DllImport("user32.dll", SetLastError = true)] 801 | public static extern int PostMessage( 802 | int hWnd, 803 | int wMsg, 804 | int wParam, 805 | string lParam 806 | ); 807 | 808 | [DllImport("user32.dll", SetLastError = true)] 809 | public static extern int SetActiveWindow(int hWnd); 810 | 811 | [DllImport("user32.dll")] 812 | public static extern int GetWindowThreadProcessId( 813 | int hWnd, 814 | ref int lpdwProcessId); 815 | 816 | [DllImport("user32")] 817 | public static extern int Sleep( 818 | int dwMilliseconds 819 | ); 820 | 821 | [DllImport("user32.dll")] 822 | public static extern bool GetWindowRect( 823 | int hWnd, 824 | ref RECT lpRect 825 | ); 826 | 827 | [DllImport("user32")] 828 | public static extern int GetWindowText( 829 | int hWnd, 830 | StringBuilder lpString, 831 | int nMaxCount 832 | ); 833 | 834 | 835 | [DllImport("user32.dll")] 836 | public static extern bool ShowWindow( 837 | int hWnd, 838 | int nCmdShow 839 | ); 840 | 841 | [DllImport("user32", EntryPoint = "SetWindowLong")] 842 | public static extern uint SetWindowLong( 843 | IntPtr hwnd, 844 | int nIndex, 845 | uint dwNewLong 846 | ); 847 | 848 | [DllImport("user32", EntryPoint = "GetWindowLong")] 849 | public static extern uint GetWindowLong( 850 | IntPtr hwnd, 851 | int nIndex 852 | ); 853 | 854 | [DllImport("user32", EntryPoint = "SetLayeredWindowAttributes")] 855 | public static extern int SetLayeredWindowAttributes( 856 | IntPtr hwnd, //目标窗口句柄 857 | int ColorRefKey, //透明色 858 | int bAlpha, //不透明度 859 | int dwFlags 860 | ); 861 | 862 | [DllImport("user32")] 863 | public static extern bool MoveWindow( 864 | int hWnd, 865 | int X, 866 | int Y, 867 | int nWidth, 868 | int nHeight, 869 | bool bRepaint 870 | ); 871 | 872 | //获得窗口类名称,返回值为字符串的字符数量 873 | [DllImport("user32")] 874 | public static extern uint RealGetWindowClass( 875 | int hWnd, 876 | StringBuilder pszType, //缓冲区 877 | uint cchType); //缓冲区长度 878 | 879 | //枚举屏幕上所有顶级窗口(不会枚举子窗口,除了一些有WS_CHILD的顶级窗口) 880 | [DllImport("user32")] 881 | public static extern bool EnumWindows( 882 | WNDENUMPROC lpEnumFunc, 883 | int lParam 884 | ); 885 | 886 | [DllImport("user32")] 887 | public static extern bool EnumChildWindows( 888 | int hWndParent, 889 | WNDENUMPROC lpEnumFunc, 890 | int lParam 891 | ); 892 | 893 | [DllImport("user32")] 894 | public static extern bool EnumThreadWindows( //枚举线程窗口 895 | int dwThreadId, 896 | WNDENUMPROC lpEnumFunc, 897 | int lParam 898 | ); 899 | 900 | [DllImport("user32")] 901 | public static extern int GetParent( 902 | int hWnd 903 | ); 904 | 905 | [DllImport("user32")] 906 | public static extern int GetWindow( 907 | int hWnd, //基础窗口 908 | uint uCmd //关系 909 | ); 910 | 911 | /* 912 | * 获取鼠标的屏幕坐标,填充到Point 913 | * WINUSERAPI 914 | BOOL 915 | WINAPI 916 | GetCursorPos( 917 | __out LPPOINT lpPoint); 918 | */ 919 | [DllImport("user32")] 920 | public static extern bool GetCursorPos( 921 | out POINT lpPoint 922 | ); 923 | 924 | [DllImport("user32")] 925 | public static extern int GetDC( 926 | int hWnd 927 | ); 928 | 929 | [DllImport("user32")] 930 | public static extern int GetWindowDC( 931 | int hWnd 932 | ); 933 | 934 | [DllImport("user32")] 935 | public static extern int ReleaseDC( 936 | int hWnd, 937 | int hDC 938 | ); 939 | 940 | [DllImport("user32")] 941 | public static extern int FillRect( 942 | int hDC, 943 | RECT lprc, 944 | int hBrush 945 | ); 946 | 947 | [DllImport("user32")] 948 | public static extern bool InvalidateRect( 949 | int hwnd, 950 | ref RECT lpRect, 951 | bool bErase 952 | ); 953 | 954 | //判断一个窗口是否是可见的 955 | [DllImport("user32")] 956 | public static extern bool IsWindowVisible( 957 | int hwnd 958 | ); 959 | 960 | //绘制焦点举行 961 | [DllImport("user32")] 962 | public static extern bool DrawFocusRect( 963 | int hDC, 964 | ref RECT lprc 965 | ); 966 | 967 | [DllImport("user32")] 968 | public static extern bool UpdateWindow( 969 | int hwnd 970 | ); 971 | 972 | [DllImport("user32")] 973 | public static extern bool EnableWindow( 974 | int hwnd, 975 | bool bEnable 976 | ); 977 | 978 | //设置前景窗口,强制其线程成为前台,并激活窗口 979 | [DllImport("user32")] 980 | public static extern bool SetForegroundWindow( 981 | int hwnd 982 | ); 983 | 984 | [DllImport("user32.dll")] 985 | public static extern bool IsWindowEnabled( 986 | int hWnd 987 | ); 988 | 989 | //设置前景窗口,强制其线程成为前台,并激活窗口 990 | [DllImport("user32")] 991 | public static extern bool GetForegroundWindow( 992 | ); 993 | 994 | //获取拥有焦点窗口(唯一拥有键盘输入的窗口) 995 | [DllImport("user32")] 996 | public static extern int GetFocus( 997 | ); 998 | 999 | //设置焦点窗口(返回值是前一个焦点窗口) 1000 | [DllImport("user32")] 1001 | public static extern int SetFocus( 1002 | int hwnd 1003 | ); 1004 | 1005 | //根据点查找窗口 1006 | [DllImport("user32")] 1007 | public static extern int WindowFromPoint( 1008 | POINT Point 1009 | ); 1010 | 1011 | [DllImport("user32")] 1012 | public static extern int ChildWindowFromPoint( 1013 | int hWndParent, 1014 | POINT Point 1015 | ); 1016 | 1017 | [DllImport("user32")] 1018 | public static extern bool DestroyIcon( 1019 | int hIcon 1020 | ); 1021 | 1022 | [DllImport("user32.dll", EntryPoint = "SetWindowText", CharSet = CharSet.Auto)] 1023 | public static extern int SetWindowText( 1024 | int hwnd, 1025 | string lpString 1026 | ); 1027 | 1028 | [DllImport("kernel32")] 1029 | public static extern uint GetTickCount(); 1030 | 1031 | [DllImport("user32.dll", EntryPoint = "GetWindowThreadProcessId")] 1032 | public static extern uint GetWindowThreadProcessId(IntPtr hWnd, ref uint lpdwProcessId); 1033 | 1034 | [DllImport("user32.dll", CharSet = CharSet.Auto)] 1035 | public static extern int GetDlgItem(int hDlg, int nControlID); 1036 | #endregion 1037 | } 1038 | 1039 | } 1040 | -------------------------------------------------------------------------------- /THSTrader/THSClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Threading; 7 | using System.Configuration; 8 | using System.Windows.Forms; 9 | 10 | namespace THSTrader 11 | { 12 | public class StockHolding 13 | { 14 | public string Code { get; set; } 15 | public string Name { get; set; } 16 | public long Balance { get; set; } 17 | public long AvaiBalance { get; set; } 18 | public double Cost { get; set; } 19 | public double Price { get; set; } 20 | public double ProfitAndLossRate { get; set; } 21 | public double ProfitAndLoss { get; set; } 22 | public double Value { get; set; } 23 | } 24 | public class StockCommission 25 | { 26 | public string Code { get; set; } 27 | public string Name { get; set; } 28 | public string Direction { get; set; } 29 | public double OrderPrice { get; set; } 30 | public long OrderVol { get; set; } 31 | public string Time { get; set; } 32 | public long DealVol { get; set; } 33 | public long CancelVol { get; set; } 34 | public double DealPrice { get; set; } 35 | public string Contract { get; set; } 36 | } 37 | 38 | public class THSClient 39 | { 40 | static private object locker = new object(); 41 | 42 | const int WM_ID_COPY = 57634; 43 | const int WM_ID_BUY = 161; 44 | const int WM_ID_SELL = 162; 45 | const int WM_ID_CANCEL = 163; 46 | const int WM_ID_HOLD = 165; 47 | const int WM_ID_ORDER = 167; 48 | const int WM_ID_COMMIT = 168; 49 | const int WM_ID_PREORDER = 172; 50 | 51 | public string strMainWindowTitle = "网上股票交易系统5.0"; 52 | public string strSHAccount = ""; 53 | public string strSZAccount = ""; 54 | 55 | public bool allowBuyST = false; 56 | 57 | public int hWnd = 0; 58 | public int hToolbar = 0; 59 | public int hToolbarMarket = 0; 60 | public int hToolbarAccount = 0; 61 | public int hFrame = 0; 62 | public int hAfxWnd = 0; 63 | public int hLeft = 0; 64 | public int hLeftWnd = 0; 65 | public int hLeftTree = 0; 66 | 67 | public int hBuyWnd = 0; 68 | public int hBuyCodeEdit = 0; 69 | public int hBuyPriceEdit = 0; 70 | public int hBuyAmountEdit = 0; 71 | public int hBuyBtn = 0; 72 | public int hBuyNameStatic = 0; 73 | public int hBuyMaxAmountStatic = 0; 74 | public int hBQuoteWnd = 0; 75 | public int hBQuoteB1PriceStatic = 0; 76 | public int hBQuoteB2PriceStatic = 0; 77 | public int hBQuoteB3PriceStatic = 0; 78 | public int hBQuoteB4PriceStatic = 0; 79 | public int hBQuoteB5PriceStatic = 0; 80 | public int hBQuoteS1PriceStatic = 0; 81 | public int hBQuoteS2PriceStatic = 0; 82 | public int hBQuoteS3PriceStatic = 0; 83 | public int hBQuoteS4PriceStatic = 0; 84 | public int hBQuoteS5PriceStatic = 0; 85 | public int hBQuoteNowPriceStatic = 0; 86 | public int hBQuoteMaxPriceStatic = 0; 87 | public int hBQuoteMinPriceStatic = 0; 88 | 89 | 90 | public int hSellWnd = 0; 91 | public int hSellCodeEdit = 0; 92 | public int hSellPriceEdit = 0; 93 | public int hSellAmountEdit = 0; 94 | public int hSellBtn = 0; 95 | public int hSellNameStatic = 0; 96 | public int hSellMaxAmountStatic = 0; 97 | public int hSQuoteWnd = 0; 98 | public int hSQuoteB1PriceStatic = 0; 99 | public int hSQuoteB2PriceStatic = 0; 100 | public int hSQuoteB3PriceStatic = 0; 101 | public int hSQuoteB4PriceStatic = 0; 102 | public int hSQuoteB5PriceStatic = 0; 103 | public int hSQuoteS1PriceStatic = 0; 104 | public int hSQuoteS2PriceStatic = 0; 105 | public int hSQuoteS3PriceStatic = 0; 106 | public int hSQuoteS4PriceStatic = 0; 107 | public int hSQuoteS5PriceStatic = 0; 108 | public int hSQuoteNowPriceStatic = 0; 109 | public int hSQuoteMaxPriceStatic = 0; 110 | public int hSQuoteMinPriceStatic = 0; 111 | 112 | public int hHoldWnd = 0; 113 | public int hAvailable = 0; 114 | public int hStockValue = 0; 115 | public int hAsset = 0; 116 | public int hHoldGrid = 0; 117 | 118 | public int hOrderWnd = 0; 119 | public int hOrderGrid = 0; 120 | public int hCommitWnd = 0; 121 | public int hCommitGrid = 0; 122 | 123 | public int hWithdrawWnd = 0; 124 | public int hWithdrawCodeEdit = 0; 125 | public int hWithdrawQueryBtn = 0; 126 | public int hWithdrawSelectedBtn = 0; 127 | public int hWithdrawAllBtn = 0; 128 | public int hWithdrawBuyBtn = 0; 129 | public int hWithdrawSellBtn = 0; 130 | public int hWithdrawGrid = 0; 131 | public int hWithdrawSelectAllBtn = 0; 132 | 133 | System.Configuration.Configuration config; 134 | 135 | public THSClient() 136 | { 137 | config = ConfigurationManager.OpenExeConfiguration(System.Reflection.Assembly.GetExecutingAssembly().Location); 138 | strMainWindowTitle = config.AppSettings.Settings["MainWindowTitle"].Value.ToString(); 139 | strSHAccount = config.AppSettings.Settings["SHAccount"].Value.ToString(); 140 | strSZAccount = config.AppSettings.Settings["SZAccount"].Value.ToString(); 141 | 142 | StringBuilder stringBuilder = new StringBuilder(256); 143 | while ((hWnd = Utility.FindWindowEx(0, hWnd, null, strMainWindowTitle)) > 0) 144 | { 145 | List hList = Utility.FindWindowRe(hWnd, 0, "ToolbarWindow32", null, 10); 146 | hToolbar = hList.First(); 147 | hToolbarMarket = Utility.GetDlgItem(Utility.FindWindowEx(hToolbar, 0, "#32770", null), 0x3EB); 148 | hToolbarAccount = Utility.GetDlgItem(Utility.FindWindowEx(hToolbar, 0, "#32770", null), 0x3EC); 149 | 150 | string text = Utility.getItemText(hToolbarAccount); 151 | if (text == strSHAccount || text == strSZAccount) 152 | { 153 | hFrame = Utility.GetDlgItem(hWnd, 0xE900); 154 | hAfxWnd = Utility.GetDlgItem(hFrame, 0xE900); 155 | hLeft = Utility.GetDlgItem(hAfxWnd, 0x81); 156 | hLeftWnd = Utility.GetDlgItem(hLeft, 0xC8); 157 | hLeftTree = Utility.GetDlgItem(hLeftWnd, 0x81); 158 | return; 159 | } 160 | } 161 | 162 | throw new Exception("未找到对应的THS窗口。"); 163 | } 164 | 165 | public List GetHoldingDetail() 166 | { 167 | string[] strColumnTitle = new string[1]; 168 | string[][] strItems = new string[1][]; 169 | 170 | uint oldTick = Utility.GetTickCount(); 171 | 172 | while (Utility.GetTickCount() - oldTick < Utility.timeout) 173 | { 174 | if (GetStockDetail(ref strColumnTitle, ref strItems) == "") 175 | { 176 | return DecodeStockHolding(strColumnTitle, strItems); 177 | } 178 | 179 | Thread.Sleep(100); 180 | } 181 | 182 | return null; 183 | } 184 | public List GetCommissionDetail() 185 | { 186 | string[] strColumnTitle = new string[1]; 187 | string[][] strItems = new string[1][]; 188 | 189 | uint oldTick = Utility.GetTickCount(); 190 | 191 | while (Utility.GetTickCount() - oldTick < Utility.timeout) 192 | { 193 | if (GetCommissionDetail(ref strColumnTitle, ref strItems) == "") 194 | { 195 | return DecodeCommission(strColumnTitle, strItems); 196 | } 197 | 198 | Thread.Sleep(100); 199 | } 200 | 201 | return null; 202 | } 203 | public string GetAccountStat(ref double available, 204 | ref double stockValue, ref double asset) 205 | { 206 | string currentCaption = ""; 207 | int outResult = 0; 208 | 209 | lock (locker) 210 | { 211 | Utility.SendMessageTimeout(hWnd, Utility.WM_COMMAND, WM_ID_HOLD, 0, SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out outResult); 212 | hHoldWnd = WaitForDialog(hFrame, new string[] { "可用金额" }, ref currentCaption); 213 | if (hHoldWnd <= 0) 214 | return "无法定位持仓对话框"; 215 | 216 | hAvailable = Utility.GetDlgItem(hHoldWnd, 0x3F8); 217 | hStockValue = Utility.GetDlgItem(hHoldWnd, 0x3F6); 218 | hAsset = Utility.GetDlgItem(hHoldWnd, 0x3F7); 219 | //hHoldGrid = Utility.GetDlgItem( 220 | // Utility.GetDlgItem( 221 | // Utility.GetDlgItem(hHoldWnd, 0x417) 222 | // , 0xC8) 223 | // , 0x417);//表格控件嵌套在两层HexinWnd之内 224 | 225 | if (!WaitItemIsNotEmpty(hAvailable)) 226 | return "无法读取可用金额数据"; 227 | 228 | try 229 | { 230 | available = double.Parse(Utility.getItemText(hAvailable)); 231 | stockValue = double.Parse(Utility.getItemText(hStockValue)); 232 | asset = double.Parse(Utility.getItemText(hAsset)); 233 | return ""; 234 | } 235 | catch 236 | { 237 | return "数据读取错误"; 238 | } 239 | } 240 | } 241 | 242 | public string Cancel(string code, string type)//all, code_all, code_buy, code_sell 243 | { 244 | string currentCaption = ""; 245 | int msgResult = 0; 246 | 247 | lock (locker) 248 | { 249 | Utility.PostMessage(hWnd, Utility.WM_KEYDOWN, Utility.VK_F3, 0); 250 | hWithdrawWnd = WaitForDialog(hFrame, new string[] { "在委托记录上用鼠标双击或回车即可撤单" }, ref currentCaption); 251 | if (hWithdrawWnd <= 0) 252 | return "无法定位撤单对话框"; 253 | 254 | hWithdrawCodeEdit = Utility.GetDlgItem(hWithdrawWnd, 0xD14); 255 | hWithdrawQueryBtn = Utility.GetDlgItem(hWithdrawWnd, 0xD15); 256 | hWithdrawSelectedBtn = Utility.GetDlgItem(hWithdrawWnd, 0x44B); 257 | hWithdrawAllBtn = Utility.GetDlgItem(hWithdrawWnd, 0x7531); 258 | hWithdrawBuyBtn = Utility.GetDlgItem(hWithdrawWnd, 0x7532); 259 | hWithdrawSellBtn = Utility.GetDlgItem(hWithdrawWnd, 0x7533); 260 | hWithdrawSelectAllBtn = Utility.GetDlgItem(hWithdrawWnd, 0x44A); 261 | 262 | hWithdrawGrid = Utility.GetDlgItem( 263 | Utility.GetDlgItem( 264 | Utility.GetDlgItem(hWithdrawWnd, 0x417) 265 | , 0xC8) 266 | , 0x417);//表格控件嵌套在两层HexinWnd之内 267 | 268 | type = type.ToLower(); 269 | if (type == "all") 270 | { 271 | if (!WaitGridIsNotEmpty(hWithdrawGrid)) 272 | return "无可撤订单"; 273 | if (!WaitWindowEnable(hWithdrawAllBtn)) 274 | return "无法点击按钮"; 275 | Utility.SetActiveWindow(hWithdrawAllBtn); 276 | Utility.SendMessage(hWithdrawAllBtn, Utility.WM_CLICK, 0, 0); 277 | WaitWindowEnable(hWithdrawAllBtn); 278 | } 279 | else 280 | { 281 | Utility.SendMessageTimeout(hWithdrawCodeEdit, Utility.WM_SETTEXT, 0, code, SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 282 | if (!WaitItemIsEqual(hWithdrawCodeEdit, code)) 283 | return "无法正确设置代码"; 284 | if (!WaitWindowEnable(hWithdrawQueryBtn)) 285 | return "无法点击按钮"; 286 | Utility.SetActiveWindow(hWithdrawQueryBtn); 287 | Utility.SendMessage(hWithdrawQueryBtn, Utility.WM_CLICK, 0, 0); 288 | WaitWindowEnable(hWithdrawQueryBtn); 289 | if (!WaitGridCodeAreEqual(hWithdrawGrid, code) || !WaitItemIsEqual(hWithdrawSelectAllBtn, "全部清除")) 290 | return "无法执行查询代码和选中代码"; 291 | 292 | switch (type) 293 | { 294 | case "code_all": 295 | if (!WaitWindowEnable(hWithdrawSelectedBtn)) 296 | return "无法点击按钮"; 297 | Utility.SetActiveWindow(hWithdrawSelectedBtn); 298 | Utility.SendMessage(hWithdrawSelectedBtn, Utility.WM_CLICK, 0, 0); 299 | break; 300 | case "code_buy": 301 | if (!WaitWindowEnable(hWithdrawBuyBtn)) 302 | return "无法点击按钮"; 303 | Utility.SetActiveWindow(hWithdrawBuyBtn); 304 | Utility.SendMessage(hWithdrawBuyBtn, Utility.WM_CLICK, 0, 0); 305 | WaitWindowEnable(hWithdrawBuyBtn); 306 | break; 307 | case "code_sell": 308 | if (!WaitWindowEnable(hWithdrawSellBtn)) 309 | return "无法点击按钮"; 310 | Utility.SetActiveWindow(hWithdrawSellBtn); 311 | Utility.SendMessage(hWithdrawSellBtn, Utility.WM_CLICK, 0, 0); 312 | WaitWindowEnable(hWithdrawSellBtn); 313 | break; 314 | } 315 | } 316 | return ""; 317 | } 318 | } 319 | 320 | public string Buy_Money(string code, double money) 321 | { 322 | string level = "s5"; 323 | 324 | int msgResult = 0; 325 | 326 | lock (locker) 327 | { 328 | LoadBuyControl(); 329 | Utility.SendMessageTimeout(hBuyCodeEdit, Utility.WM_SETTEXT, 0, "", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 330 | 331 | Utility.SendMessageTimeout(hBuyPriceEdit, Utility.WM_SETTEXT, 0, "", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 332 | if (!WaitItemIsEqual(hBQuoteNowPriceStatic, "-")) 333 | return "无法重置输入编辑框"; 334 | 335 | Utility.SendMessageTimeout(hBuyCodeEdit, Utility.WM_SETTEXT, 0, code, SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 336 | if (!WaitItemIsEqual(hBuyCodeEdit, code) || !WaitItemIsNotEqual(hBQuoteNowPriceStatic, "-")) 337 | return "无法正确设置代码"; 338 | 339 | if (!WaitItemIsNotEmpty(hBuyNameStatic)) 340 | return "无法获取股票名称"; 341 | string s = Utility.getItemText(hBuyNameStatic).ToLower(); 342 | if (!allowBuyST && (s.Contains("*") || s.Contains("s"))) 343 | return "禁止买进*/s/st个股"; 344 | 345 | double price = GetNearlyBQuote(level); 346 | Utility.SendMessageTimeout(hBuyPriceEdit, Utility.WM_SETTEXT, 0, price.ToString("F2"), SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 347 | if (!WaitItemIsEqual(hBuyPriceEdit, price.ToString("F2"))) 348 | return "无法正确设置价格"; 349 | 350 | long num = (long)Math.Round(money / price); 351 | num = num / 100 * 100; 352 | Utility.SendMessageTimeout(hBuyAmountEdit, Utility.WM_SETTEXT, 0, num.ToString(), SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 353 | if (!WaitItemIsEqual(hBuyAmountEdit, num.ToString())) 354 | return "无法正确设置数量"; 355 | 356 | if (code[0] == '0' || code[0] == '3' || code.IndexOf("159") == 0) //sz 357 | { 358 | if (!WaitItemContains(hToolbarMarket, "深圳")) 359 | return "无法正确选择市场"; 360 | } 361 | else 362 | { 363 | if (!WaitItemContains(hToolbarMarket, "上海")) 364 | return "无法正确选择市场"; 365 | } 366 | 367 | if (!WaitWindowEnable(hBuyBtn)) 368 | return "无法点击按钮"; 369 | Utility.SetActiveWindow(hBuyWnd); 370 | Utility.SendMessage(hBuyBtn, Utility.WM_CLICK, 0, 0); 371 | 372 | WaitWindowEnable(hBuyBtn); 373 | Utility.SendMessageTimeout(hBuyCodeEdit, Utility.WM_SETTEXT, 0, "", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 374 | return ""; 375 | } 376 | } 377 | public string Buy_Level(string code, long num, string level) 378 | { 379 | level = level.ToLower(); 380 | int msgResult = 0; 381 | 382 | lock (locker) 383 | { 384 | LoadBuyControl(); 385 | Utility.SendMessageTimeout(hBuyCodeEdit, Utility.WM_SETTEXT, 0, "", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 386 | 387 | Utility.SendMessageTimeout(hBuyPriceEdit, Utility.WM_SETTEXT, 0, "", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 388 | if (!WaitItemIsEqual(hBQuoteNowPriceStatic, "-")) 389 | return "无法重置输入编辑框"; 390 | 391 | Utility.SendMessageTimeout(hBuyCodeEdit, Utility.WM_SETTEXT, 0, code, SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 392 | if (!WaitItemIsEqual(hBuyCodeEdit, code) || !WaitItemIsNotEqual(hBQuoteNowPriceStatic, "-")) 393 | return "无法正确设置代码"; 394 | 395 | if (!WaitItemIsNotEmpty(hBuyNameStatic)) 396 | return "无法获取股票名称"; 397 | string s = Utility.getItemText(hBuyNameStatic).ToLower(); 398 | if (!allowBuyST && (s.Contains("*") || s.Contains("s"))) 399 | return "禁止买进*/s/st个股"; 400 | 401 | double price = GetNearlyBQuote(level); 402 | Utility.SendMessageTimeout(hBuyPriceEdit, Utility.WM_SETTEXT, 0, price.ToString("F2"), SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 403 | if (!WaitItemIsEqual(hBuyPriceEdit, price.ToString("F2"))) 404 | return "无法正确设置价格"; 405 | 406 | num = num / 100 * 100; 407 | Utility.SendMessageTimeout(hBuyAmountEdit, Utility.WM_SETTEXT, 0, num.ToString(), SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 408 | if (!WaitItemIsEqual(hBuyAmountEdit, num.ToString())) 409 | return "无法正确设置数量"; 410 | 411 | if (code[0] == '0' || code[0] == '3' || code.IndexOf("159") == 0) //sz 412 | { 413 | if (!WaitItemContains(hToolbarMarket, "深圳")) 414 | return "无法正确选择市场"; 415 | } 416 | else 417 | { 418 | if (!WaitItemContains(hToolbarMarket, "上海")) 419 | return "无法正确选择市场"; 420 | } 421 | 422 | if (!WaitWindowEnable(hBuyBtn)) 423 | return "无法点击按钮"; 424 | Utility.SetActiveWindow(hBuyWnd); 425 | Utility.SendMessage(hBuyBtn, Utility.WM_CLICK, 0, 0); 426 | 427 | WaitWindowEnable(hBuyBtn); 428 | Utility.SendMessageTimeout(hBuyCodeEdit, Utility.WM_SETTEXT, 0, "", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 429 | return ""; 430 | } 431 | } 432 | public string Buy(string code, long num, double price) 433 | { 434 | int msgResult = 0; 435 | 436 | lock (locker) 437 | { 438 | LoadBuyControl(); 439 | Utility.SendMessageTimeout(hBuyCodeEdit, Utility.WM_SETTEXT, 0, "", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 440 | 441 | Utility.SendMessageTimeout(hBuyPriceEdit, Utility.WM_SETTEXT, 0, "", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 442 | if (!WaitItemIsEqual(hBQuoteNowPriceStatic, "-")) 443 | return "无法重置输入编辑框"; 444 | 445 | 446 | Utility.SendMessageTimeout(hBuyCodeEdit, Utility.WM_SETTEXT, 0, code, SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 447 | Utility.SendMessageTimeout(hBuyPriceEdit, Utility.WM_SETTEXT, 0, price.ToString("F2"), SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 448 | if (!WaitItemIsEqual(hBuyCodeEdit, code) || !WaitItemIsNotEqual(hBQuoteNowPriceStatic, "-")) 449 | return "无法正确设置代码"; 450 | if (!WaitItemIsEqual(hBuyPriceEdit, price.ToString("F2"))) 451 | return "无法正确设置价格"; 452 | 453 | 454 | if (!WaitItemIsNotEmpty(hBuyNameStatic)) 455 | return "无法获取股票名称"; 456 | string s = Utility.getItemText(hBuyNameStatic).ToLower(); 457 | if (!allowBuyST && (s.Contains("*") || s.Contains("s"))) 458 | return "禁止买进*/s/st个股"; 459 | 460 | num = num / 100 * 100; 461 | Utility.SendMessageTimeout(hBuyAmountEdit, Utility.WM_SETTEXT, 0, num.ToString(), SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 462 | if (!WaitItemIsEqual(hBuyAmountEdit, num.ToString())) 463 | return "无法正确设置数量"; 464 | 465 | if (code[0] == '0' || code[0] == '3' || code.IndexOf("159") == 0) //sz 466 | { 467 | if (!WaitItemContains(hToolbarMarket, "深圳")) 468 | return "无法正确选择市场"; 469 | } 470 | else 471 | { 472 | if (!WaitItemContains(hToolbarMarket, "上海")) 473 | return "无法正确选择市场"; 474 | } 475 | 476 | if (!WaitWindowEnable(hBuyBtn)) 477 | return "无法点击按钮"; 478 | Utility.SetActiveWindow(hBuyWnd); 479 | Utility.SendMessage(hBuyBtn, Utility.WM_CLICK, 0, 0); 480 | 481 | WaitWindowEnable(hBuyBtn); 482 | Utility.SendMessageTimeout(hBuyCodeEdit, Utility.WM_SETTEXT, 0, "", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 483 | return ""; 484 | } 485 | } 486 | 487 | public string Sell_Percent(string code, double percent) 488 | { 489 | string level = "b5"; 490 | int msgResult = 0; 491 | 492 | lock (locker) 493 | { 494 | LoadSellControl(); 495 | Utility.SendMessageTimeout(hSellCodeEdit, Utility.WM_SETTEXT, 0, "11", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 496 | 497 | Utility.SendMessageTimeout(hSellPriceEdit, Utility.WM_SETTEXT, 0, "", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 498 | if (!WaitItemIsEqual(hSQuoteNowPriceStatic, "-")) 499 | return "无法重置输入编辑框"; 500 | 501 | 502 | Utility.SendMessageTimeout(hSellCodeEdit, Utility.WM_SETTEXT, 0, code, SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 503 | if (!WaitItemIsEqual(hSellCodeEdit, code) || !WaitItemIsNotEqual(hSQuoteNowPriceStatic, "-")) 504 | return "无法正确设置代码"; 505 | 506 | double price = GetNearlySQuote(level); 507 | Utility.SendMessageTimeout(hSellPriceEdit, Utility.WM_SETTEXT, 0, price.ToString("F2"), SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 508 | if (!WaitItemIsEqual(hSellPriceEdit, price.ToString("F2"))) 509 | return "无法正确设置价格"; 510 | 511 | long maxAmount = 0; 512 | maxAmount = long.Parse(Utility.getItemText(hSellMaxAmountStatic)); 513 | long num = (long)Math.Floor((double)maxAmount * percent); 514 | Utility.SendMessageTimeout(hSellAmountEdit, Utility.WM_SETTEXT, 0, num.ToString(), SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 515 | if (!WaitItemIsEqual(hSellAmountEdit, num.ToString())) 516 | return "无法正确设置数量"; 517 | 518 | if (code[0] == '0' || code[0] == '3' || code.IndexOf("159") == 0) //sz 519 | { 520 | if (!WaitItemContains(hToolbarMarket, "深圳")) 521 | return "无法正确选择市场"; 522 | } 523 | else 524 | { 525 | if (!WaitItemContains(hToolbarMarket, "上海")) 526 | return "无法正确选择市场"; 527 | } 528 | 529 | if (!WaitWindowEnable(hSellBtn)) 530 | return "无法点击按钮"; 531 | Utility.SetActiveWindow(hSellWnd); 532 | Utility.SendMessage(hSellBtn, Utility.WM_CLICK, 0, 0); 533 | 534 | WaitWindowEnable(hSellBtn); 535 | Utility.SendMessageTimeout(hSellCodeEdit, Utility.WM_SETTEXT, 0, "", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 536 | return ""; 537 | } 538 | } 539 | public string Sell_Level(string code, long num, string level) 540 | { 541 | level = level.ToLower(); 542 | int msgResult = 0; 543 | 544 | lock (locker) 545 | { 546 | LoadSellControl(); 547 | Utility.SendMessageTimeout(hSellCodeEdit, Utility.WM_SETTEXT, 0, "11", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 548 | 549 | Utility.SendMessageTimeout(hSellPriceEdit, Utility.WM_SETTEXT, 0, "", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 550 | if (!WaitItemIsEqual(hSQuoteNowPriceStatic, "-")) 551 | return "无法重置输入编辑框"; 552 | 553 | 554 | Utility.SendMessageTimeout(hSellCodeEdit, Utility.WM_SETTEXT, 0, code, SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 555 | if (!WaitItemIsEqual(hSellCodeEdit, code) || !WaitItemIsNotEqual(hSQuoteNowPriceStatic, "-")) 556 | return "无法正确设置代码"; 557 | 558 | double price = GetNearlySQuote(level); 559 | Utility.SendMessageTimeout(hSellPriceEdit, Utility.WM_SETTEXT, 0, price.ToString("F2"), SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 560 | if (!WaitItemIsEqual(hSellPriceEdit, price.ToString("F2"))) 561 | return "无法正确设置价格"; 562 | 563 | long maxAmount = 0; 564 | maxAmount = long.Parse(Utility.getItemText(hSellMaxAmountStatic)); 565 | num = Math.Min(num, maxAmount); 566 | Utility.SendMessageTimeout(hSellAmountEdit, Utility.WM_SETTEXT, 0, num.ToString(), SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 567 | if (!WaitItemIsEqual(hSellAmountEdit, num.ToString())) 568 | return "无法正确设置数量"; 569 | 570 | if (code[0] == '0' || code[0] == '3' || code.IndexOf("159") == 0) //sz 571 | { 572 | if (!WaitItemContains(hToolbarMarket, "深圳")) 573 | return "无法正确选择市场"; 574 | } 575 | else 576 | { 577 | if (!WaitItemContains(hToolbarMarket, "上海")) 578 | return "无法正确选择市场"; 579 | } 580 | 581 | if (!WaitWindowEnable(hSellBtn)) 582 | return "无法点击按钮"; 583 | Utility.SetActiveWindow(hSellWnd); 584 | Utility.SendMessage(hSellBtn, Utility.WM_CLICK, 0, 0); 585 | 586 | WaitWindowEnable(hSellBtn); 587 | Utility.SendMessageTimeout(hSellCodeEdit, Utility.WM_SETTEXT, 0, "", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 588 | return ""; 589 | } 590 | } 591 | public string Sell(string code, long num, double price) 592 | { 593 | int msgResult = 0; 594 | 595 | lock (locker) 596 | { 597 | LoadSellControl(); 598 | Utility.SendMessageTimeout(hSellCodeEdit, Utility.WM_SETTEXT, 0, "11", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 599 | 600 | Utility.SendMessageTimeout(hSellPriceEdit, Utility.WM_SETTEXT, 0, "", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 601 | if (!WaitItemIsEqual(hSQuoteNowPriceStatic, "-")) 602 | return "无法重置输入编辑框"; 603 | 604 | 605 | Utility.SendMessageTimeout(hSellCodeEdit, Utility.WM_SETTEXT, 0, code, SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 606 | Utility.SendMessageTimeout(hSellPriceEdit, Utility.WM_SETTEXT, 0, price.ToString("F2"), SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 607 | if (!WaitItemIsEqual(hSellCodeEdit, code) || !WaitItemIsNotEqual(hSQuoteNowPriceStatic, "-")) 608 | return "无法正确设置代码"; 609 | if (!WaitItemIsEqual(hSellPriceEdit, price.ToString("F2"))) 610 | return "无法正确设置价格"; 611 | 612 | long maxAmount = 0; 613 | maxAmount = long.Parse(Utility.getItemText(hSellMaxAmountStatic)); 614 | num = Math.Min(num, maxAmount); 615 | Utility.SendMessageTimeout(hSellAmountEdit, Utility.WM_SETTEXT, 0, num.ToString(), SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 616 | if (!WaitItemIsEqual(hSellAmountEdit, num.ToString())) 617 | return "无法正确设置数量"; 618 | 619 | if (code[0] == '0' || code[0] == '3' || code.IndexOf("159") == 0) //sz 620 | { 621 | if (!WaitItemContains(hToolbarMarket, "深圳")) 622 | return "无法正确选择市场"; 623 | } 624 | else 625 | { 626 | if (!WaitItemContains(hToolbarMarket, "上海")) 627 | return "无法正确选择市场"; 628 | } 629 | 630 | if (!WaitWindowEnable(hSellBtn)) 631 | return "无法点击按钮"; 632 | Utility.SetActiveWindow(hSellWnd); 633 | Utility.SendMessage(hSellBtn, Utility.WM_CLICK, 0, 0); 634 | 635 | WaitWindowEnable(hSellBtn); 636 | Utility.SendMessageTimeout(hSellCodeEdit, Utility.WM_SETTEXT, 0, "", SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out msgResult); 637 | return ""; 638 | } 639 | } 640 | 641 | #region Helper 642 | private double GetNearlyBQuote(string level) 643 | { 644 | level = level.ToLower(); 645 | 646 | switch (level) 647 | { 648 | case "b5": 649 | try 650 | { 651 | return double.Parse(Utility.getItemText(hBQuoteB5PriceStatic)); 652 | } 653 | catch 654 | { 655 | return GetNearlyBQuote("b4"); 656 | } 657 | case "b4": 658 | try 659 | { 660 | return double.Parse(Utility.getItemText(hBQuoteB4PriceStatic)); 661 | } 662 | catch 663 | { 664 | return GetNearlyBQuote("b3"); 665 | } 666 | case "b3": 667 | try 668 | { 669 | return double.Parse(Utility.getItemText(hBQuoteB3PriceStatic)); 670 | } 671 | catch 672 | { 673 | return GetNearlyBQuote("b2"); 674 | } 675 | case "b2": 676 | try 677 | { 678 | return double.Parse(Utility.getItemText(hBQuoteB2PriceStatic)); 679 | } 680 | catch 681 | { 682 | return GetNearlyBQuote("b1"); 683 | } 684 | case "b1": 685 | try 686 | { 687 | return double.Parse(Utility.getItemText(hBQuoteB1PriceStatic)); 688 | } 689 | catch 690 | { 691 | return GetNearlyBQuote("now"); 692 | } 693 | case "s5": 694 | try 695 | { 696 | return double.Parse(Utility.getItemText(hBQuoteS5PriceStatic)); 697 | } 698 | catch 699 | { 700 | return GetNearlyBQuote("s4"); 701 | } 702 | case "s4": 703 | try 704 | { 705 | return double.Parse(Utility.getItemText(hBQuoteS4PriceStatic)); 706 | } 707 | catch 708 | { 709 | return GetNearlyBQuote("s3"); 710 | } 711 | case "s3": 712 | try 713 | { 714 | return double.Parse(Utility.getItemText(hBQuoteS3PriceStatic)); 715 | } 716 | catch 717 | { 718 | return GetNearlyBQuote("s2"); 719 | } 720 | case "s2": 721 | try 722 | { 723 | return double.Parse(Utility.getItemText(hBQuoteS2PriceStatic)); 724 | } 725 | catch 726 | { 727 | return GetNearlyBQuote("s1"); 728 | } 729 | case "s1": 730 | try 731 | { 732 | return double.Parse(Utility.getItemText(hBQuoteS1PriceStatic)); 733 | } 734 | catch 735 | { 736 | return GetNearlyBQuote("now"); 737 | } 738 | default: 739 | return double.Parse(Utility.getItemText(hBQuoteNowPriceStatic)); 740 | } 741 | } 742 | private double GetNearlySQuote(string level) 743 | { 744 | level = level.ToLower(); 745 | 746 | switch (level) 747 | { 748 | case "b5": 749 | try 750 | { 751 | return double.Parse(Utility.getItemText(hSQuoteB5PriceStatic)); 752 | } 753 | catch 754 | { 755 | return GetNearlySQuote("b4"); 756 | } 757 | case "b4": 758 | try 759 | { 760 | return double.Parse(Utility.getItemText(hSQuoteB4PriceStatic)); 761 | } 762 | catch 763 | { 764 | return GetNearlySQuote("b3"); 765 | } 766 | case "b3": 767 | try 768 | { 769 | return double.Parse(Utility.getItemText(hSQuoteB3PriceStatic)); 770 | } 771 | catch 772 | { 773 | return GetNearlySQuote("b2"); 774 | } 775 | case "b2": 776 | try 777 | { 778 | return double.Parse(Utility.getItemText(hSQuoteB2PriceStatic)); 779 | } 780 | catch 781 | { 782 | return GetNearlySQuote("b1"); 783 | } 784 | case "b1": 785 | try 786 | { 787 | return double.Parse(Utility.getItemText(hSQuoteB1PriceStatic)); 788 | } 789 | catch 790 | { 791 | return GetNearlySQuote("now"); 792 | } 793 | case "s5": 794 | try 795 | { 796 | return double.Parse(Utility.getItemText(hSQuoteS5PriceStatic)); 797 | } 798 | catch 799 | { 800 | return GetNearlySQuote("s4"); 801 | } 802 | case "s4": 803 | try 804 | { 805 | return double.Parse(Utility.getItemText(hSQuoteS4PriceStatic)); 806 | } 807 | catch 808 | { 809 | return GetNearlySQuote("s3"); 810 | } 811 | case "s3": 812 | try 813 | { 814 | return double.Parse(Utility.getItemText(hSQuoteS3PriceStatic)); 815 | } 816 | catch 817 | { 818 | return GetNearlySQuote("s2"); 819 | } 820 | case "s2": 821 | try 822 | { 823 | return double.Parse(Utility.getItemText(hSQuoteS2PriceStatic)); 824 | } 825 | catch 826 | { 827 | return GetNearlySQuote("s1"); 828 | } 829 | case "s1": 830 | try 831 | { 832 | return double.Parse(Utility.getItemText(hSQuoteS1PriceStatic)); 833 | } 834 | catch 835 | { 836 | return GetNearlySQuote("now"); 837 | } 838 | default: 839 | return double.Parse(Utility.getItemText(hSQuoteNowPriceStatic)); 840 | } 841 | } 842 | private void LoadBuyControl() 843 | { 844 | string currentCaption = ""; 845 | 846 | Utility.PostMessage(hWnd, Utility.WM_KEYDOWN, Utility.VK_F1, 0); 847 | hBuyWnd = WaitForDialog(hFrame, new string[] { "买入股票" }, ref currentCaption); 848 | if (hBuyWnd <= 0) 849 | throw new Exception("无法定位买入对话框"); 850 | 851 | hBuyCodeEdit = Utility.GetDlgItem(hBuyWnd, 0x408); 852 | hBuyPriceEdit = Utility.GetDlgItem(hBuyWnd, 0x409); 853 | hBuyAmountEdit = Utility.GetDlgItem(hBuyWnd, 0x40A); 854 | hBuyBtn = Utility.GetDlgItem(hBuyWnd, 0x3EE); 855 | hBuyNameStatic = Utility.GetDlgItem(hBuyWnd, 0x40C); 856 | hBuyMaxAmountStatic = Utility.GetDlgItem(hBuyWnd, 0x3FA); 857 | hBQuoteWnd = FindDialog(hBuyWnd, new string[] { "涨停", "跌停" }, ref currentCaption); 858 | hBQuoteB1PriceStatic = Utility.GetDlgItem(hBQuoteWnd, 0x3FA); 859 | hBQuoteB2PriceStatic = Utility.GetDlgItem(hBQuoteWnd, 0x401); 860 | hBQuoteB3PriceStatic = Utility.GetDlgItem(hBQuoteWnd, 0x402); 861 | hBQuoteB4PriceStatic = Utility.GetDlgItem(hBQuoteWnd, 0x40B); 862 | hBQuoteB5PriceStatic = Utility.GetDlgItem(hBQuoteWnd, 0x40C); 863 | hBQuoteS1PriceStatic = Utility.GetDlgItem(hBQuoteWnd, 0x3FD); 864 | hBQuoteS2PriceStatic = Utility.GetDlgItem(hBQuoteWnd, 0x3Fe); 865 | hBQuoteS3PriceStatic = Utility.GetDlgItem(hBQuoteWnd, 0x3FF); 866 | hBQuoteS4PriceStatic = Utility.GetDlgItem(hBQuoteWnd, 0x409); 867 | hBQuoteS5PriceStatic = Utility.GetDlgItem(hBQuoteWnd, 0x408); 868 | hBQuoteNowPriceStatic = Utility.GetDlgItem(hBQuoteWnd, 0x400); 869 | hBQuoteMaxPriceStatic = Utility.GetDlgItem(hBQuoteWnd, 0x404); 870 | hBQuoteMinPriceStatic = Utility.GetDlgItem(hBQuoteWnd, 0x405); 871 | } 872 | private void LoadSellControl() 873 | { 874 | string currentCaption = ""; 875 | 876 | Utility.PostMessage(hWnd, Utility.WM_KEYDOWN, Utility.VK_F2, 0); 877 | hSellWnd = WaitForDialog(hFrame, new string[] { "卖出股票" }, ref currentCaption); 878 | if (hSellWnd <= 0) 879 | throw new Exception("无法定位卖出对话框"); 880 | 881 | hSellCodeEdit = Utility.GetDlgItem(hSellWnd, 0x408); 882 | hSellPriceEdit = Utility.GetDlgItem(hSellWnd, 0x409); 883 | hSellAmountEdit = Utility.GetDlgItem(hSellWnd, 0x40A); 884 | hSellBtn = Utility.GetDlgItem(hSellWnd, 0x3EE); 885 | hSellNameStatic = Utility.GetDlgItem(hSellWnd, 0x40C); 886 | hSellMaxAmountStatic = Utility.GetDlgItem(hSellWnd, 0x40E); 887 | hSQuoteWnd = FindDialog(hSellWnd, new string[] { "涨停", "跌停" }, ref currentCaption); 888 | hSQuoteB1PriceStatic = Utility.GetDlgItem(hSQuoteWnd, 0x3FA); 889 | hSQuoteB2PriceStatic = Utility.GetDlgItem(hSQuoteWnd, 0x401); 890 | hSQuoteB3PriceStatic = Utility.GetDlgItem(hSQuoteWnd, 0x402); 891 | hSQuoteB4PriceStatic = Utility.GetDlgItem(hSQuoteWnd, 0x40B); 892 | hSQuoteB5PriceStatic = Utility.GetDlgItem(hSQuoteWnd, 0x40C); 893 | hSQuoteS1PriceStatic = Utility.GetDlgItem(hSQuoteWnd, 0x3FD); 894 | hSQuoteS2PriceStatic = Utility.GetDlgItem(hSQuoteWnd, 0x3Fe); 895 | hSQuoteS3PriceStatic = Utility.GetDlgItem(hSQuoteWnd, 0x3FF); 896 | hSQuoteS4PriceStatic = Utility.GetDlgItem(hSQuoteWnd, 0x409); 897 | hSQuoteS5PriceStatic = Utility.GetDlgItem(hSQuoteWnd, 0x408); 898 | hSQuoteNowPriceStatic = Utility.GetDlgItem(hSQuoteWnd, 0x400); 899 | hSQuoteMaxPriceStatic = Utility.GetDlgItem(hSQuoteWnd, 0x404); 900 | hSQuoteMinPriceStatic = Utility.GetDlgItem(hSQuoteWnd, 0x405); 901 | } 902 | 903 | private string GetStockDetail(ref string[] strColumnHeader, 904 | ref string[][] strItems) 905 | { 906 | string currentCaption = ""; 907 | int outResult = 0; 908 | 909 | lock (locker) 910 | { 911 | try 912 | { 913 | Utility.SendMessageTimeout(hWnd, Utility.WM_COMMAND, WM_ID_HOLD, 0, SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out outResult); 914 | hHoldWnd = WaitForDialog(hFrame, new string[] { "可用金额" }, ref currentCaption); 915 | if (hHoldWnd <= 0) 916 | return "无法定位持仓对话框"; 917 | 918 | hHoldGrid = Utility.GetDlgItem( 919 | Utility.GetDlgItem( 920 | Utility.GetDlgItem(hHoldWnd, 0x417) 921 | , 0xC8) 922 | , 0x417);//表格控件嵌套在两层HexinWnd之内 923 | 924 | ClipboardHelper.Save(); 925 | Clipboard.Clear(); 926 | int outResule = 0; 927 | Utility.SendMessageTimeout(hHoldGrid, (uint)Utility.WM_COMMAND, WM_ID_COPY, 0, SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out outResule); 928 | string cbText = Clipboard.GetText(TextDataFormat.UnicodeText); 929 | ClipboardHelper.Restore(); 930 | 931 | string[] strLines = cbText.Split(new string[] { "\r\n" }, 932 | StringSplitOptions.RemoveEmptyEntries); 933 | 934 | strColumnHeader = strLines[0].Split(new string[] { "\t" }, 935 | StringSplitOptions.RemoveEmptyEntries); 936 | 937 | string[][] items = new string[strLines.Length - 1][]; 938 | 939 | for (int i = 1; i < strLines.Length; i++) 940 | { 941 | items[i - 1] = strLines[i].Split(new string[] { "\t" }, 942 | StringSplitOptions.RemoveEmptyEntries); 943 | } 944 | 945 | strItems = items; 946 | return ""; 947 | } 948 | catch 949 | { 950 | return "无法提取持仓数据"; 951 | } 952 | } 953 | } 954 | private string GetCommissionDetail(ref string[] strColumnHeader, 955 | ref string[][] strItems) 956 | { 957 | string currentCaption = ""; 958 | int outResult = 0; 959 | 960 | lock (locker) 961 | { 962 | try 963 | { 964 | Utility.SendMessageTimeout(hWnd, Utility.WM_COMMAND, WM_ID_COMMIT, 0, SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out outResult); 965 | hCommitWnd = WaitForDialog(hFrame, new string[] { "合同编号" }, ref currentCaption); 966 | if (hCommitWnd <= 0) 967 | return "无法定位当日委托对话框"; 968 | 969 | hCommitGrid = Utility.GetDlgItem( 970 | Utility.GetDlgItem( 971 | Utility.GetDlgItem(hCommitWnd, 0x417) 972 | , 0xC8) 973 | , 0x417);//表格控件嵌套在两层HexinWnd之内 974 | 975 | ClipboardHelper.Save(); 976 | Clipboard.Clear(); 977 | int outResule = 0; 978 | Utility.SendMessageTimeout(hCommitGrid, (uint)Utility.WM_COMMAND, WM_ID_COPY, 0, SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out outResule); 979 | string cbText = Clipboard.GetText(TextDataFormat.UnicodeText); 980 | ClipboardHelper.Restore(); 981 | 982 | string[] strLines = cbText.Split(new string[] { "\r\n" }, 983 | StringSplitOptions.RemoveEmptyEntries); 984 | 985 | strColumnHeader = strLines[0].Split(new string[] { "\t" }, 986 | StringSplitOptions.RemoveEmptyEntries); 987 | 988 | string[][] items = new string[strLines.Length - 1][]; 989 | 990 | for (int i = 1; i < strLines.Length; i++) 991 | { 992 | items[i - 1] = strLines[i].Split(new string[] { "\t" }, 993 | StringSplitOptions.RemoveEmptyEntries); 994 | } 995 | 996 | strItems = items; 997 | return ""; 998 | } 999 | catch 1000 | { 1001 | return "无法提取委托数据"; 1002 | } 1003 | } 1004 | } 1005 | 1006 | private List DecodeStockHolding(string[] strColumnHeader, 1007 | string[][] strItems) 1008 | { 1009 | List listStockHoldings = new List(); 1010 | 1011 | for (int i = 0; i < strItems.Length; i++) 1012 | listStockHoldings.Add(new StockHolding()); 1013 | 1014 | for (int i = 0; i < strColumnHeader.Length; i++) 1015 | { 1016 | if (strColumnHeader[i] == config.AppSettings.Settings["Holding_Code"].Value.ToString()) 1017 | { 1018 | for (int j = 0; j < strItems.Length; j++) 1019 | listStockHoldings[j].Code = strItems[j][i]; 1020 | } 1021 | else if (strColumnHeader[i] == config.AppSettings.Settings["Holding_Name"].Value.ToString()) 1022 | { 1023 | for (int j = 0; j < strItems.Length; j++) 1024 | listStockHoldings[j].Name = strItems[j][i]; 1025 | } 1026 | else if (strColumnHeader[i] == config.AppSettings.Settings["Holding_Balance"].Value.ToString()) 1027 | { 1028 | for (int j = 0; j < strItems.Length; j++) 1029 | listStockHoldings[j].Balance = (long)double.Parse(strItems[j][i]); 1030 | } 1031 | else if (strColumnHeader[i] == config.AppSettings.Settings["Holding_AvaiBalance"].Value.ToString()) 1032 | { 1033 | for (int j = 0; j < strItems.Length; j++) 1034 | listStockHoldings[j].AvaiBalance = (long)double.Parse(strItems[j][i]); 1035 | } 1036 | else if (strColumnHeader[i] == config.AppSettings.Settings["Holding_Cost"].Value.ToString()) 1037 | { 1038 | for (int j = 0; j < strItems.Length; j++) 1039 | listStockHoldings[j].Cost = double.Parse(strItems[j][i]); 1040 | } 1041 | else if (strColumnHeader[i] == config.AppSettings.Settings["Holding_Price"].Value.ToString()) 1042 | { 1043 | for (int j = 0; j < strItems.Length; j++) 1044 | listStockHoldings[j].Price = double.Parse(strItems[j][i]); 1045 | } 1046 | else if (strColumnHeader[i] == config.AppSettings.Settings["Holding_ProfitAndLossRate"].Value.ToString()) 1047 | { 1048 | for (int j = 0; j < strItems.Length; j++) 1049 | listStockHoldings[j].ProfitAndLossRate = double.Parse(strItems[j][i]); 1050 | } 1051 | else if (strColumnHeader[i] == config.AppSettings.Settings["Holding_ProfitAndLoss"].Value.ToString()) 1052 | { 1053 | for (int j = 0; j < strItems.Length; j++) 1054 | listStockHoldings[j].ProfitAndLoss = double.Parse(strItems[j][i]); 1055 | } 1056 | else if (strColumnHeader[i] == config.AppSettings.Settings["Holding_Value"].Value.ToString()) 1057 | { 1058 | for (int j = 0; j < strItems.Length; j++) 1059 | listStockHoldings[j].Value = double.Parse(strItems[j][i]); 1060 | } 1061 | } 1062 | 1063 | return listStockHoldings; 1064 | } 1065 | private List DecodeCommission(string[] strColumnHeader, 1066 | string[][] strItems) 1067 | { 1068 | List listStockCommissions = new List(); 1069 | 1070 | for (int i = 0; i < strItems.Length; i++) 1071 | listStockCommissions.Add(new StockCommission()); 1072 | 1073 | for (int i = 0; i < strColumnHeader.Length; i++) 1074 | { 1075 | if (strColumnHeader[i] == config.AppSettings.Settings["Commission_Time"].Value.ToString()) 1076 | { 1077 | for (int j = 0; j < strItems.Length; j++) 1078 | listStockCommissions[j].Time = strItems[j][i]; 1079 | } 1080 | else if (strColumnHeader[i] == config.AppSettings.Settings["Commission_Code"].Value.ToString()) 1081 | { 1082 | for (int j = 0; j < strItems.Length; j++) 1083 | listStockCommissions[j].Code = strItems[j][i]; 1084 | } 1085 | else if (strColumnHeader[i] == config.AppSettings.Settings["Commission_Name"].Value.ToString()) 1086 | { 1087 | for (int j = 0; j < strItems.Length; j++) 1088 | listStockCommissions[j].Name = strItems[j][i]; 1089 | } 1090 | else if (strColumnHeader[i] == config.AppSettings.Settings["Commission_Direction"].Value.ToString()) 1091 | { 1092 | for (int j = 0; j < strItems.Length; j++) 1093 | listStockCommissions[j].Direction = strItems[j][i]; 1094 | } 1095 | else if (strColumnHeader[i] == config.AppSettings.Settings["Commission_OrderPrice"].Value.ToString()) 1096 | { 1097 | for (int j = 0; j < strItems.Length; j++) 1098 | listStockCommissions[j].OrderPrice = double.Parse(strItems[j][i]); 1099 | } 1100 | else if (strColumnHeader[i] == config.AppSettings.Settings["Commission_OrderVol"].Value.ToString()) 1101 | { 1102 | for (int j = 0; j < strItems.Length; j++) 1103 | listStockCommissions[j].OrderVol = (long)double.Parse(strItems[j][i]); 1104 | } 1105 | else if (strColumnHeader[i] == config.AppSettings.Settings["Commission_DealVol"].Value.ToString()) 1106 | { 1107 | for (int j = 0; j < strItems.Length; j++) 1108 | listStockCommissions[j].DealVol = (long)double.Parse(strItems[j][i]); 1109 | } 1110 | else if (strColumnHeader[i] == config.AppSettings.Settings["Commission_CancelVol"].Value.ToString()) 1111 | { 1112 | for (int j = 0; j < strItems.Length; j++) 1113 | listStockCommissions[j].CancelVol = (long)double.Parse(strItems[j][i]); 1114 | } 1115 | else if (strColumnHeader[i] == config.AppSettings.Settings["Commission_DealPrice"].Value.ToString()) 1116 | { 1117 | for (int j = 0; j < strItems.Length; j++) 1118 | listStockCommissions[j].DealPrice = double.Parse(strItems[j][i]); 1119 | } 1120 | else if (strColumnHeader[i] == config.AppSettings.Settings["Commission_Contract"].Value.ToString()) 1121 | { 1122 | for (int j = 0; j < strItems.Length; j++) 1123 | listStockCommissions[j].Contract = strItems[j][i]; 1124 | } 1125 | } 1126 | 1127 | return listStockCommissions; 1128 | } 1129 | 1130 | private bool WaitGridIsNotEmpty(int hGrid) 1131 | { 1132 | uint oldTick = Utility.GetTickCount(); 1133 | 1134 | while (Utility.GetTickCount() - oldTick < Utility.timeout) 1135 | { 1136 | try 1137 | { 1138 | ClipboardHelper.Save(); 1139 | Clipboard.Clear(); 1140 | int outResule = 0; 1141 | Utility.SendMessageTimeout(hGrid, (uint)Utility.WM_COMMAND, WM_ID_COPY, 0, SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out outResule); 1142 | string cbText = Clipboard.GetText(TextDataFormat.UnicodeText); 1143 | ClipboardHelper.Restore(); 1144 | 1145 | string[] strLines = cbText.Split(new string[] { "\r\n" }, 1146 | StringSplitOptions.RemoveEmptyEntries); 1147 | 1148 | if (strLines.Length >= 2) 1149 | return true; 1150 | } 1151 | catch 1152 | { 1153 | } 1154 | 1155 | Thread.Sleep(100); 1156 | } 1157 | 1158 | return false; 1159 | } 1160 | private bool WaitGridCodeAreEqual(int hGrid, string code) 1161 | { 1162 | uint oldTick = Utility.GetTickCount(); 1163 | 1164 | while (Utility.GetTickCount() - oldTick < Utility.timeout) 1165 | { 1166 | try 1167 | { 1168 | ClipboardHelper.Save(); 1169 | Clipboard.Clear(); 1170 | int outResule = 0; 1171 | Utility.SendMessageTimeout(hGrid, (uint)Utility.WM_COMMAND, WM_ID_COPY, 0, SendMessageTimeoutFlags.SMTO_BLOCK, Utility.timeout, out outResule); 1172 | string cbText = Clipboard.GetText(TextDataFormat.UnicodeText); 1173 | ClipboardHelper.Restore(); 1174 | 1175 | string[] strLines = cbText.Split(new string[] { "\r\n" }, 1176 | StringSplitOptions.RemoveEmptyEntries); 1177 | 1178 | string[] strColumnHeader = strLines[0].Split(new string[] { "\t" }, 1179 | StringSplitOptions.RemoveEmptyEntries); 1180 | 1181 | string[][] items = new string[strLines.Length - 1][]; 1182 | 1183 | for (int i = 1; i < strLines.Length; i++) 1184 | { 1185 | items[i - 1] = strLines[i].Split(new string[] { "\t" }, 1186 | StringSplitOptions.RemoveEmptyEntries); 1187 | } 1188 | 1189 | for (int i = 0; i < strColumnHeader.Length; i++) 1190 | { 1191 | if (strColumnHeader[i] == config.AppSettings.Settings["Cancel_Code"].Value.ToString()) 1192 | { 1193 | for (int j = 0; j < items.Length; j++) 1194 | if (items[j][i] != code) 1195 | return false; 1196 | } 1197 | } 1198 | 1199 | return true; 1200 | } 1201 | catch 1202 | { 1203 | } 1204 | 1205 | Thread.Sleep(100); 1206 | } 1207 | 1208 | return false; 1209 | } 1210 | 1211 | private bool WaitWindowEnable(int hWnd) 1212 | { 1213 | uint oldTick = Utility.GetTickCount(); 1214 | 1215 | while (Utility.GetTickCount() - oldTick < Utility.timeout) 1216 | { 1217 | if (Utility.IsWindowEnabled(hWnd)) 1218 | return true; 1219 | 1220 | Thread.Sleep(100); 1221 | } 1222 | 1223 | return false; 1224 | } 1225 | private bool WaitItemIsNotEmpty(int hItem) 1226 | { 1227 | StringBuilder stringBuilder = new StringBuilder(256); 1228 | uint oldTick = Utility.GetTickCount(); 1229 | 1230 | while (Utility.GetTickCount() - oldTick < Utility.timeout) 1231 | { 1232 | Utility.SendMessage(hItem, Utility.WM_GETTEXT, 256, stringBuilder); 1233 | 1234 | string strCaption = stringBuilder.ToString(); 1235 | if (strCaption.Trim() != "") 1236 | return true; 1237 | 1238 | Thread.Sleep(100); 1239 | } 1240 | 1241 | return false; 1242 | } 1243 | private bool WaitItemIsEmpty(int hItem) 1244 | { 1245 | StringBuilder stringBuilder = new StringBuilder(256); 1246 | uint oldTick = Utility.GetTickCount(); 1247 | 1248 | while (Utility.GetTickCount() - oldTick < Utility.timeout) 1249 | { 1250 | Utility.SendMessage(hItem, Utility.WM_GETTEXT, 256, stringBuilder); 1251 | 1252 | string strCaption = stringBuilder.ToString(); 1253 | 1254 | if (strCaption.Trim() == "") 1255 | return true; 1256 | 1257 | Thread.Sleep(100); 1258 | } 1259 | 1260 | return false; 1261 | } 1262 | private bool WaitItemIsEqual(int hItem, string ipt) 1263 | { 1264 | StringBuilder stringBuilder = new StringBuilder(256); 1265 | uint oldTick = Utility.GetTickCount(); 1266 | 1267 | while (Utility.GetTickCount() - oldTick < Utility.timeout) 1268 | { 1269 | Utility.SendMessage(hItem, Utility.WM_GETTEXT, 256, stringBuilder); 1270 | 1271 | string strCaption = stringBuilder.ToString(); 1272 | 1273 | if (strCaption.Trim() == ipt) 1274 | return true; 1275 | 1276 | Thread.Sleep(100); 1277 | } 1278 | 1279 | return false; 1280 | } 1281 | private bool WaitItemIsNotEqual(int hItem, string ipt) 1282 | { 1283 | StringBuilder stringBuilder = new StringBuilder(256); 1284 | uint oldTick = Utility.GetTickCount(); 1285 | 1286 | while (Utility.GetTickCount() - oldTick < Utility.timeout) 1287 | { 1288 | Utility.SendMessage(hItem, Utility.WM_GETTEXT, 256, stringBuilder); 1289 | 1290 | string strCaption = stringBuilder.ToString(); 1291 | 1292 | if (strCaption.Trim() != ipt) 1293 | return true; 1294 | 1295 | Thread.Sleep(100); 1296 | } 1297 | 1298 | return false; 1299 | } 1300 | private bool WaitItemContains(int hItem, string ipt) 1301 | { 1302 | StringBuilder stringBuilder = new StringBuilder(256); 1303 | uint oldTick = Utility.GetTickCount(); 1304 | 1305 | while (Utility.GetTickCount() - oldTick < Utility.timeout) 1306 | { 1307 | Utility.SendMessage(hItem, Utility.WM_GETTEXT, 256, stringBuilder); 1308 | 1309 | string strCaption = stringBuilder.ToString(); 1310 | 1311 | if (strCaption.Trim().Contains(ipt)) 1312 | return true; 1313 | 1314 | Thread.Sleep(100); 1315 | } 1316 | 1317 | return false; 1318 | } 1319 | private bool WaitItemDontContain(int hItem, string ipt) 1320 | { 1321 | StringBuilder stringBuilder = new StringBuilder(256); 1322 | uint oldTick = Utility.GetTickCount(); 1323 | 1324 | while (Utility.GetTickCount() - oldTick < Utility.timeout) 1325 | { 1326 | Utility.SendMessage(hItem, Utility.WM_GETTEXT, 256, stringBuilder); 1327 | 1328 | string strCaption = stringBuilder.ToString(); 1329 | 1330 | if (!strCaption.Trim().Contains(ipt)) 1331 | return true; 1332 | 1333 | Thread.Sleep(100); 1334 | } 1335 | 1336 | return false; 1337 | } 1338 | private int FindDialog(int hParent, string[] captionArr, ref string currentCaption) 1339 | { 1340 | int hDialog = 0; 1341 | StringBuilder stringBuilder = new StringBuilder(256); 1342 | 1343 | while ((hDialog = Utility.FindWindowEx(hParent, hDialog, "#32770", null)) > 0) 1344 | { 1345 | int hStatic = 0; 1346 | while ((hStatic = Utility.FindWindowEx(hDialog, hStatic, "Static", null)) > 0) 1347 | { 1348 | Utility.SendMessage(hStatic, Utility.WM_GETTEXT, 256, stringBuilder); 1349 | string strCaption = stringBuilder.ToString(); 1350 | 1351 | foreach (string caption in captionArr) 1352 | { 1353 | if (strCaption == caption) 1354 | { 1355 | currentCaption = caption; 1356 | return hDialog; 1357 | } 1358 | } 1359 | } 1360 | } 1361 | 1362 | return 0; 1363 | } 1364 | private int WaitForDialog(int hParent, string[] captionArr, ref string currentCaption) 1365 | { 1366 | uint oldTick = Utility.GetTickCount(); 1367 | 1368 | while (Utility.GetTickCount() - oldTick < Utility.timeout) 1369 | { 1370 | int hDialog = 0; 1371 | 1372 | if ((hDialog = FindDialog(hParent, captionArr, ref currentCaption)) > 0) 1373 | return hDialog; 1374 | 1375 | Thread.Sleep(100); 1376 | } 1377 | 1378 | return 0; 1379 | } 1380 | #endregion 1381 | 1382 | } 1383 | } 1384 | --------------------------------------------------------------------------------