Forum > Cocoa

macOS how to get window position?

<< < (2/3) > >>

trev:
0,0 is located at the bottom left, NOT the top left :-)

See: https://developer.apple.com/library/archive/documentation/General/Devpedia-CocoaApp-MOSX/CoordinateSystem.html

Key-Real:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure getGFXwindowPos(var x,y:longint);begin  x:=round(window.frame.origin.x);  y:=round(NSScreen.mainScreen.Frame.size.height-window.frame.origin.y);end; 
y is not correct :(

is NSScreen.mainScreen.Frame.size.height not the height of the whole screen?

trev:
This works for me (small adjustment to my program above):


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var   appName    : NSString;   window     : NSWindow;   myBadgeButton   : NSButton;   myUnBadgeButton : NSButton;   myDelegate : TMyDelegate;   myScreen : NSRect;   // addition procedure TMyDelegate.BadgeButtonClick(sender :  id);begin   NSApp.dockTile.setBadgeLabel(NSStr('12'));   myScreen := NSscreen.MainScreen.Frame;          // addition   NSLog(NSSTR(FloatToStr(myScreen.size.width)));  // addition   NSLog(NSSTR(FloatToStr(myScreen.size.height))); // additionend;

dbannon:
Er, forgive my ignorance of things Apple, but does this discussion mean that the usual 'top' and 'left' properties of a form do not give (or set) the top left of the form wrt the screen ?

Davo

trev:
The OP is not using the LCL, but pure Cocoa as you can see from my example program above.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version