Integration of OCCT 6.5.0 from SVN
[occt.git] / src / Draw / MainWindow.cxx
1 // File:        MainWindow.cxx
2 // Created:     Thu Aug  6 10:00:35 1998
3 // Author:      Administrateur Atelier MDL
4 //              <mdl@efalakox.paris1.matra-dtv.fr>
5
6
7
8 #ifdef WNT
9
10
11 #include <windows.h>
12 #include <DrawRessource.h>
13 #include <init.h>
14 #include <MainWindow.h>
15 #include <Draw_Window.hxx>
16 #include <CommandWindow.h>
17
18 Standard_Boolean Draw_Interprete(char* command); // Implemente dans Draw.cxx
19 extern Standard_Boolean Draw_IsConsoleSubsystem;
20
21 //extern "C" int  compat_unlink(const char *fname); // Implemente dans TCL
22
23 /*--------------------------------------------------------*\
24 |  CLIENT WINDOW PROCEDURE
25 |
26 |
27 \*--------------------------------------------------------*/
28 LONG APIENTRY WndProc(HWND hWndFrame, UINT wMsg, WPARAM wParam, LONG lParam )
29 {
30   HWND hWndClient;      
31   switch(wMsg)
32   {
33     case WM_CREATE :
34       {
35         CreateProc(hWndFrame);                                  
36         hWndClient = (HWND)GetWindowLong(hWndFrame, CLIENTWND);
37         DrawWindow::hWndClientMDI = hWndClient;
38         if (!Draw_IsConsoleSubsystem)
39           CreateCommandWindow(hWndFrame,0);                                     
40       }
41       break;
42
43     case WM_COMMAND :
44       CommandProc(hWndFrame, wParam, lParam);
45       break;
46       
47     case WM_DESTROY :
48       Draw_Interprete("exit");
49       DestroyProc(hWndFrame);                                                           
50       break;
51
52     default :
53       hWndClient = (HWND)GetWindowLong(hWndFrame, CLIENTWND);
54       return(DefFrameProc(hWndFrame, hWndClient, wMsg, wParam, lParam));
55   }
56   return(0l);
57 }
58
59
60 /*--------------------------------------------------------------------------*\
61 |  CLIENT CREATE PROCEDURE
62 |     Handler pour le message WM_CREATE. Creation de la fenetre de control MDI
63 |
64 \*--------------------------------------------------------------------------*/
65 BOOL CreateProc(HWND hWndFrame)
66 {
67   HWND hWnd;
68
69   // Enregistre le hWnd dans la fenetre principale dans extra memory en 0
70   if (hWnd = CreateMDIClientWindow(hWndFrame))
71     SetWindowLong(hWndFrame, CLIENTWND, (LONG)hWnd);
72   return(TRUE);
73 }
74
75
76 /*--------------------------------------------------------------------------*\
77 |  COMMAND PROCEDURE
78 |               Handler pour le message WM_COMMAND   
79 |
80 \*--------------------------------------------------------------------------*/
81 BOOL CommandProc(HWND hWndFrame, WPARAM wParam, LPARAM lParam)
82 {
83   HWND hWndClient; // Handle sur la fenetre MDI
84   HWND hWndActive;
85
86         hWndClient = (HWND)GetWindowLong(hWndFrame, CLIENTWND);
87   switch (LOWORD(wParam))
88         {
89           case IDM_WINDOW_NEXT :
90                                         if(hWndClient = (HWND)GetWindowLong(hWndFrame, CLIENTWND))
91                                           hWndActive = (HWND)SendMessage(hWndClient, WM_MDIGETACTIVE, 0, 0l);
92                                                 SendMessage(hWndClient, WM_MDINEXT, (WPARAM)hWndActive, 0l);  
93                                         break;
94
95                 case IDM_WINDOW_CASCADE :
96                                         if(hWndClient = (HWND)GetWindowLong(hWndFrame, CLIENTWND))
97                                                 SendMessage(hWndClient, WM_MDICASCADE, 0, 0l);
98                                         break;
99                                          
100                 case IDM_WINDOW_TILEHOR :
101                                         if(hWndClient = (HWND)GetWindowLong(hWndFrame, CLIENTWND))
102                                                 SendMessage(hWndClient, WM_MDITILE, MDITILE_HORIZONTAL, 0l);
103                                         break;
104
105                 case IDM_WINDOW_TILEVERT :
106                                         if(hWndClient = (HWND)GetWindowLong(hWndFrame, CLIENTWND))
107                                                 SendMessage(hWndClient, WM_MDITILE, MDITILE_VERTICAL, 0l);
108                                         break;
109                 
110                 case IDM_FILE_EXIT :
111                                         Draw_Interprete("exit");
112                                         //compat_unlink(NULL);
113
114                                         DestroyProc(hWndFrame);
115                                         break;
116         }
117   return(TRUE);
118 }
119
120
121 /*--------------------------------------------------------------------------*\
122 |  CLIENT DESTROY PROCEDURE
123 |     Handler pour le message WM_DESTROY.
124 |
125 \*--------------------------------------------------------------------------*/
126 VOID DestroyProc(HWND hWnd)
127 {
128 #ifndef _WIN64
129   HINSTANCE hInst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);
130 #else
131   HINSTANCE hInst = (HINSTANCE)GetWindowLong(hWnd, GWLP_HINSTANCE);
132 #endif
133   Destroy_Appli(hInst);
134   PostQuitMessage(0);
135 }
136 #endif
137