473,756 Members | 9,160 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get window handle from point

I need to draw a dot where ever the user clicks (which will be on either
the form or a couple dynamically placed picture boxes). I thought the
following code should work:
//---
[DllImport("user 32.dll", EntryPoint = "WindowFromPoin t")]
static public extern IntPtr WindowFromPoint (System.Drawing .Point Point);
//...
h = (System.Drawing .Point)hits[iii]; // this is an array of Point
objects
ip = WindowFromPoint (h);
System.Diagnost ics.Trace.Write Line(ip.ToStrin g());
g = Graphics.FromHw nd(ip.Handle);
g.FillEllipse(b ,h.X,h.Y,20,20) ;
//---

but it seems to return sparatic results.
However the following code works consistantly

//---
//...
h = (System.Drawing .Point)hits[iii]; // this is an array of Point
objects
g = Graphics.FromHw nd(this.Handle) ; // <------------------- change
g.FillEllipse(b ,h.X,h.Y,20,20) ;
//---

The problem with the second code is that the dots are apparently drawn under
the picture box and cannot be seen. I need the dot to be top most so the
user can see it.
Thanks in advance,
~Logan
Nov 15 '05 #1
3 10053
You really need to take some time to learn about GDI+ in .Net, rather
than jumping through hoops to draw a simple ellipse. You'd probably have an
easier time using the Control.CreateG raphics object as well, so that you
could apply the ellipse directly to the control which has the mouse click.

Chris R.

"Logan McKinley" <lo***@globalwe b.net> wrote in message
news:#2******** ******@TK2MSFTN GP10.phx.gbl...
I need to draw a dot where ever the user clicks (which will be on either
the form or a couple dynamically placed picture boxes). I thought the
following code should work:
//---
[DllImport("user 32.dll", EntryPoint = "WindowFromPoin t")]
static public extern IntPtr WindowFromPoint (System.Drawing .Point Point);
//...
h = (System.Drawing .Point)hits[iii]; // this is an array of Point
objects
ip = WindowFromPoint (h);
System.Diagnost ics.Trace.Write Line(ip.ToStrin g());
g = Graphics.FromHw nd(ip.Handle);
g.FillEllipse(b ,h.X,h.Y,20,20) ;
//---

but it seems to return sparatic results.
However the following code works consistantly

//---
//...
h = (System.Drawing .Point)hits[iii]; // this is an array of Point
objects
g = Graphics.FromHw nd(this.Handle) ; // <------------------- change
g.FillEllipse(b ,h.X,h.Y,20,20) ;
//---

The problem with the second code is that the dots are apparently drawn under the picture box and cannot be seen. I need the dot to be top most so the
user can see it.
Thanks in advance,
~Logan

Nov 15 '05 #2
Max
As far as I understand it is a bad practice to draw something outside
OnPaint event handler.

Paint is initiated by the system and you have no guarantee system will not
call paint after you have your ellipse drawn and erase it.

If you do not have a possibility to modify the window's WM_PAINT event
handler (which is OnPaint for .NET controls) for some reason you may try to
use the following trick.

1. Place additional control over the control of your interest.
2. Draw additional graphics according to your business logic.
3. Make it (additional control) transparent by using Region property.

Good luck.

"Logan McKinley" <lo***@globalwe b.net> wrote in message
news:%2******** **********@TK2M SFTNGP10.phx.gb l...
I need to draw a dot where ever the user clicks (which will be on either
the form or a couple dynamically placed picture boxes). I thought the
following code should work:
//---
[DllImport("user 32.dll", EntryPoint = "WindowFromPoin t")]
static public extern IntPtr WindowFromPoint (System.Drawing .Point Point);
//...
h = (System.Drawing .Point)hits[iii]; // this is an array of Point
objects
ip = WindowFromPoint (h);
System.Diagnost ics.Trace.Write Line(ip.ToStrin g());
g = Graphics.FromHw nd(ip.Handle);
g.FillEllipse(b ,h.X,h.Y,20,20) ;
//---

but it seems to return sparatic results.
However the following code works consistantly

//---
//...
h = (System.Drawing .Point)hits[iii]; // this is an array of Point
objects
g = Graphics.FromHw nd(this.Handle) ; // <------------------- change
g.FillEllipse(b ,h.X,h.Y,20,20) ;
//---

The problem with the second code is that the dots are apparently drawn under the picture box and cannot be seen. I need the dot to be top most so the
user can see it.
Thanks in advance,
~Logan

Nov 15 '05 #3
The code snippet I gave is in a function called from OnPaint but I need to
call it at other times as well to add a point when the window is not being
repainted. I guess I could take everything out of the function and put it
just in the OnPaint and then invalidate the display, but I don't think that
would help my problem.

Unfortunately I cannot have transparent layers set on my application for
outside reasons. I am sorry, I don't think I explained my problem
effectively. I believe the real problem I am having is with the
ip = WindowFromPoint (h);
g = Graphics.FromHw nd(ip);
part of the code not working correctly. The reason I think that is because
when I use
This.Handle
in place of "ip" it will draw correctly on that window but not on the
others.

Thanks,
~Logan

"Max" <Pl****@reply.t o.news.group> wrote in message
news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..
As far as I understand it is a bad practice to draw something outside
OnPaint event handler.

Paint is initiated by the system and you have no guarantee system will not
call paint after you have your ellipse drawn and erase it.

If you do not have a possibility to modify the window's WM_PAINT event
handler (which is OnPaint for .NET controls) for some reason you may try to use the following trick.

1. Place additional control over the control of your interest.
2. Draw additional graphics according to your business logic.
3. Make it (additional control) transparent by using Region property.

Good luck.

"Logan McKinley" <lo***@globalwe b.net> wrote in message
news:%2******** **********@TK2M SFTNGP10.phx.gb l...
I need to draw a dot where ever the user clicks (which will be on either the form or a couple dynamically placed picture boxes). I thought the
following code should work:
//---
[DllImport("user 32.dll", EntryPoint = "WindowFromPoin t")]
static public extern IntPtr WindowFromPoint (System.Drawing .Point Point); //...
h = (System.Drawing .Point)hits[iii]; // this is an array of Point
objects
ip = WindowFromPoint (h);
System.Diagnost ics.Trace.Write Line(ip.ToStrin g());
g = Graphics.FromHw nd(ip.Handle);
g.FillEllipse(b ,h.X,h.Y,20,20) ;
//---

but it seems to return sparatic results.
However the following code works consistantly

//---
//...
h = (System.Drawing .Point)hits[iii]; // this is an array of Point
objects
g = Graphics.FromHw nd(this.Handle) ; // <------------------- change
g.FillEllipse(b ,h.X,h.Y,20,20) ;
//---

The problem with the second code is that the dots are apparently drawn

under
the picture box and cannot be seen. I need the dot to be top most so the user can see it.
Thanks in advance,
~Logan


Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
561
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum number of window handle, because if I reduce to about 2 instances of each window, it can run. But not 20 instances of each window. Does anyone know what the problem is? is it really because it exceeds the maximum number of window handle?
0
600
by: Matt Warner | last post by:
Hi guys, A couple of people have already posted questions about similar issues but haven't had any response. Occasionally, sometimes after running the app for a few hours, it bombs out saying that it could not create a windows handle. On one machine the stacktrace is this:
4
1934
by: Brad Jones | last post by:
<Previously posted in microsoft.public.dotnet.framework.windowsforms> Hi all. Any suggestions here would be appreciated. Thanks for reading. I'm primarly a C++ developer but I've been trying to complete development on a C# application with the following basic requirements: - The app runs in the background is initially hidden from the user, including the Windows Taskbar. - The app needs to receive a registered Windows message - The app...
2
1564
by: Simon Wigzell | last post by:
I use a subroutine to popup windows in my sebsite. It looks like this : function poplink(filename) { filestring = filename + "htm" LinkWindow = window.open(filestring,'LinkWindow',''); } Filename is just the extensionless web page name e.g. "Addresses"
1
3923
by: Arne | last post by:
Hi, I keep getting "Error creating window handle." now and then while running my C# application. I've tried to figure out why, but I'm stuck. What is the usual cause of this error ? The error occurs during a this.PointToScreen( newPos )-call, and "this" is referencing a instantiated Form class.... newPos is of class Point.
1
15842
by: Matt | last post by:
Hi I am looking for a way in C# to use a IntPtr handle to a (possibly unmanaged) windows form to get the current position of the window on the desktop. I have tried using Form.FromHandle( handle ) but this does not work for non .NET windows. I am expecting to need to use SendMessage somewhere along the line, but cannot find the correct message to get the window position. Also, is there a way to perform simple operations on a window...
4
25256
by: harvie wang | last post by:
Hi, I use API GetDesktopWindow to get desktop window handle and compare with WindowFromPoint(x,y) to get window handle. GetDesktopWindow return 65556 WindowFromPoint return 65700 but I use apy++ to get desktop window handle, it return 100A2 or 1000A4 why?
2
1313
by: Nathaniel | last post by:
I play an online game application that displays how many points I have earned throught my game play. I want the number of points I have earned to appear as a string in a text box in the program I am writing in VB.net. If I already knew the window handle, is there someway of accessing the I/O stream to find out my point status?
0
969
by: msdnuniv | last post by:
Hello! I have an application running since 2004 on win98 to Server 2003 SP1 and Vista without problems. But on Server 2003 with SP2 sometimes window handles of opened, but hidden windows disappear. If i try to show the window again, I get a System.Reflection.TargetInvocationException: Unable to get the window handle - the closing event of the form is _not_ called - i still can use functions and variables on this window. - i cannot...
0
2183
by: Sasie7679 | last post by:
Dear All, We have a requirement to open any document with a specific application and display it within a OCX control (Example - word, excel, adobe reader, MSPaint, Photoshop etc). We are using CreateProcess Api to open the application. This APi returns process id and process handle. Once the application is opened, i need the exact window handle to show within the container (OCX control). I use "EnumWindows" to enumerate all top level windows...
0
9287
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10046
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9886
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9857
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7259
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6542
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3817
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.