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

Prestashop custom hooks
tml_new_user_activated hook not working
Prestashop : Showing back-office custom tab content in product.tpl in front-office
gitolite post-receive hook not triggering
Using hooks to trigger a process
hooks to run different setup and clean for each test case in mocha
Is it possible to add a message in the listing of items in Prestashop?
Does Karma have an initialization hook?
Make hook local in emacs
SpecFlow - Retry failed tests
Gitolite hooks un responsive
WordPress Visual Editor Filter for Visual View
API hooking fails using JMP instruction
Selecting output lines in chunk output by modifying the default output hook
How to detect Windows suspend message?
Gerrit hooks can't execute after a period of time

Categories

HOME
cakephp
compiler-construction
osgi
variables
gitlab
wso2
proxy
fluentd
relative-path
grep
cplex
graphql
jpeg
ezpublish
flyway4
applepay
dacpac
offline
quicklook
remote-access
msp430
dosgi
after-effects
beyondcompare
google-cloud-speech
zurb-foundation-6
h2db
user-interaction
traffic
nhapi
facebook-apps
libssl
preg-match
caret
google-api-nodejs-client
file-format
bitbucket-pipelines
retina-display
hot-module-replacement
withings
c11
reportbuilder
sas-visual-analytics
hp-ux
powershell-dsc
glew
slick-3.0
qcombobox
executenonquery
babel-core
cubic-spline
skeleton-css-boilerplate
scrollable
atomicity
dandelion
blogengine.net
dropbox-php
dotnetzip
nstextview
darcs
csound
crypt
libusb-win32
django-scheduler
redundancy
word-vba-mac
google-feed-api
heidisql
file-writing
qpid
lttng
sdf
pickadate
apachebench
ipconfig
asp.net5
wso2cloud
wireshark-dissector
fouc
browser-bugs
drawbitmap
ionic
sonarqube5.1.2
inmobi
formatjs
camanjs
jscript.net
fpml
rdtsc
onactivityresult
starcluster
jubula
message-driven-bean
cloud-connect
html5-notifications
floating-point-precision
ivyde
commoncrypto
easy-install
android-hardware
path-separator
nsnetservice
propertyeditor
punbb
nsobject
data-loss
subgurim-maps
ecl
w3wp.exe
sproutcore-2
iweb
.net-1.0

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App