0029564: STEP Import and Export failure
[occt.git] / src / WNT / WNT_WClass.cxx
CommitLineData
b311480e 1// Copyright (c) 1996-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 6// This library is free software; you can redistribute it and/or modify it under
7// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 8// by the Free Software Foundation, with special exception defined in the file
9// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10// distribution for complete text of the license and disclaimer of any warranty.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
7fd59977 14
cf4bee7c 15#if defined(_WIN32)
16 #include <windows.h>
17#endif
7fd59977 18
1ce0716b 19#include <WNT_WClass.hxx>
20
ad03c234 21#include <TCollection_ExtendedString.hxx>
42cf5bc1 22#include <WNT_ClassDefinitionError.hxx>
42cf5bc1 23#include <WNT_Window.hxx>
7fd59977 24
1ce0716b 25#if defined(_WIN32) && !defined(OCCT_UWP)
26
ad03c234 27IMPLEMENT_STANDARD_RTTIEXT(WNT_WClass, Standard_Transient)
92efcf78 28
7fd59977 29//=======================================================================
30//function : WNT_WClass
ad03c234 31//purpose :
7fd59977 32//=======================================================================
ad03c234 33WNT_WClass::WNT_WClass (const TCollection_AsciiString& theClassName,
34 const Standard_Address theWndProc,
896faa72 35 const unsigned int theStyle,
ad03c234 36 const Standard_Integer theClassExtra,
37 const Standard_Integer theWindowExtra,
38 const Aspect_Handle theCursor,
39 const Aspect_Handle theIcon,
40 const TCollection_AsciiString& theMenuName)
41: myClassName (theClassName),
42 myAppInstance (GetModuleHandleW (NULL)),
43 myWndProc (NULL)
44{
45 const TCollection_ExtendedString aClassNameW (theClassName);
46 const TCollection_ExtendedString aMenuNameW (theMenuName);
47 WNDCLASSW aWinClass;
896faa72 48 aWinClass.style = (UINT)theStyle;
ad03c234 49 aWinClass.lpfnWndProc = theWndProc != NULL ? (WNDPROC )theWndProc : DefWindowProcW;
50 aWinClass.cbClsExtra = theClassExtra;
51 aWinClass.cbWndExtra = theWindowExtra;
52 aWinClass.hInstance = (HINSTANCE )myAppInstance;
c85a994a 53 aWinClass.hIcon = theIcon != NULL ? (HICON )theIcon : LoadIcon (NULL, IDI_APPLICATION);
54 aWinClass.hCursor = theCursor != NULL ? (HCURSOR )theCursor : LoadCursor (NULL, IDC_NO);
ad03c234 55 aWinClass.hbrBackground = 0;
56 aWinClass.lpszMenuName = !aMenuNameW.IsEmpty() ? aMenuNameW.ToWideString() : NULL;
57 aWinClass.lpszClassName = aClassNameW.ToWideString();
58 if (!RegisterClassW (&aWinClass))
59 {
60 myClassName.Clear();
9775fa61 61 throw WNT_ClassDefinitionError("Unable to register window class");
ad03c234 62 }
63 myWndProc = (Standard_Address )aWinClass.lpfnWndProc;
64}
7fd59977 65
66//=======================================================================
e6f550da 67//function : ~WNT_WClass
ad03c234 68//purpose :
7fd59977 69//=======================================================================
ad03c234 70WNT_WClass::~WNT_WClass()
7fd59977 71{
ad03c234 72 if (!myClassName.IsEmpty())
73 {
74 const TCollection_ExtendedString aClassNameW (myClassName);
75 UnregisterClassW (aClassNameW.ToWideString(), (HINSTANCE )myAppInstance);
76 }
77}
7fd59977 78
1ce0716b 79#endif // _WIN32