Thread View: borland.public.cppbuilder.nativeapi
12 messages
12 total messages
Started by Helmut Giese
Mon, 03 Apr 2006 22:06
How to get a window's coordinates?
Author: Helmut Giese
Date: Mon, 03 Apr 2006 22:06
Date: Mon, 03 Apr 2006 22:06
9 lines
1010 bytes
1010 bytes
Hello out there, having been away from Windows GUI development for a rather long time it seems like I forgot most of the few things I used to know. :( Given a window's HWND, how do I obtain its current position/coordinates on the screen? Any information will be greatly appreciated. Best regards Helmut Giese
Re: How to get a window's coordinates?
Author: Remy Lebeau (TeamB)
Date: Mon, 03 Apr 2006 22:43
Date: Mon, 03 Apr 2006 22:43
12 lines
1185 bytes
1185 bytes
"Helmut Giese" <hgiese@ratiosoft.com> wrote in message news:44319b6a.32745546@forums.borland.com... > Given a window's HWND, how do I obtain its current > position/coordinates on the screen? Use the GetWindowRect() function. If the HWND is a child of another HWND, then you need to also use ClientToScreen() or MapWindowPoints() as well. Gambit
Re: How to get a window's coordinates?
Author: Helmut Giese
Date: Tue, 04 Apr 2006 09:44
Date: Tue, 04 Apr 2006 09:44
19 lines
1550 bytes
1550 bytes
On Mon, 3 Apr 2006 15:43:11 -0700, "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote: > >"Helmut Giese" <hgiese@ratiosoft.com> wrote in message >news:44319b6a.32745546@forums.borland.com... > >> Given a window's HWND, how do I obtain its current >> position/coordinates on the screen? > >Use the GetWindowRect() function. If the HWND is a child of another HWND, >then you need to also use ClientToScreen() or MapWindowPoints() as well. Hi Gambit, thanks a lot. Don't know what I was looking at in the help last night but I didn't see it. Hm, child window? I am interested in the coordinates of a menu once it is posted. Well, I'll find out if it is a child or not. Thanks and best regards Helmut Giese
Re: How to get a window's coordinates?
Author: Remy Lebeau (TeamB)
Date: Tue, 04 Apr 2006 17:47
Date: Tue, 04 Apr 2006 17:47
10 lines
1247 bytes
1247 bytes
"Helmut Giese" <hgiese@ratiosoft.com> wrote in message news:44323f3e.1124992@forums.borland.com... > I am interested in the coordinates of a menu once it is posted. You can't get the HWND of a menu. That is private to the OS's internals. Gambit
Re: How to get a window's coordinates?
Author: Helmut Giese
Date: Tue, 04 Apr 2006 20:00
Date: Tue, 04 Apr 2006 20:00
24 lines
1905 bytes
1905 bytes
On Tue, 4 Apr 2006 10:47:59 -0700, "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote: > >"Helmut Giese" <hgiese@ratiosoft.com> wrote in message >news:44323f3e.1124992@forums.borland.com... > >> I am interested in the coordinates of a menu once it is posted. > >You can't get the HWND of a menu. That is private to the OS's internals. Hi Gambit, don't make me nervous, please :) I found the function GetMenuItemRect which looks promising - though I have to admit that I am still fighting to come to grips with menus, and it's not clear who is going to win. Hm, I want to add some kind of tooltip to any menu a user selects, so I'd better find out where the currently active menu is situated on the screen. Do you thing there is any possibilty to achieve what I'm after? Thanks and best regards Helmut Giese
Re: How to get a window's coordinates?
Author: Remy Lebeau (TeamB)
Date: Tue, 04 Apr 2006 21:55
Date: Tue, 04 Apr 2006 21:55
31 lines
2232 bytes
2232 bytes
"Helmut Giese" <hgiese@ratiosoft.com> wrote in message news:4432cef6.24197000@forums.borland.com... > I found the function GetMenuItemRect which looks promising That will only tell you the screen coordinates of a particular menu item that is visible onscreen, but you still can't get the HWND for that item. Plus, the call requires you to already know ahead of time the HWND of the parent window and the HMENU of the menu that the item belongs to. > I have to admit that I am still fighting to come to grips with > menus, and it's not clear who is going to win. What EXACTLY are you trying to accomplish in the first place? > Hm, I want to add some kind of tooltip to any menu a user selects, Menus don't have tooltips. They only have hints, which are not the same thing. > I'd better find out where the currently active menu is situated on the screen. There are no API functions for finding the active menu. The only way to know which menu is active is if you are displaying the menu yourself to begin with. If you are not, then there is nothing available to tell you which menu of which external application is active, if any. Gambit
Re: How to get a window's coordinates?
Author: Helmut Giese
Date: Wed, 05 Apr 2006 16:01
Date: Wed, 05 Apr 2006 16:01
44 lines
2903 bytes
2903 bytes
On Tue, 4 Apr 2006 14:55:13 -0700, "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote: Hi Gambit, >What EXACTLY are you trying to accomplish in the first place? > As I said, I want to add some kind of tooltip to any menu a user selects. My users don't read manuals and they don't know to look at the status bar (which is where normally this kind of help is dsplayed). So I thought it would be a cool idea to provide this kind of help - sort of pushing some information onto the user (ok, they'll get the option of turning it off). >Menus don't have tooltips. They only have hints, which are not the same >thing. Yes I know, I just thought it would be worth a try. > >> I'd better find out where the currently active menu is situated on the >screen. > >There are no API functions for finding the active menu. The only way to >know which menu is active is if you are displaying the menu yourself to >begin with. If you are not, then there is nothing available to tell you >which menu of which external application is active, if any. Well, maybe the situation is not as hopeless then. Some background info: The app is written in Tcl/Tk and _Tk_ is handling the menus itself (playing around with GetMenuItemInfo I found the style 'owner drawn'). I can attach a (Tcl) callback function which gets activated whenever a menu is posted, and there I can even retrieve the active item's index - all on the Tcl level. I just cannot get the coordinates. Now, if you cannot do something from the Tcl level, you always have the option of implementing the missing functionality in C (on the Tcl side this is called an extension) and then call it like any other command. So, in my (Tcl) callback function I have access to a - in Tcl speak - a widget: something I can obtain a hWnd of. I just don't get the needed positional information from there. Well, needs some more experiments :( Thanks and best regards Helmut Giese
Re: How to get a window's coordinates?
Author: Bob Gonder
Date: Wed, 05 Apr 2006 18:11
Date: Wed, 05 Apr 2006 18:11
15 lines
1630 bytes
1630 bytes
Helmut Giese wrote:
>Well, needs some more experiments :(
You might try iterating the client window with
for( point.x=10; x<MaxClient.x-10; point.x+=10 )
for( point.y=10; x<MaxClient.y-10; point.y+=10 )
if( (menuitem = MenuItemFromPoint( hwnd, hmenu, point )) != -1 )
{ //We have menu item number menuitem at location point
if( menuitem == menuitemwewant )
{ // we have a point within the item we want
}
}
Re: How to get a window's coordinates?
Author: Helmut Giese
Date: Wed, 05 Apr 2006 20:12
Date: Wed, 05 Apr 2006 20:12
35 lines
2246 bytes
2246 bytes
On Wed, 05 Apr 2006 11:11:46 -0700, Bob Gonder
<notbg@notmindspring.invalid> wrote:
>Helmut Giese wrote:
>
>>Well, needs some more experiments :(
>
>You might try iterating the client window with
>
> for( point.x=10; x<MaxClient.x-10; point.x+=10 )
> for( point.y=10; x<MaxClient.y-10; point.y+=10 )
>
> if( (menuitem = MenuItemFromPoint( hwnd, hmenu, point )) != -1 )
> { //We have menu item number menuitem at location point
> if( menuitem == menuitemwewant )
> { // we have a point within the item we want
> }
> }
Hi Bob,
thanks for the idea, but my problem is just that I don't have a
'hmenu' (and neither the hwnd to go with it).
I have some window managed by Tk (it's a window because I can get its
hwnd). It's not a menu ('IsMenu' says no), it does not _have_ a menu
(GetMenu returns 0), it doesn't have a parent (GetParent says so) - I
figured maybe this thing I have is a child of someone else - but I can
query it e.g. for its active index.
A bit weird. For the moment I ran out of ideas what ot try next, so
the project is put on hold. Hm, I _knew_ why I wrote a bit earlier in
this thread
it's not clear who is going to win
Best regards
Helmut Giese
Re: How to get a window's coordinates?
Author: Bob Gonder
Date: Thu, 06 Apr 2006 01:25
Date: Thu, 06 Apr 2006 01:25
17 lines
1824 bytes
1824 bytes
Helmut Giese wrote: >> if( (menuitem = MenuItemFromPoint( hwnd, hmenu, point )) != -1 ) > >thanks for the idea, but my problem is just that I don't have a >'hmenu' (and neither the hwnd to go with it). Well. the hmenu might be a problem, but you go on to say you do have the hwnd... >I have some window managed by Tk (it's a window because I can get its >hwnd). >A bit weird. Might be that Tk emulates menus in a portable (Non-MS) way. If so, then looking at the Tk source might be in your future.
Re: How to get a window's coordinates?
Author: Helmut Giese
Date: Thu, 06 Apr 2006 09:15
Date: Thu, 06 Apr 2006 09:15
29 lines
2168 bytes
2168 bytes
On Wed, 05 Apr 2006 18:25:46 -0700, Bob Gonder <notbg@notmindspring.invalid> wrote: Hi Bob, >>> if( (menuitem = MenuItemFromPoint( hwnd, hmenu, point )) != -1 ) >> >>thanks for the idea, but my problem is just that I don't have a >>'hmenu' (and neither the hwnd to go with it). > >Well. the hmenu might be a problem, but you go on to say you do have >the hwnd... I have _a_ hwnd but it isn't a menu (IsMenu returns 0) and it doesn't _have_ a menu either, so I don't relly know what to do with it. > >>I have some window managed by Tk (it's a window because I can get its >>hwnd). > >>A bit weird. > >Might be that Tk emulates menus in a portable (Non-MS) way. >If so, then looking at the Tk source might be in your future. Yes, that's the nice thing about open source. I didn't do it so far, because modifying Tk isn't all that attractive: - I could break some other code and - I would have to apply those patches to every new version For the moment I let Windows win :( Best regards Helmut Giese
Re: How to get a window's coordinates?
Author: Bob Gonder
Date: Thu, 06 Apr 2006 21:52
Date: Thu, 06 Apr 2006 21:52
26 lines
2337 bytes
2337 bytes
Helmut Giese wrote: >On Wed, 05 Apr 2006 18:25:46 -0700, Bob Gonder > >>>> if( (menuitem = MenuItemFromPoint( hwnd, hmenu, point )) != -1 ) >>> >>>thanks for the idea, but my problem is just that I don't have a >>>'hmenu' (and neither the hwnd to go with it). >> >>Well. the hmenu might be a problem, but you go on to say you do have >>the hwnd... >I have _a_ hwnd but it isn't a menu (IsMenu returns 0) That functions doesn't take a menu hwnd, it takes the hwnd of the form that has the menu. (But you still don't have the hmenu, so still can't use it) >Yes, that's the nice thing about open source. I didn't do it so far, >because modifying Tk isn't all that attractive: You might not need to modify Tk. It might be sufficient to know *how* Tk produces the menu effect so you can knowledgabley do your thing. >- I would have to apply those patches to every new version Or submit them for inclusion. It is OS after all.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads