Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

WindowCreator.cpp

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * ウィンドウクリエータ実装
00022  * @author Junpee
00023  */
00024 
00025 #include "LampBasic.h"
00026 #include "Framework/Utility/WindowCreator.h"
00027 
00028 namespace Lamp{
00029 
00030 //------------------------------------------------------------------------------
00031 // ウィンドウ作成パラメータコンストラクタ
00032 WindowCreator::CreateParameter::CreateParameter(){
00033     windowName_ = "windowName";
00034     instanceHandle_ = NULL;
00035     windowProcedure_ = NULL;
00036     windowStyle_ =
00037         WS_OVERLAPPED |
00038         WS_CAPTION |
00039         WS_SYSMENU |
00040         WS_THICKFRAME |
00041         WS_MINIMIZEBOX |
00042         WS_MAXIMIZEBOX |
00043         WS_VISIBLE;
00044     createWidth_ = 640;
00045     createHeight_ = 480;
00046     iconHandle_ = ::LoadIcon(NULL, IDI_WINLOGO);
00047     smallIconHandle_ = ::LoadIcon(NULL, IDI_WINLOGO);
00048     cursorHandle_ = ::LoadCursor(NULL, IDC_ARROW);
00049 }
00050 //------------------------------------------------------------------------------
00051 // ウィンドウの作成
00052 HWND WindowCreator::create(const CreateParameter& parameter){
00053     // ウィンドウクラスの登録
00054     WNDCLASSEX windowClass;
00055     String windowClassName = parameter.windowName_ + "WindowClass";
00056     windowClass.cbSize = sizeof(WNDCLASSEX);    // WindowClassのサイズ
00057     windowClass.style = 0;                      // ウィンドウスタイル
00058     windowClass.lpfnWndProc =                   // ウィンドウプロシージャ
00059         parameter.windowProcedure_;
00060     windowClass.cbClsExtra = 0;                 // 拡張情報サイズ
00061     windowClass.cbWndExtra = 0;                 // 拡張情報サイズ
00062     windowClass.hInstance =                     // インスタンスハンドル
00063         parameter.instanceHandle_;
00064     windowClass.hIcon =                         // アイコンハンドル
00065         parameter.iconHandle_;
00066     windowClass.hIconSm =                       // スモールアイコンハンドル
00067         parameter.smallIconHandle_;
00068     windowClass.hCursor =                       // カーソルハンドル
00069         parameter.cursorHandle_;
00070     windowClass.hbrBackground =                 // 背景ブラシ
00071         (HBRUSH)::GetStockObject(GRAY_BRUSH);
00072     windowClass.lpszMenuName = NULL;            // メニュー名
00073     windowClass.lpszClassName =                 // ウィンドウクラス名
00074         windowClassName.getBytes();
00075     if(!::RegisterClassEx(&windowClass)){
00076         ErrorOut("SimpleFramework::createWindow() RegisterClassEx");
00077         return NULL;
00078     }
00079     // ウィンドウサイズの算出
00080     RECT windowRect;
00081     ::SetRect(&windowRect, 0, 0,
00082         parameter.createWidth_, parameter.createHeight_);
00083     // メニューには対応しない
00084     ::AdjustWindowRect(&windowRect, parameter.windowStyle_, false);
00085     // ウィンドウの作成
00086     return ::CreateWindowEx(
00087         0,                                      // 拡張ウィンドウスタイル
00088         windowClassName.getBytes(),             // ウィンドウクラス名
00089         parameter.windowName_.getBytes(),       // ウィンドウ名
00090         parameter.windowStyle_,                 // ウィンドウスタイル
00091         CW_USEDEFAULT,                          // ウィンドウX位置
00092         CW_USEDEFAULT,                          // ウィンドウY位置
00093         (windowRect.right - windowRect.left),   // ウィンドウ幅
00094         (windowRect.bottom - windowRect.top),   // ウィンドウ高さ
00095         NULL,                                   // 親ウィンドウ
00096         NULL,                                   // メニューハンドル
00097         parameter.instanceHandle_,              // インスタンスハンドル
00098         NULL);                                  // ウィンドウ作成データ
00099 }
00100 //------------------------------------------------------------------------------
00101 // ウィンドウの破棄
00102 void WindowCreator::destroy(HWND windowHandle){
00103     // メニューの破棄
00104     HMENU menuHandle = GetMenu(windowHandle);
00105     if(menuHandle != NULL){ DestroyMenu(menuHandle); }
00106     // ウィンドウの破棄
00107     DestroyWindow(windowHandle);
00108 }
00109 //------------------------------------------------------------------------------
00110 } // End of namespace Lamp
00111 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:38 2005 for Lamp by doxygen 1.3.2