Window::Window(const string& title, U32 width, U32 height) { U32 styleFlags = WS_OVERLAPPED | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;// | WS_THICKFRAME; AdjustWindowSize(styleFlags, &width, &height); this->width = width; this->height = height; isClosed = false; isMinimized = false; isInactive = false; HINSTANCE instanceHandle = (HINSTANCE)GetModuleHandle(NULL); WNDCLASS wc; wc.style = CS_DBLCLKS; wc.lpfnWndProc = (WNDPROC) Window::StaticWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = instanceHandle; wc.hIcon = LoadIcon(0, IDI_APPLICATION); wc.hCursor = LoadCursorFromFile("..//Data//Cursors//arrow.cur"); wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wc.lpszMenuName = 0; wc.lpszClassName = "MainWinWindowClass"; if (!RegisterClass(&wc)) { throw WinException(GetLastError()); } // Create window instance handle = CreateWindow("MainWinWindowClass", // Registered WNDCLASS instance to use. title.c_str(), // window title styleFlags, // style flags CW_USEDEFAULT, // x-coordinate CW_USEDEFAULT, // y-coordinate width, // width height, // height 0, // parent window 0, // menu handle instanceHandle, // app instance 0); if (!handle) { throw WinException(GetLastError()); } SetWindowLongPtr(handle, GWLP_USERDATA, (LONG_PTR)this); // Show window ShowWindow(handle, true); UpdateWindow(handle); }
/** * Frees memory * @param ptr Address of the memory to deallocate */ void deallocate(ptr_t ptr) { //Free memory int ec = VirtualFreeEx( proc_.getHandle(), reinterpret_cast<void*>(ptr), 0, MEM_RELEASE); if(!ec) { dword_t error = GetLastError(); throw WinException( "Process::freeMemory()", "VirtualFreeEx()", error); } //If case scoped_release was specified we need to remove the pointer if(scoped_release) { if(allocations_.size() == 0) return; AllocIter element; element = std::find(allocations_.begin(), allocations_.end(), ptr); if((*element) == ptr) allocations_.erase(element); } }
void RenderContext::openForValues(const wchar_t* const* values, std::size_t n) { handle_.reset(EvtCreateRenderContext(n, const_cast<const wchar_t**>(values), EvtRenderEventValues)); if (!handle_) { throw WinException(L"EvtCreateRenderContext", GetLastError()); } }
void RenderContext::getValues(const Event& event, Variant* values, std::size_t n) { EVT_HANDLE handle = handle_.get(); DWORD used = 0; DWORD properties = 0; bool success = EvtRender( handle, event.getHandle(), EvtRenderEventValues, n * sizeof(EVT_VARIANT), values, &used, &properties); if (!success) { throw WinException(L"EvtRender", GetLastError()); } if (n * sizeof(EVT_VARIANT) > used || n != properties) { throw WinException(L"RenderContext::getValues", ERROR_BAD_ARGUMENTS); } }
void WinMaker::Create () { _hwnd = ::CreateWindowEx ( _exStyle, _class.GetName (), _windowName, _style, _x, _y, _width, _height, _hWndParent, _hMenu, _class.GetInstance (), _data); if (_hwnd == 0) throw WinException ("Internal error: Window Creation Failed."); }
size_t rawWrite( const ptr_t dest, const data_t* source, const size_t amount) const { SIZE_T bytesWritten; int ec = ::WriteProcessMemory( handle_, reinterpret_cast<void*>(dest), static_cast<const void*>(source), amount, &bytesWritten); if(!ec) { const dword_t error = GetLastError(); throw WinException( "Process::rawWrite<>()", "WriteProcessMemory()", error); } return bytesWritten; }
size_t rawRead( const ptr_t source, data_t* dest, const size_t amount) const { SIZE_T bytesRead; int ec = ::ReadProcessMemory( handle_, reinterpret_cast<const void*>(source), static_cast<void*>(dest), amount, &bytesRead); if(!ec) { const dword_t error = GetLastError(); throw WinException( "Process::rawRead<>()", "ReadProcessMemory()", error); } return bytesRead; }
ptr_t allocate(size_t count) { //Get memory void* allocatedMemory = VirtualAllocEx( proc_.getHandle(), NULL, count * sizeof(data_t), MEM_COMMIT, PAGE_EXECUTE_READWRITE); if(!allocatedMemory) { dword_t error = GetLastError(); throw WinException( "Allocator::allocate()", "VirtualAllocEx()", error); } ptr_t temp = reinterpret_cast<ptr_t>(allocatedMemory); //If case scoped_release was specified we need to store the pointer if(scoped_release) allocations_.push_back(temp); return temp; }
void WinClass::Register () { if (::RegisterClassEx (&_class) == 0) throw WinException ("Internal error: RegisterClassEx failed."); }
// String Resource ResString::ResString (HINSTANCE hInst, int resId) { if (!::LoadString (hInst, resId, _buf, MAX_RESSTRING + 1)) throw WinException ("Load String failed"); }