hook


Detect when windows moves


I need to "dock", "snap", or "attach" my windows form to a window from a different process (not part of my application).
I have figured out how to get the correct window handle from the process name, and can move my form next to the desired window, but I can't quite figure out how to detect when the window moves so I can move my form to the new location beside the window that moved.
I have found lots of postings but all either have bugs that I cannot resolve, or don't quite match my scenario, or are incomplete. This is a little outside my skill set.
Here is the code for finding the desired window and moving my form next to it:
[
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace XXXXXXXX
{
public partial class Form1 : Form
{
private static Form1 frm;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string strClassName, string strWindowName);
[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle);
public struct Rect
{
public int Left { get; set; }
public int Top { get; set; }
public int Right { get; set; }
public int Bottom { get; set; }
}
private void Form1_Load(object sender, EventArgs e)
{
Process[] processes = Process.GetProcessesByName("XXXXXXX");
process = processes[0];
if (processes != null)
{
process = processes[0];
}
WindowLocation();
}
private void WindowLocation()
{
if (process != null)
{
// Get pointer to window
IntPtr ptr = process.MainWindowHandle;
// Get coordinates of window
Rect winRect = new Rect();
GetWindowRect(ptr, ref winRect);
// Display coordinates
tbTop.Text = winRect.Top.ToString();
tbRight.Text = winRect.Right.ToString();
tbBottom.Text = winRect.Bottom.ToString();
tbLeft.Text = winRect.Left.ToString();
this.Top = winRect.Top;
this.Left = (winRect.Left - 300);
}
}

Related Links

SpecRun hooks and testThreadCount > 1 not work properly
phpldapadmin user creation hook
Codeigniter Hooks helper and library
Prestashop hookActionProductUpdate Update not working in 1.7
Hooking all the active procs
What is the difference between ctx.end() and next()?
role assign after order complete in ubercart in drupal 8
In Pyramid, is there any kind of “hook” that occurs just before a view is called?
vBulletin: Variable in Threadbits not working
Sequelize 'afterValidate' hook does not change values
Function Hooking with C++
What is the difference between AspectJ And ASM?
Make a hook to be executed only on “onClick” button
How to use WHMCS hook to collect custom field and pass it to WHMCS bundle order pages?
Kubernetes postStart hook seems that blocks all the containers startup. Is that possible?
How to build Microsoft Detours Express Version 3.0?

Categories

HOME
date
oracle11g
deezer
pycharm
comparison
hashmap
iot
mean-stack
youtube-dl
maven-3
jpeg
gps
icloud
installshield
bs4
contact
circular-dependency
clearcase-ucm
uitypeeditor
serilog
apache-metamodel
jqwidget
beyondcompare
dbext
mmap
lcd
one-to-many
info.plist
filezilla
maxmind
spring-mybatis
typo3-6.2.x
elasticsearch-net
windows-server-2000
google-cloud-nl
gsmcomm
unboundid
r-raster
yadcf
commit
environment-modules
devextreme
multilingual
dynamics-crm-2013
withings
service-discovery
az-application-insights
trim
galen
powershell-dsc
midl
netcdf4
flashair
flickr-api
atomicity
promela
dandelion
statsd
elgg
sqlclient
nsarray
mcafee
spring-mongodb
query-performance
suffix-tree
pagerank
associative-array
energy
freelancer.com-api
tcpserver
embedded-code
deis
offloading
operator-precedence
phalanger
mdt
funcunit
rebol3
.aspxauth
aqtime
gwt-rpc
flashvars
trusted
bluepill
jspinclude
qtkit
asyncfileupload
gcj
site.master
.nettiers
substrings
zune
uiq3

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App