How to push (unbury) Browser Window to Top to Occlude other windows


i have c# code spawns process using process.start display contents of html file in default browser.

there problem because new

  (1) window remains occluded (buried) underneath other windows.

  (2) new tab (inside browser) must top window.

i tried bing/google searching not find hits "pop top" or "occluded window".

here powershell script got powershell forum years ago , i've been using years display new web page. have translate c#? if so, have com handle instance of ie. what? how pop top?

is there easier way translating powershell script c#? hope so!

thanks

siegried

# find browser instance  $browserset = (new-object -comobject shell.application).windows() |  ? {$_.locationurl -like "http:*"}   if($browserset -ne $null)  {    $browser=$browserset[0].application    $browser.name    $ieset = $browserset | ? {$_.name -like "windows internet explorer"}    $ie = $ieset[0]  }else{    # can create new instance of ie    $ie = new-object -com internetexplorer.application  }      # create new tab  #$ie.navigate2("http://msdn.microsoft.com/en-us/data/jj205424", 2048)  $ie.navigate2("http://msdn.microsoft.com/en-us/data/jj193542", 2048)  $ie.visible=$true


siegfried heintze

this code works if there not many ie tabs already. when dozen tabs on ie, stops working. bug in windows? or bug in code? can me fix this?

here modified powershell works me 0 or several ie tabs:

# find browser instance $browserset = (new-object -comobject shell.application).windows() |  ? {$_.locationurl -like "http:*"}  if($browserset -ne $null) {   $browser=$browserset[0].application   $browser.name   $ieset = $browserset | ? {$_.name -like "internet explorer"}   $ie = $ieset[0] }else{   # can create new instance of ie   $ie = new-object -com internetexplorer.application }   # create new tab #$ie.navigate2("http://msdn.microsoft.com/en-us/data/jj205424", 2048) $ie.navigate2("http://msdn.microsoft.com/en-us/data/jj193542", 2048) $ie.visible=$true add-type @"   using system;   using system.runtime.interopservices;   public class tricks {      [dllimport("user32.dll")]      [return: marshalas(unmanagedtype.bool)]      public static extern bool setforegroundwindow(intptr hwnd);   } "@ $h = $ie.hwnd [void] [tricks]::setforegroundwindow($h) 

here translated c# code works me windows 10 , vs 2015 0 or several ie tabs. wow! verbose! can me make bit more terse using linq or lambdas or functional style programming?  

using system; using system.collections.generic; using system.linq; using system.text; using system.threading.tasks; using static system.console; namespace popupinternetexplorer {     class popupiemain     {         [system.runtime.interopservices.dllimport("user32.dll")]         [return: system.runtime.interopservices.marshalas(system.runtime.interopservices.unmanagedtype.bool)]         public static extern bool setforegroundwindow(intptr hwnd);         [system.runtime.interopservices.dllimport("user32.dll")]         [return: system.runtime.interopservices.marshalas(system.runtime.interopservices.unmanagedtype.bool)]         public static extern bool bringwindowtotop(intptr hwnd);         static void main(string[] args)         {             type shelltype = type.gettypefromprogid("shell.application");             dynamic shell = activator.createinstance(shelltype);             dynamic windows = shell.windows();             bool found = false;             int c = windows.count;             dynamic ie=null;             (int ii = 0; ii < c; ii++)             {                 if (system.text.regularexpressions.regex.match(windows.item(ii).locationurl, "^http://").success && system.text.regularexpressions.regex.match(windows.item(ii).name, "internet explorer").success)                 {                     found = true;                     ie = windows.item(ii);                     writeline(ie.locationurl);                     break;                 }             }             if (!found)             {                 type ietype = type.gettypefromprogid("internetexplorer.application");                 ie = activator.createinstance(ietype);             }             ie.navigate2("www.bing.com", 2048);             ie.visible = true;             intptr h = (intptr)ie.hwnd;             setforegroundwindow(h); // bringwindowtotop(h);         }     } } 


siegfried heintze



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'