/* * Copyright (c) 2022 Jonathan Schleifer * * All rights reserved. * * This file is part of Obj3DEngine. It may be distributed under the terms of * the Q Public License 1.0, which can be found in the file LICENSE.QPL * included in the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of * this file. */ #import "O3DWinAPIWindow.h" #ifdef OF_WINDOWS # include @implementation O3DWinAPIWindow @synthesize hWnd = _hWnd; - (instancetype)initWithSize: (OFSize)size { self = [super init]; @try { _wndClass = (WNDCLASS){ .lpfnWndProc = (WNDPROC)DefWindowProc, .hInstance = GetModuleHandle(NULL), .lpszClassName = "O3DMainWindowClass" }; if (!RegisterClass(&_wndClass)) @throw [OFInitializationFailedException exceptionWithClass: self.class]; if ((_hWnd = CreateWindowEx(WS_EX_APPWINDOW, _wndClass.lpszClassName, "O3DMainWindow", WS_OVERLAPPED, CW_USEDEFAULT, CW_USEDEFAULT, size.width, size.height, NULL, NULL, _wndClass.hInstance, NULL)) == NULL) @throw [OFInitializationFailedException exceptionWithClass: self.class]; ShowWindow(_hWnd, SW_NORMAL); UpdateWindow(_hWnd); } @catch (id e) { [self release]; @throw e; } return self; } - (instancetype)init { OF_INVALID_INIT_METHOD } - (void)dealloc { if (_hWnd != NULL) OFEnsure(DestroyWindow(_hWnd)); if (_wndClass.lpszClassName != NULL) OFEnsure(UnregisterClass( _wndClass.lpszClassName, _wndClass.hInstance)); [super dealloc]; } @end #endif