c# - How to stick my form to a window of a thirdparty application? -


i'm trying stick form window of application (let's microsoft outlook). when move outlook window, form should still stick @ right-hand side of it.

at moment, i'm monitoring outlook's position in while(true) loop (with sleep()) , adjusting form's position it.

here 2 problems:

  • if sleep() duration short, takes performance check outlook's position , adjust form often.
  • if sleep() duration long, form slow in adjusting outlook (it lags).

isn't there native solution this?

you have hook on process , listen event

this should give starting point

using system; using system.diagnostics; using system.runtime.interopservices; using system.windows.forms;  namespace windowsformsapplication1 {     public partial class form1 : form     {         private const uint winevent_outofcontext = 0x0000;         private const uint event_object_locationchange = 0x800b;          private const uint event_system_movesizestart = 0x000a;         private const uint event_system_movesizeend = 0x000b;          public form1()         {             initializecomponent();         }          private void form1_load(object sender, eventargs e)         {             this.width = 100;             this.height = 100;             this.topmost = true;             int processid = process.getprocessesbyname("outlook")[0].id;              //this triggered mouse moving on process windows             //nativemethods.setwineventhook(event_object_locationchange, event_object_locationchange, intptr.zero, wineventproc, (uint)processid, (uint)0, winevent_outofcontext);              nativemethods.setwineventhook(event_system_movesizestart, event_system_movesizeend, intptr.zero, wineventproc, (uint)processid, (uint)0, winevent_outofcontext);         }          private void wineventproc(intptr hwineventhook, uint eventtype, intptr hwnd, int idobject, int idchild, uint dweventthread, uint dwmseventtime)         {             rect move = new rect();              if (eventtype == event_system_movesizestart)             {                 nativemethods.getwindowrect(hwnd, ref move);                  debug.writeline("event_system_movesizestart");             }             else if (eventtype == event_system_movesizeend)             {                 nativemethods.getwindowrect(hwnd, ref move);                  debug.writeline("event_system_movesizeend");             }              this.left = move.left;             this.top = move.top;         }     }      public struct rect     {         public int left { get; set; }         public int top { get; set; }         public int right { get; set; }         public int bottom { get; set; }     }      static class nativemethods     {         [dllimport("user32.dll")]         public static extern intptr setwineventhook(uint eventmin, uint eventmax, intptr hmodwineventproc, wineventdelegate lpfnwineventproc, uint idprocess, uint idthread, uint dwflags);          public delegate void wineventdelegate(intptr hwineventhook, uint eventtype, intptr hwnd, int idobject, int idchild, uint dweventthread, uint dwmseventtime);          [dllimport("user32.dll")]         public static extern bool getwindowrect(intptr hwnd, ref rect rectangle);     } } 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -