ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

console.c
Go to the documentation of this file.
00001 /*
00002  * ReactOS Management Console
00003  * Copyright (C) 2006 - 2007 Thomas Weidenmueller
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Lesser General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public
00016  * License along with this library; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00020 #include "precomp.h"
00021 
00022 static const TCHAR szMMCMainFrame[] = TEXT("MMCMainFrame");
00023 static const TCHAR szMMCChildFrm[] = TEXT("MMCChildFrm");
00024 
00025 static LONG MainFrameWndCount = 0;
00026 static ULONG NewConsoleCount = 0;
00027 
00028 static LPTSTR
00029 CreateNewConsoleTitle(VOID)
00030 {
00031     LPTSTR lpTitle;
00032 
00033     if (LoadAndFormatString(hAppInstance,
00034                             IDS_CONSOLETITLE,
00035                             &lpTitle,
00036                             ++NewConsoleCount) == 0)
00037     {
00038         lpTitle = NULL;
00039     }
00040 
00041     return lpTitle;
00042 }
00043 
00044 typedef struct _CONSOLE_MAINFRAME_WND
00045 {
00046     HWND hwnd;
00047     LPCTSTR lpConsoleTitle;
00048     HMENU hMenuConsoleRoot;
00049     union
00050     {
00051         DWORD Flags;
00052         struct
00053         {
00054             DWORD AppAuthorMode : 1;
00055         };
00056     };
00057 } CONSOLE_MAINFRAME_WND, *PCONSOLE_MAINFRAME_WND;
00058 
00059 static LRESULT CALLBACK
00060 ConsoleMainFrameWndProc(IN HWND hwnd,
00061                         IN UINT uMsg,
00062                         IN WPARAM wParam,
00063                         IN LPARAM lParam)
00064 {
00065     PCONSOLE_MAINFRAME_WND Info;
00066     LRESULT Ret = FALSE;
00067 
00068     Info = (PCONSOLE_MAINFRAME_WND)GetWindowLongPtr(hwnd,
00069                                                     0);
00070 
00071     if (Info != NULL || uMsg == WM_NCCREATE)
00072     {
00073         switch (uMsg)
00074         {
00075             case WM_COMMAND:
00076             {
00077                 switch (LOWORD(wParam))
00078                 {
00079                     case ID_FILE_EXIT:
00080                         PostMessage(hwnd,
00081                                     WM_CLOSE,
00082                                     0,
00083                                     0);
00084                         break;
00085                 }
00086                 break;
00087             }
00088 
00089             case WM_NCCREATE:
00090             {
00091                 MainFrameWndCount++;
00092 
00093                 Info = HeapAlloc(hAppHeap,
00094                                  0,
00095                                  sizeof(*Info));
00096                 if (Info != NULL)
00097                 {
00098                     ZeroMemory(Info,
00099                                sizeof(*Info));
00100 
00101                     Info->hwnd = hwnd;
00102 
00103                     SetWindowLongPtr(hwnd,
00104                                      0,
00105                                      (LONG_PTR)Info);
00106 
00107                     Info->hMenuConsoleRoot = LoadMenu(hAppInstance,
00108                                                       MAKEINTRESOURCE(IDM_CONSOLEROOT));
00109                     Ret = TRUE;
00110                 }
00111                 break;
00112             }
00113 
00114             case WM_CREATE:
00115             {
00116                 LPCTSTR lpFileName = (LPCTSTR)(((LPCREATESTRUCT)lParam)->lpCreateParams);
00117 
00118                 if (lpFileName != NULL)
00119                 {
00120                     /* FIXME */
00121                 }
00122                 else
00123                 {
00124                     Info->AppAuthorMode = TRUE;
00125                     Info->lpConsoleTitle = CreateNewConsoleTitle();
00126                 }
00127 
00128                 SetWindowText(Info->hwnd,
00129                               Info->lpConsoleTitle);
00130                 break;
00131             }
00132 
00133             case WM_NCDESTROY:
00134                 SetMenu(Info->hwnd,
00135                         NULL);
00136 
00137                 if (Info->hMenuConsoleRoot != NULL)
00138                 {
00139                     DestroyMenu(Info->hMenuConsoleRoot);
00140                     Info->hMenuConsoleRoot = NULL;
00141                 }
00142 
00143                 HeapFree(hAppHeap,
00144                          0,
00145                          Info);
00146 
00147                 if (--MainFrameWndCount == 0)
00148                     PostQuitMessage(0);
00149                 break;
00150 
00151 
00152             case WM_CLOSE:
00153                 DestroyWindow(hwnd);
00154                 break;
00155 
00156             default:
00157                 goto HandleDefaultMsg;
00158         }
00159     }
00160     else
00161     {
00162 HandleDefaultMsg:
00163         Ret = DefWindowProc(hwnd,
00164                             uMsg,
00165                             wParam,
00166                             lParam);
00167     }
00168 
00169     return Ret;
00170 }
00171 
00172 typedef struct _CONSOLE_CHILDFRM_WND
00173 {
00174     HWND hwnd;
00175     PCONSOLE_MAINFRAME_WND MainFrame;
00176 } CONSOLE_CHILDFRM_WND, *PCONSOLE_CHILDFRM_WND;
00177 
00178 static LRESULT CALLBACK
00179 ConsoleChildFrmProc(IN HWND hwnd,
00180                     IN UINT uMsg,
00181                     IN WPARAM wParam,
00182                     IN LPARAM lParam)
00183 {
00184     PCONSOLE_CHILDFRM_WND Info;
00185     LRESULT Ret = FALSE;
00186 
00187     Info = (PCONSOLE_CHILDFRM_WND)GetWindowLongPtr(hwnd,
00188                                                    0);
00189 
00190     if (Info != NULL || uMsg == WM_NCCREATE)
00191     {
00192         switch (uMsg)
00193         {
00194             case WM_NCCREATE:
00195                 Info = HeapAlloc(hAppHeap,
00196                                  0,
00197                                  sizeof(*Info));
00198                 if (Info != NULL)
00199                 {
00200                     ZeroMemory(Info,
00201                                sizeof(*Info));
00202 
00203                     Info->hwnd = hwnd;
00204 
00205                     SetWindowLongPtr(hwnd,
00206                                      0,
00207                                      (LONG_PTR)Info);
00208 
00209                     Ret = TRUE;
00210                 }
00211                 break;
00212 
00213 
00214             case WM_NCDESTROY:
00215                 HeapFree(hAppHeap,
00216                          0,
00217                          Info);
00218                 break;
00219 
00220             default:
00221                 goto HandleDefaultMsg;
00222         }
00223     }
00224     else
00225     {
00226 HandleDefaultMsg:
00227         Ret = DefWindowProc(hwnd,
00228                             uMsg,
00229                             wParam,
00230                             lParam);
00231     }
00232 
00233     return Ret;
00234 
00235 }
00236 
00237 BOOL
00238 RegisterMMCWndClasses(VOID)
00239 {
00240     WNDCLASS wc;
00241     BOOL Ret;
00242 
00243     /* Register the MMCMainFrame window class */
00244     wc.style = 0;
00245     wc.lpfnWndProc = ConsoleMainFrameWndProc;
00246     wc.cbClsExtra = 0;
00247     wc.cbWndExtra = sizeof(PCONSOLE_MAINFRAME_WND);
00248     wc.hInstance = hAppInstance;
00249     wc.hIcon = LoadIcon(hAppInstance,
00250                         MAKEINTRESOURCE(IDI_MAINAPP));
00251     wc.hCursor = LoadCursor(NULL,
00252                             MAKEINTRESOURCE(IDC_ARROW));
00253     wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
00254     wc.lpszMenuName = NULL;
00255     wc.lpszClassName = szMMCMainFrame;
00256 
00257     Ret = (RegisterClass(&wc) != (ATOM)0);
00258     if (Ret)
00259     {
00260         /* Register the MMCChildFrm window class */
00261         wc.lpfnWndProc = ConsoleChildFrmProc;
00262         wc.cbWndExtra = sizeof(PCONSOLE_CHILDFRM_WND);
00263         wc.lpszClassName = szMMCChildFrm;
00264 
00265         Ret = (RegisterClass(&wc) != (ATOM)0);
00266         if (!Ret)
00267         {
00268             UnregisterClass(szMMCMainFrame,
00269                             hAppInstance);
00270         }
00271     }
00272 
00273     return Ret;
00274 }
00275 
00276 VOID
00277 UnregisterMMCWndClasses(VOID)
00278 {
00279     UnregisterClass(szMMCChildFrm,
00280                     hAppInstance);
00281     UnregisterClass(szMMCMainFrame,
00282                     hAppInstance);
00283 }
00284 
00285 HWND
00286 CreateConsoleWindow(IN LPCTSTR lpFileName  OPTIONAL)
00287 {
00288     HWND hWndConsole;
00289     LONG_PTR FileName = (LONG_PTR)lpFileName;
00290 
00291     hWndConsole = CreateWindowEx(WS_EX_WINDOWEDGE,
00292                                  szMMCMainFrame,
00293                                  NULL,
00294                                  WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS,
00295                                  CW_USEDEFAULT,
00296                                  CW_USEDEFAULT,
00297                                  CW_USEDEFAULT,
00298                                  CW_USEDEFAULT,
00299                                  NULL,
00300                                  NULL,
00301                                  hAppInstance,
00302                                  (PVOID)FileName);
00303 
00304     if (hWndConsole != NULL)
00305     {
00306         ShowWindow(hWndConsole,
00307                    SW_SHOWDEFAULT);
00308     }
00309 
00310     return hWndConsole;
00311 }

Generated on Sun May 27 2012 04:16:55 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.