C#调用外部exe作为子窗体或UI? VC++如何实现呢呢?...札记plus

2 篇文章 0 订阅
1 篇文章 0 订阅
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            System.Diagnostics.Process p = System.Diagnostics.Process.Start(@"C:\tmp\Soong.exe");
            p.WaitForInputIdle();
            SetParent(p.MainWindowHandle, this.Handle);
            ShowWindowAsync(p.MainWindowHandle, 3);
        }
        [DllImport("user32.dll")]
        static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
        [DllImport("user32.dll")]
        private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); 
    }
}


如果是VC++,如何实现上述功能呢?

道理是一样的:

1,开启线程,获取其窗口句柄

2,设置其父窗口

3,设置窗口样式,去掉标题栏和菜单栏

4,调整窗口,使看起来是一个窗口

5,OnSize重写,调整父窗口时,子窗口跟着相应调整


POCO C++库在Windows上使用VS2010编译的方法:

1 下载POCO库:http://pocoproject.org/download/index.html

2 解压在解压目录内写一个后缀名为cmd的空文本文件,编写命令行内容:

@echo off
if defined VS100COMNTOOLS (
call "%VS100COMNTOOLS%\vsvars32.bat")
buildwin 100 build static_mt both Win32 nosamples devenv

3 运行该文件,即可编译


OpenSSLWIN平台上上通过Perl使用VS2010编译


1. 下载最新版本的Perl

2.下载 latest openssl并解压到C:\

参考openssl目录下的install.win32说明进行安装:

1、进入解压目录。

>cd C:\openssl-0.9.8k

2、运行Configure

>perl Configure VC-WIN32–prefix=C:\openssl-0.9.8k”(注意大小写区分),

如不成功会有明显提示。

3、创建Makefile文件。

>ms\do_ms

推荐使用这种方式,另外两种方式如果使用也必须保证本机有编译器才能使用。

:ms\do_masm(默认vc自带的编译器;也也以自己下载安装)

:ms\do_nasm(需要自己下载)

4、配置VC环境变量。很重要

>cd C:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools

  >vcvars32.bat

5、编译动态链接库。

>cd C:\openssl-0.9.8k

>nmake -f ms\ntdll.mak

如果编译成功,最后的输出都在out32dll目录下:包括可执行文件、两个dllssleay32.lib, libeay32.lib)和两个lib文件(ssleay32.dll, libeay32.dll)。

6、为VC添加头文件和静态链接库路径。

ToolsàOptionsàDirectores,在Include files中增加C:\openssl-0.9.8k \inc32目录;在Libray files中增加C:\openssl-0.9.8k\out32dll

7、编写OpenSSL程序,可参考C:\openssl-0.9.8k\demos

1)包含相应头文件

#include<openssl/***.h>

(2)添加静态链接库

#pragmacomment(lib,"libeay32.lib")

#pragmacomment(lib,"ssleay32.lib")

ProjectàSettingsàLinkàObject\library modules填写libeay32.lib ssleay32.lib

3)将动态链接库ssleay32.dll, libeay32.dll复制到C:\WINDOWS\system32Debug目录下,确保动态链接库在正确的路径。


C++分词一例

#include < iostream >
#include < sstream >
#include < string >
#include < iterator >
#include < numeric>

using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::istringstream;
using std::istream_iterator;

void _tmain(int argc, _TCHAR* argv[])
{
	string data("2.4 2.5 3.6 2.1 6.7 6.8 94 95 1.1 1.4 32");
	istringstream input(data);
	istream_iterator < double > begin(input), end;
	cout << "The sum of the values from the data string is "<< std::accumulate(begin, end, 0.0) << endl;
}


Python导入包

如下图,想在Main.py中导入包Soong的Material类

Main.py源码:

__author__ = 'Proteus'

from Soong import *
from Phy import *

mtrl=MaterialDef.Material()
mtrl.Cp=31

print mtrl.Cp

node=Node1D.Node1D()

node.mtrl=mtrl
node.mtrl.rho=7010

print node.mtrl.rho

__init__.py中代码如下:

__author__ = 'Proteus'

__all__ = ['MaterialDef']

         __init__.py是个很重要的文件,导入包会执行其中脚本。当其为空文件时,编译器执行语句“from Soong import *”时会问说:

Traceback (most recent call last):
  File "D:/PycharmProjects/pyDemo/Main.py", line 5, in <module>
    mtrl=MaterialDef.Material()
NameError: name 'MaterialDef' is not defined

         MaterialDef.py中Material类的定义如下:

class Material:
    def __init__(self,name="Steel",rho=7200,Cp=680,lmd=34):
        self.name=name
        self.rho=rho
        self.Cp=Cp
        self.lmd=lmd

    def GetH(self,T,T0):
        return self.Cp*(T-T0)

    def ToString(self):
        return self.name
想在Phy包中引用Soong包中的Material类则在Node1D文件中导入MaterialDef包:
__author__ = 'Proteus'

from Soong import *

class Node1D:
    def __init__(self,x=0,T=1550,T0=1550,Vol=1):
        self.x=0
        self.T=1550
        self.T0=1550
        self.Vol=1
        self.mtrl=MaterialDef.Material()

    def Update(self):
        self.T0=self.T

Python逐行读取文本文件并去掉换行符

      早就听说Python是干大事的,小事情是不屑于做的,今天领教了,RT:

FileOrigin=open("AS3Syntax.txt")
FileConverted=open("AS3SyntaxList.txt",'w')
lineNo=0
for line in FileOrigin:
    lineNo+=1
    print(lineNo)
    ln=line.strip();
    ln.replace('\n','')
    ln="\""+ln+"\",\n"
    print(ln)
    FileConverted.write(ln)
    
FileOrigin.close()    
FileConverted.close()
print("done..")   






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值