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 | |
15 | #include <windows.h> |
7fd59977 |
16 | |
1ce0716b |
17 | #include <WNT_WClass.hxx> |
18 | |
ad03c234 |
19 | #include <TCollection_ExtendedString.hxx> |
42cf5bc1 |
20 | #include <WNT_ClassDefinitionError.hxx> |
42cf5bc1 |
21 | #include <WNT_Window.hxx> |
7fd59977 |
22 | |
1ce0716b |
23 | #if defined(_WIN32) && !defined(OCCT_UWP) |
24 | |
ad03c234 |
25 | IMPLEMENT_STANDARD_RTTIEXT(WNT_WClass, Standard_Transient) |
92efcf78 |
26 | |
7fd59977 |
27 | //======================================================================= |
28 | //function : WNT_WClass |
ad03c234 |
29 | //purpose : |
7fd59977 |
30 | //======================================================================= |
ad03c234 |
31 | WNT_WClass::WNT_WClass (const TCollection_AsciiString& theClassName, |
32 | const Standard_Address theWndProc, |
33 | const WNT_Uint& theStyle, |
34 | const Standard_Integer theClassExtra, |
35 | const Standard_Integer theWindowExtra, |
36 | const Aspect_Handle theCursor, |
37 | const Aspect_Handle theIcon, |
38 | const TCollection_AsciiString& theMenuName) |
39 | : myClassName (theClassName), |
40 | myAppInstance (GetModuleHandleW (NULL)), |
41 | myWndProc (NULL) |
42 | { |
43 | const TCollection_ExtendedString aClassNameW (theClassName); |
44 | const TCollection_ExtendedString aMenuNameW (theMenuName); |
45 | WNDCLASSW aWinClass; |
46 | aWinClass.style = theStyle; |
47 | aWinClass.lpfnWndProc = theWndProc != NULL ? (WNDPROC )theWndProc : DefWindowProcW; |
48 | aWinClass.cbClsExtra = theClassExtra; |
49 | aWinClass.cbWndExtra = theWindowExtra; |
50 | aWinClass.hInstance = (HINSTANCE )myAppInstance; |
51 | aWinClass.hIcon = theIcon != NULL ? (HICON )theIcon : LoadIconW (NULL, IDI_APPLICATION); |
52 | aWinClass.hCursor = theCursor != NULL ? (HCURSOR )theCursor : LoadCursorW (NULL, IDC_NO); |
53 | aWinClass.hbrBackground = 0; |
54 | aWinClass.lpszMenuName = !aMenuNameW.IsEmpty() ? aMenuNameW.ToWideString() : NULL; |
55 | aWinClass.lpszClassName = aClassNameW.ToWideString(); |
56 | if (!RegisterClassW (&aWinClass)) |
57 | { |
58 | myClassName.Clear(); |
9775fa61 |
59 | throw WNT_ClassDefinitionError("Unable to register window class"); |
ad03c234 |
60 | } |
61 | myWndProc = (Standard_Address )aWinClass.lpfnWndProc; |
62 | } |
7fd59977 |
63 | |
64 | //======================================================================= |
e6f550da |
65 | //function : ~WNT_WClass |
ad03c234 |
66 | //purpose : |
7fd59977 |
67 | //======================================================================= |
ad03c234 |
68 | WNT_WClass::~WNT_WClass() |
7fd59977 |
69 | { |
ad03c234 |
70 | if (!myClassName.IsEmpty()) |
71 | { |
72 | const TCollection_ExtendedString aClassNameW (myClassName); |
73 | UnregisterClassW (aClassNameW.ToWideString(), (HINSTANCE )myAppInstance); |
74 | } |
75 | } |
7fd59977 |
76 | |
1ce0716b |
77 | #endif // _WIN32 |