Application didnt work when launch without VS


hi

i compile 1 application , give focus window on basis of title . 1 strange thing face works ok when open in vs , press f5 particular window pops correctly , when launch double clikcking administrative previllage didnt pop window .

one more difference see when launch through vs in task massenger there 1 more application launch name of <program_name>.vshost.exe .

code of program this

using system;  using system.runtime.interopservices;  using system.threading;    namespace get_focus  {      class program      {              //import findwindow api find our window          [dllimportattribute("user32.dll")]          private static extern int findwindow(string classname, string windowname);            //import setforeground api activate          [dllimportattribute("user32.dll")]          private static extern intptr setforegroundwindow(int hwnd);          static void main(string[] args)          {                while (true)              {                  thread.sleep(2000);                  //find window, using correct window title, example, notepad                  int hwnd = findwindow(null, "notepad");                    if (hwnd > 0) //if found                  {                        setforegroundwindow(hwnd); //activate                  }                }          }      }  }  


if post helpful please mark right else feel free correct me

hi uahmed,

welcome msdn forum.

you can try sample below.

        [dllimport("user32")]         private static extern int setforegroundwindow(intptr hwnd);          // activate or minimize window          [dllimportattribute("user32.dll")]         private static extern bool showwindow(intptr hwnd, int ncmdshow);         private const int sw_show = 5;         private const int sw_minimize = 6;         private const int sw_restore = 9;            static void main(string[] args)         {             process[] proclist = process.getprocessesbyname("notepad");             if (proclist.length > 0)             {                 showwindow(proclist[0].mainwindowhandle, sw_restore);                 setforegroundwindow(proclist[0].mainwindowhandle);             }           }

have nice day.

bob shen [msft]
msdn community support | feedback us



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'