How do you get a Process' main window handle in C#?

The objective is to programmatically start a Windows Form, get its handle, and send info to its wndProc() function using Win Api's SendMessage() function. I got the SendMessage() part taken care of but the problem now is getting the form's handle after the process has been started. My first guess was that Process' MainWindowHandle property would get me the handle I am looking for,

如何在C#中获得Process'主窗口句柄?

目标是以编程方式启动Windows窗体,获取其句柄,并使用Win Api的SendMessage()函数将信息发送到其wndProc()函数。 我得到了SendMessage()部分的照顾,但现在的问题是在进程启动后获取表单的句柄。 我的第一个猜测是Process'MainWindowHandle属性会让我得到我正在查找的句柄,但是在我启动过程之后,MainWindowHandle仍然等于0,下面的代码不显示刚刚启动的过程的句柄: foreach (Process p in Process.GetProcesse

Get component type of custom .NET class from window handle

I need to see the component type, meaning the name of the class that was programmed, of a clicked control in another process. I need the type so I can react to the clicked control and then do some Automation tasks. Right now I am doing the following: 1. I FindWindow() from Win32 to find the main window handle of the process. 2. Then, I get call EnumChildWindows(), also from Win32, and get the

从窗口句柄获取自定义.NET类的组件类型

我需要查看组件类型,即所编程的类的名称,以及另一个进程中单击的控件的名称。 我需要这种类型,以便对点击的控件作出反应,然后执行一些自动化任务。 现在我正在做以下工作:1.我从Win32的FindWindow()找到进程的主窗口句柄。 2.然后,我从Win32中调用EnumChildWindows(),并获取主窗口句柄的所有子项的窗口句柄。 3.现在变得棘手。 当我调用GetClassName()时,它会返回WindowsForms10.STATIC.app [...],因为我试

Find window with specific text for a Process

I'm trying to find if a window with specific has been open by a Process. That process spawns multiple windows, and I need to check them all. I have no trouble finding the process, with foreach (Process p in Process.GetProcesses()) { if (p.MainModule.FileName.ToLower().EndsWith("foo.exe")) FindChildWindowWithText(p); //do work the problem is what to do next. I cannot use Process&#

查找包含特定文本的窗口

我试图找出一个特定的窗口是否已经被一个Process打开。 该过程会产生多个窗口,我需要检查它们。 我不难发现这个过程 foreach (Process p in Process.GetProcesses()) { if (p.MainModule.FileName.ToLower().EndsWith("foo.exe")) FindChildWindowWithText(p); //do work 问题是接下来要做什么。 我无法使用MainWindowText ,因为它随着激活的窗口而改变。 然后我尝试使用Windows函数EnumChildWindows和GetWindo

Is there a way to check if a file is in use?

I'm writing a program in C# that needs to repeatedly access 1 image file. Most of the time it works, but if my computer's running fast, it will try to access the file before it's been saved back to the filesystem and throw an error: "File in use by another process". I would like to find a way around this, but all my Googling has only yielded creating checks by using excep

有没有办法检查一个文件是否在使用?

我正在用C#编写一个需要重复访问1个图像文件的程序。 大多数情况下它都能正常工作,但如果我的电脑运行速度很快,它会在文件保存回文件系统之前尝试访问该文件,并抛出一个错误:“正被另一进程使用的文件”。 我想找到一个解决方法,但我所有的谷歌搜索只使用异常处理创建检查。 这是违背我的宗教信仰的,所以我想知道是否有人有更好的方式去做? 已更新此解决方案的注意事项 :使用FileAccess.ReadWrite检查将无法读取只

Entity Framwork Unable to Load the specified metadata resource

So I have set up a SQL Server and EF in my project. MPSDBEntities mpsEntities = new MPSDBEntities(); And it works fine when I do a save changes. eg mpsEntities.SaveChanges(); it updates the database (does it mean my connection string is correct?) However, whenever I tried to perform any kind of load data/SQL from the EF, such as var temp = mpsEntities.CARD_BY_CHECKTYPE.Where(x => (x.CH

实体框架无法加载指定的元数据资源

所以我在我的项目中建立了一个SQL Server和EF。 MPSDBEntities mpsEntities = new MPSDBEntities(); 当我进行保存更改时,它工作正常。 例如 mpsEntities.SaveChanges(); 它更新数据库(这是否意味着我的连接字符串是正确的?) 但是,每当我尝试从EF执行任何类型的加载数据/ SQL时,例如 var temp = mpsEntities.CARD_BY_CHECKTYPE.Where(x => (x.CHECK_TYPE == "AA2")).ToList(); 它会抛出一个例外 无法加载指定

Unable to load the specified metadata resource Release vs Debug build

I've been scratching my head for hours with a peculiar issue in Entity Framework. The following questions are not duplicates since their answers do not help me: MetadataException: Unable to load the specified metadata resource Entity Framework - Unable to load the specified metadata resource Unable to load the specified metadata resource I have an aspnet core mvc app ( v1.1 ) that r

无法加载指定的元数据资源Release vs Debug版本

我在Entity Framework中遇到了一个特殊问题,一直在困扰着我几个小时。 以下问题不是重复的,因为他们的回答对我没有帮助: MetadataException:无法加载指定的元数据资源 实体框架 - 无法加载指定的元数据资源 无法加载指定的元数据资源 我有一个aspnet core mvc应用程序( v1.1 ),它引用了作为NuGet程序包安装的Entity Framework 6.1.3的.NET Framework 4.7项目(数据访问层)。 我正在使用设计器,因此我有一个

Unable to load the specified metadata resource

I realise that this has been asked a number of times but I just can't seem to get the bottom of my issue. I'm getting the following error stack: When I reflect out my dll I can see the following Reading http://blogs.teamb.com/craigstuntz/2010/08/13/38628/ it suggests I'd expect to see the csdl, msl and ssdl files here, but they're not. They do exist here objDebugedmxResource

无法加载指定的元数据资源

我意识到这已被问了很多次,但我似乎无法得到我的问题的底部。 我收到以下错误堆栈: 当我反映出我的dll时,我可以看到以下内容 阅读http://blogs.teamb.com/craigstuntz/2010/08/13/38628/它建议我期望在这里看到csdl,msl和ssdl文件,但它们不是。 尽管如此,它们确实存在obj Debug edmxResourcesToEmbed。 无论如何,我试图通过这样做明确地告诉web.config在哪里看: ...connectionString="metadata=res://DllName.

MetadataException: Schema specified is not valid

I have been working on a Silverlight application. This application is supposed to be hosted with Godaddy. The application connects to MySql as it's backend database and uses entity framework. The application works correctly on Visual Studio. However, when I moved the files to Godaddy, I started having some issues. The application started throwing a MetadataException. I have used Fidd

MetadataException:指定的模式无效

我一直在研究Silverlight应用程序。 这个应用程序应该与Godaddy托管。 该应用程序连接到MySql,因为它是后端数据库并使用实体框架。 该应用程序在Visual Studio上正常工作。 但是,当我将文件移至Godaddy时,我开始出现一些问题。 该应用程序开始抛出MetadataException。 我用小提琴来追踪这个问题。 第一个WCF请求被正确终止,但后续请求失败,头代码为500.抛出以下异常。 我希望能帮助我解决这个问题,因为我尝试

MetadataException in Release Build

My Program uses EF to access data from a SQL CE database. When debug the application using debug setup it works fine but if I use release setup I get a MetadataException when the program tries to access the database through EF. What I've checked so far: Debug and release configuration is identical (same target platform) The app.config is copied to the same directory as the executable (R

发布版本中的MetadataException

我的程序使用EF从SQL CE数据库访问数据。 当使用调试设置来调试应用程序时,它可以正常工作,但如果我使用发布设置,当程序试图通过EF访问数据库时,我会遇到MetadataException。 我到目前为止检查过的东西: 调试和发布配置是相同的(相同的目标平台) app.config被复制到与可执行文件相同的目录( Release) sdf数据库文件被复制到 Release 元数据工件处理设置为在输出汇编中嵌入 连接字符串名称在app.config和EF

MetadataException [Unable to load the specified metadata resource]

I really need help on this. There are a lot of information about the error in stackoverflow. However none of them is of help. A problem description is following in bottom of this question. MetadataArtifactProcessing - this is set to "embed in output assembly", which is correct app.config - I know the connectionstring have to be in the config file from the running assembly. I

MetadataException [无法加载指定的元数据资源]

我真的需要帮助。 关于stackoverflow中的错误有很多信息。 然而,他们都没有帮助。 这个问题的底部是一个问题描述。 MetadataArtifactProcessing - 这被设置为“嵌入输出组件”,这是正确的 的app.config - 我知道connectionstring必须位于运行程序集的配置文件中。 我已经做到了。 x86 / x64位我已经对汇编和框架版本进行了双重检查,并且所有内容都是应该的(在这种情况下,这意味着.net 4和x86)。 路径res: