Page 1 of 1

"Converting" Windows APIs to MacOS-APIs

Posted: Tue Dec 07, 2021 1:41 am
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).

Re: "Converting" Windows APIs to MacOS-APIs

Posted: Tue Dec 07, 2021 9:52 am
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

Re: "Converting" Windows APIs to MacOS-APIs

Posted: Tue Dec 07, 2021 10:10 am
by BarryG
jacdelad wrote: Tue Dec 07, 2021 1:41 amGetCursorPos_()
DesktopMouseX() and DesktopMouseY() do this, for all OSes. No API conversion needed.

Re: "Converting" Windows APIs to MacOS-APIs

Posted: Tue Dec 07, 2021 10:49 am
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)

Re: "Converting" Windows APIs to MacOS-APIs

Posted: Wed Dec 08, 2021 2:00 am
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.