"Converting" Windows APIs to MacOS-APIs

Mac OSX specific forum
User avatar
jacdelad
Addict
Addict
Posts: 1436
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

"Converting" Windows APIs to MacOS-APIs

Post by jacdelad »

So,
I'm firm enough to use MSDN and a lot of Windows APIs (surely just a tiny bit, but that suits my additional needs). However, I'm absolutely not firm with Mac OSX. I am currently programming a Ribbon Menu (already shown in the German forum, but still under development), which uses a few Windows APIs. I would like to make it available on Mac OSX too, but I've never used it (and never will). So, what I've already learned, is that I need "CocoaMessage()" and I know a bare minimum about the syntax from the help. However, can someone please help me convert some Windows API calls into CocoaMessages?
Namely SHAppBarMessage_ (or another way to the height of the taskbar), GetModuleHandle_ (needed for Tooltips), CreateWindowEx_ (for creating ToolTips), DestroyWindow_ (for uncreating ToolTips), SendMessage_ (for a lot of messages, is this even possible?), GetWindowRect_/GetClientRect_ (maybe not really needed), SetWindowLong_/GetWindowLong_ (manipulating control parameters, maybe done in different way), SetWindowPos_ (maybe not needed), CreateRoundRectRgn_/SetWindowRgn_/DeleteObject_ (rounding window corners), SetParent_ (move a control into another window), MoveWindow_ (maybe not needed), GetCursorPos_/ScreenToClient_/ClientToScreen_ (converting coordinates, maybe doable in another way), IsWindowVisible_ (check if window is visible), GetForegroundWindow_ (determine active window (systemwide)), IsWindowEnabled_ (determine whether window is enabled oder not), IsIconic_ (determine whether window was minimized or not), GetObject_/GetIconInfo_/DestroyIcon_ (not really needed, just for shared objects maybe), GetSysColor_ (the only one I know).

I know that's a lot, but I also didn't find the right documentation to learn it myself. same goes with Linux, I'd relly like to add it to the compatibility list too (maybe even the Raspi).
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
deseven
Enthusiast
Enthusiast
Posts: 362
Joined: Wed Jan 12, 2011 3:48 pm
Location: Serbia
Contact:

Re: "Converting" Windows APIs to MacOS-APIs

Post by deseven »

Hi. The first thing you need to understand is that Windows, Linux and macOS are really different in many ways. You can't simply "convert" API calls, because usually the UI/API logic is different. Sometimes you can do something the way it's done in Windows, but that way you are simply transferring Windows UX and that can feel completely alien to Linux and macOS.

With that said, I'll post the ones I know :)
jacdelad wrote: Tue Dec 07, 2021 1:41 am SHAppBarMessage_ (or another way to the height of the taskbar)

Code: Select all

Debug CocoaMessage(0,CocoaMessage(0,CocoaMessage(0,0,"NSApplication sharedApplication"),"mainMenu"),"menuBarHeight")
jacdelad wrote: Tue Dec 07, 2021 1:41 am CreateRoundRectRgn_/SetWindowRgn_/DeleteObject_ (rounding window corners)
https://www.purebasic.fr/english/viewto ... 06#p427506
jacdelad wrote: Tue Dec 07, 2021 1:41 am GetCursorPos_

Code: Select all

Define cursor.CGPoint
CocoaMessage(@cursor,0,"NSEvent mouseLocation")
Debug cursor\x
Debug cursor\y
jacdelad wrote: Tue Dec 07, 2021 1:41 am GetSysColor_
https://github.com/fantaisie-software/p ... ns.pb#L209 + https://developer.apple.com/documentati ... guage=objc
BarryG
Addict
Addict
Posts: 3294
Joined: Thu Apr 18, 2019 8:17 am

Re: "Converting" Windows APIs to MacOS-APIs

Post by BarryG »

jacdelad wrote: Tue Dec 07, 2021 1:41 amGetCursorPos_()
DesktopMouseX() and DesktopMouseY() do this, for all OSes. No API conversion needed.
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: "Converting" Windows APIs to MacOS-APIs

Post by mk-soft »

macOS works very differently than Windows.
But there are many examples how to work with CocoaMessage. Is all Objective-C and therefore take the examples and functions (Objects).

Links:
Methods, Tips & Tricks
Dump Object Methods
https://developer.apple.com/documentation/

Example with colors

Code: Select all

Procedure NSColorByNameToRGB(NSColorName.s)
  Protected.cgfloat red, green, blue
  Protected nscolorspace, rgb
  nscolorspace = CocoaMessage(0, CocoaMessage(0, 0, "NSColor " + NSColorName), "colorUsingColorSpaceName:$", @"NSCalibratedRGBColorSpace")
  If nscolorspace
    CocoaMessage(@red, nscolorspace, "redComponent")
    CocoaMessage(@green, nscolorspace, "greenComponent")
    CocoaMessage(@blue, nscolorspace, "blueComponent")
    rgb = RGB(red * 255.0, green * 255.0, blue * 255.0)
    ProcedureReturn rgb
  EndIf
EndProcedure

color = NSColorByNameToRGB("controlTextColor")
Debug Hex(color)

color = NSColorByNameToRGB("controlBackgroundColor")
Debug Hex(color)

color = NSColorByNameToRGB("systemGrayColor")
Debug Hex(color)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
jacdelad
Addict
Addict
Posts: 1436
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: "Converting" Windows APIs to MacOS-APIs

Post by jacdelad »

Ah, thanks to all of you. This is already something I'm able to work with. I'll read through all the basics and try my best. Maybe I should also use a virtual machine, that should make it easier.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Post Reply