.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to get what application is connected to the topmost window?

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :Windows Application
My VB.NET application is suposed to monitor what application currently is running in the topmost window. I have tried the following approach using a timer: Declare Function GetActiveWindow Lib "user32" () As System.IntPtr Declare Function GetForegroundWindow Lib "user32" () As System.IntPtr Public Declare Auto Function GetWindowText Lib "user32" _ (ByVal hWnd As System.IntPtr, _ ByVal lpString As System.Text.StringBuilder, _ ByVal cch As Integer) As Integer Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick    Dim Caption As New System.Text.StringBuilder(256)    Dim hWnd As IntPtr = GetForegroundWindow()    GetWindowText(hWnd, Caption, Caption.Capacity)    'Caption now holds the title of the topmost window End Sub By this I can see that for example Outlook or Internet Explorer is the topmost window as the name is in Window's title bar. However, if the user crates a new mail in Outlook the title of the window is "Untitled message" givning no hint of what application is running in the the window. How do I get what application is connected to the topmost window?p> Help is appreciated!

View Complete Post

More Related Resource Links

problem in consuming WCF service through Window application


I have a silverlight application and WCF service all made in VS 2010 , i had hosted my site to web server which contain Window 2008 and IIS 7.0

now the problem is i have another application which is a window application developed in VS2008 , when i try to add the service reference it gives me error


The document at the url was not recognized as a known document type.

The error message from each known type may help you fix the problem:

- Report from 'DISCO Document' is 'There was an error downloading 'http://dev_qa.emspa.com/HRDev3/Service.svc?disco'.'.

  - The request failed with HTTP status 400: Bad Request.

- Report from 'WSDL Document' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.

- Report from '' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.

- Report from 'XML Schema' is 'The document format is not recognized (the content type is 'text/html; charset=UTF-8').'.

Metadata contains a reference that cannot be resolved: ''.

Content Type application/soap+xml; charset

Disable redirector when Installing 32 bit application on Window 7- 64 bit

When I install my 32 bit apps on Window 7 - 64 bit, it redirects registries and data files.However, the current codes have hardcoded to read the regular location such as:"HKLM\Software\MyApps" and "\Program Files\MyApps"Is there a way that I can disable the director while install my 32 bit application to solve this situation?If yes, can someone please show me how to do so in c#?I found they mention about calling Wow64EnableWow64FsRedirection in Kernel32.dll.Thanks

How do you integrate a flex 4 application in a wpf window? (With Error)

I am trying to integrate a flex 4 application into a wpf application.   I am following an old forum post: http://social.msdn.microsoft.com/forums/en-US/wpf/thread/39d558c1-5a76-4aae-be57-6aec9b8bf319 as a guide but it doesn't work correctly. The first thing I did was create the windows form control to add the flash control, i added a com component at C:\Windows\System32\Macromed\Flash\flash10i.ocx and added the Shockware flash object to the form.  added a URL property so i could set the file it would play and saved the formcontrol as mycontrol.   Then in the wpf application, i added a reference to mycontrol and windowsformintegration. then in the mainwindow.xaml i added these two lines at the top  xmlns:ax="clr-namespace:mycontrol;assembly=mycontrol"  xmlns:wfh="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration" then in the grid i added   <wfh:WindowsFormsHost>             <ax:MyControl1 x:Name="FlexFlash" URL="fileurl.swf"></ax:MyControl1 >         </wfh:WindowsFormsHost> It compiles and runs but it doesn't actually display the application.... instread it stays blank.  Now to make sure that it's a valid url i posted it in a messagebox  and copy and pasted it into a

WPF client application connected to an ASP mySQL database

Dear all, I have a customer who is using an online ASP applciation which provide different type of application. My customer run this app within a browser or a simple local client app which s connected to a remote database accessible via an ADSL connection. Today my customer ask me to build a touch client application and collect those data based on different criteria. According to information I have today it seems that the database is mySQL ( not usre at 100%) In case it is mySQL, does any one has made a kind a gateway between mySQl and .net app when database is hosted remotely ? thnaks for advise if any regards SergeYour knowledge is enhanced by that of others.

C#Net2008 Window Application - F5 launch wrong FORM


Hullo Good Friend,

I encounter another interesting problem.

I need your help. Please help me.

I am writing a new C#Net2008 Window Application. The first FORM that was created is FrmSales.cs

Then I created another FORM FrmMainMenu.cs which is the Main Menu form with 6 command buttons to load other forms.

When I pressed F5 to launch the application, FrmSales.cs appears instead of FrmMainMenu .

What must I do to make FrmMainMenu the initial form to lauch. Which provide menu options for the user to select and load other specific FORM.

Show WPF Window from any application via Com-Interop (OLE) Interface



I have a C# dll library which contains several utilities and WPF Windows.
I need to use these from an unmanaged application (actually written in Delphi 2009).
To do so I added an Ole interface to my dll.
In my initial call I start a thread and create an Application object in it whith its own Dispatcher.
Every time I need to show a WPF Window I do this by Invoking an the Applications thread.
This works so far, but seems to have a bit overhead when I try to open a WPF window for example.
Here is some of my code below:

  public interface IOleBridge
   bool Startup();

   void ShowWindow();

  // [ComSourceInterfaces(typeof(IOleBridgeEvents))]

Navigator to window application



i wanted to come up with the MDI window with tree navigator to the left. ie, tree navigator dock to the left of the MDI window. when i click on a item on the tree navigator, it should open a window to right of the navigator. when user maximize the newly opened window, it should dock to the empty space (ie, MDI window without navigator space). And user should be able to change the width of the navigator ( if newly opened window is dock, then it should change the width automatically )

i tried using splitter container (feel i should stick with this), i fixed the tree navigator to panel1 but i couldn't set the newly open window to panel2. And i wanted to dock the newly created window to Panel2.

please help me with this, it will be really useful if someone provide me with sample code.

im using c#




Export to Pdf needs to open in a new window other than the same application



I am using crystal reports 2008 with asp.net 3.5 to generate .pdf reports.

When I use the code below it exports the pdf file in the same application window. I hate this. I have to go back for getting another report.

I want this to be opened in a separate window so that users can still work on input parameter page.

RecDetrpt.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Context.Response, false, string.Empty);

RecDetrpt.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Context.Response, false, string.Empty);

I checked out some posts but I didn't get all. Please someone who has gone through this earlier can suggest me code to do this. Thanks in advance.


How to Restrict Windows Credentials Prompt Window for the Application


Hi All,

We have created an Intranet Web Application with Windows Authentication.

That asking a prompt to get Username and Password each time when we access the application.

How can we restrict that prompt other than IE --> Security --> Custom Level --> User Authentication. (Because, with this option we need to set these settings in each and every user's system)

Thanks in Advance,

Sateesh N.


Crystal Report load failed on Windows 7, VB.NET window application

I've a window application that load crystal report perfectly fine on Windows Vista. But when I tried to run the application on Windows 7, it gives me inconsistent behavior: sometimes the report will load, sometime I will just see the blue wheel, sometime it gives report load failed exception.

My application was developed with VS 2005 with Framework 2.0 and CR 10.
My Windows vista is install with framework 2.0, 3.0 and 3.5. 
Windows 7 is also came with 2.0, 3.0 and 3.5 by default.

I do notice one difference between Windows 7 and Vista. 
When a call is made to the report, a temp rpt is created in C:\Users\<user>\AppData\Local\Temp folder.
In Vista, no matter how many times the report is called in a session, only 1 rpt file will be created.
In Win 7, every call to the report will created 1 rpt file.
This is the only difference I see so far. Could this be the cause of report load failure? 
If so, what's the workaround?

An extract of my code as follow:


Slow startup of NET application if the computer is connected to LAN


Before first statement of Main method is executed my application hangs for 30 sec. If i disconnect computer from local network, this delay goes away.

I tried to profile with TCP View: my application does not open any connection. During delay svchost opens UDP connections from various ports (each application's start ports are different) (Remote address = *, Remote port = *) 

framework 3.5 Windows XP


Flash Object from a Website in Window's application


I have a website which plays songs. I am trying to create a window’s application which will play the song played in the website. I am using WebBrowser class to execute the website as follows in the Window’s application’s button’s click event:


WebBrowser wb1 = new WebBrowser();

Wb1.Navigate("http://www.123.com ");

Here the problem is if the website uses flash objects (http://www.123.com/songs.swf ) to play songs, I am not able to play the song from the website in my window’s application. How do I do this? Any help please.

Adjust application window size per screen resolution on different computers


I have built an  application which calls two dialog boxes defined in a .rc file.

When this application was run on a computer with a screen resolution of 600 x 800

the dialog boxes were not fully displayed.  How can I automatically adjust for different screen resolutions?

Access database in Window Application



Sorry if the question too simple - I am totally new in VS2010 :-(

I want the users read and write from/to access database.

I created a new window app and added the database through Add->Add New Source Data. Then I created a DataGridView and connected it to one of the tables.

It shows the correct data when I run the app, but any changes in the tables through Access are not visible on the app – it shows the original data all the time. The same thing happens if I want to make changes on the data through the app - the changes are not visible when I open Access.

Is it possible to create Window application in VS2010 and change the data both ways?


Microsoft's Collaborative Application Markup Language (CAML) Loop

discovered an interesting error recently while working with Microsoft's Collaborative Application Markup Language (CAML) that, surprisingly, had received no ink. Partly what surprises me about this is that the error may require you to rewrite large sections of your code if you haven't previously considered this SharePoint limitation. I'll start with some context, but first of all the error is:

Integrating a Legacy Web Application in SharePoint

This month we will continue with the theme of deploying Microsoft's SharePoint as a company intranet by describing a method for integrating a legacy Web application inside a SharePoint site.

In many companies the intranet site is not just a home page with announcements. It houses Web applications used by many different departments. In last month's article, I built a page to search the employee table in Northwind (the sample database included in Microsoft's SQL Server). This month, I will move the Web pages used to add/remove records from the table into the SharePoint intranet.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend