I am writing a program to create a window on WinAPI. And there was a problem with creating a cursor (which is why the window have busy cursor when launched). There should be a macro, but Swift does not support it
My creation function
func registerClass(name: LPCSTR) {
var wndClass = WNDCLASSEXA()
wndClass.cbSize = UINT(MemoryLayout<WNDCLASSEXA>.size)
wndClass.style = UINT(CS_HREDRAW | CS_VREDRAW)
wndClass.lpfnWndProc = WindowProc
wndClass.cbClsExtra = 0
wndClass.cbWndExtra = 0
wndClass.hInstance = hInstance
wndClass.hIcon = LoadIconA(nil, "32512")
wndClass.hCursor = LoadCursorA(nil, "32512")
wndClass.hbrBackground = CreateSolidBrush(0x00d9d9d9)
wndClass.lpszMenuName = nil
wndClass.lpszClassName = name
wndClass.hIconSm = nil
guard RegisterClassExA(&wndClass) != 0 else {
print("can't register class\n \(GetLastError())")
return
}
}
Problem in this strings
wndClass.hIcon = LoadIconA(nil, "32512")
wndClass.hCursor = LoadCursorA(nil, "32512")
Its normal (c/c++) must be like this
wndClass.hIcon = LoadIconA(nullptr, IDI_APPLICATION);
wndClass.hCursor = LoadCursorA(nullptr, IDC_ARROW);
But IDI_APPLICATION
and IDC_ARROW
is macro then mean MAKEINTRESOURCE(32512)
and next MAKEINTRESOURCE(i) ((LPSTR)((ULONG_PTR)((WORD)(i))))
With string code compile and work but window is busy and clas no have cursor.
Function has prototype
public func LoadCursorA(_ hInstance: HINSTANCE!, _ lpCursorName: LPCSTR!) -> HCURSOR!
but use function argument how with class name (in func registerClass(name: LPCSTR)
) not working
Need for solution convert Int32 number 32512
to UnsafePointer<Int8>!
This not working
"32512".withCString{ ... }