00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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);
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,
00092 CW_USEDEFAULT,
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 }
00111