///////////////////////////////////////////////////////////// /// Makes a query to the database ///////////////////////////////////////////////////////////// MYSQL_RES * Query(struct DataBase * DB, char * Query, ...) { // Check if the database is avaible if (DB && DB->Connection) { char QueryFormated[0xFF]; // Argument list va_list ArgList; // Initialize the argument list va_start(ArgList, Query); // sprintf arguments on string #ifdef SYSTEM_WINDOWS vsprintf_s(QueryFormated, 0xFF, Query, ArgList); #else vsprintf(QueryFormated, Query, ArgList); #endif // Destroy argument list va_end(ArgList); // Check if the connection is active if (mysql_ping(DB->Connection)) { // Show error MessageError("Query", "Error: The program couldn't make a query. %s. Trying to reconnect", mysql_error(DB->Connection)); // Close it mysql_close(DB->Connection); // Reconnect ConnectorInitialize(DB); return NULL; } // Make the query if (!mysql_query(DB->Connection, QueryFormated)) { MYSQL_RES * Result = mysql_store_result(DB->Connection); if ( Result != NULL ) { if (mysql_num_rows(Result)) return Result; } } } // Show error MessageError("Query", "Error: %s", mysql_error(DB->Connection)); // Close it mysql_close(DB->Connection); return NULL; }
void InitializeOptions(void) { WNDCLASSEX wincl; HWND hwnd; wincl.hInstance = g_hInstance; wincl.lpszClassName = OPTION_WIN_CLASS; wincl.lpfnWndProc = OptionsWndProc; wincl.style = CS_DBLCLKS; wincl.cbSize = sizeof(WNDCLASSEX); wincl.hIcon = GetApplicationIcon(); wincl.hIconSm = GetApplicationIcon(); wincl.hCursor = LoadCursor(NULL, IDC_ARROW); wincl.lpszMenuName = NULL; wincl.cbClsExtra = 0; wincl.cbWndExtra = 0; wincl.hbrBackground = g_hBrush; if(!RegisterClassEx(&wincl)) { MessageError(T("Can't register windows class '") OPTION_WIN_CLASS T("'!")); ExitProcess(0); } hwnd = CreateWindowEx(0, OPTION_WIN_CLASS, T("Computer Guard Options"), WS_CAPTION | WS_SYSMENU | WS_BORDER, CW_USEDEFAULT, CW_USEDEFAULT, 420, 250, NULL, NULL, g_hInstance, NULL); UpdateWindow(hwnd); g_hwOptions = hwnd; }
///////////////////////////////////////////////////////////// /// Process the query of database and returns it ///////////////////////////////////////////////////////////// bool QueryGet(struct DataBase * DB, char * QueryResult, MYSQL_RES * Result) { // Check if the database is avaible if (DB && DB->Connection && Result) { // Get the row MYSQL_ROW Row = mysql_fetch_row(Result); if (Row[0] == NULL) QueryResult = NULL; else { // Copy the result strcpy(QueryResult, (char *)Row[0]); } // Free it mysql_free_result(Result); return true; } // Show the error MessageError("QueryGet", "Error: Invalid Result"); return false; }
//////////////////////////////////////////////////////////// /// Switch to fullscreen mode //////////////////////////////////////////////////////////// void SwitchToFullscreen(struct VideoMode * Mode) { DEVMODE DevMode; long Style; DevMode.dmSize = sizeof(DEVMODE); DevMode.dmPelsWidth = Mode->Width; DevMode.dmPelsHeight = Mode->Height; DevMode.dmBitsPerPel = Mode->BitsPerPixel; DevMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; // Apply fullscreen mode if (ChangeDisplaySettings(&DevMode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { MessageError("SwitchToFullscreen", "Failed to change display mode for fullscreen."); return; } // Change window style (no border, no titlebar, ...) SetWindowLong(WindowhWnd, GWL_STYLE, WS_POPUP); SetWindowLong(WindowhWnd, GWL_EXSTYLE, WS_EX_APPWINDOW); // And resize it so that it fits the entire screen SetWindowPos(WindowhWnd, HWND_TOP, 0, 0, Mode->Width, Mode->Height, SWP_FRAMECHANGED); ShowWindow(WindowhWnd, SW_SHOW); // SetPixelFormat can fail (really ?) if window style doesn't contain these flags Style = GetWindowLong(WindowhWnd, GWL_STYLE); SetWindowLong(WindowhWnd, GWL_STYLE, Style | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); }
UINT CLuaToolBox::SendMessage(IHashString *msg, DWORD size, void *data, IHashString *name, IHashString *compType) { if (msg != NULL) { DWORD retVal = m_EngineToolBox->SendMessage(msg->GetUniqueID(), size, data, name, compType); if (retVal != MSG_HANDLED) { const TCHAR *nameStr = (name != NULL) ? name->GetString() : _T("unknown"); MessageError(_T("LUA: %s Message TO %s failed:\n"), msg->GetString(), nameStr); } return retVal; } else { const TCHAR *nameStr = (name != NULL) ? name->GetString() : _T("unknown"); MessageError(_T("LUA: %s Message TO %s failed:\n"), _T("*NULLMESSAGEHASH*"), nameStr); return MSG_NOT_HANDLED; } }
// // send a message to a message handler through message pump UINT CLuaToolBox::SendMessage(DWORD msg, DWORD size, void *data, IHashString *name, IHashString *compType) { DWORD retVal = m_EngineToolBox->SendMessage(msg, size, data, name, compType); if (retVal != MSG_HANDLED) { const TCHAR *msgStr = m_EngineToolBox->GetHashString(msg); const TCHAR *nameStr = (name != NULL) ? name->GetString() : _T("unknown"); MessageError(_T("LUA: %s Message TO %s failed:\n"), msgStr, nameStr); } return retVal; }
// // send a message to a message handler through message pump UINT CLuaToolBox::SendMessage(const TCHAR *msg, DWORD size, TCHAR *data, IHashString *name, IHashString *compType) { static DWORD msgHash = CHashString(msg).GetUniqueID(); DWORD retVal = m_EngineToolBox->SendMessage(msgHash, size, (void*)data, name, compType); if (retVal != MSG_HANDLED) { const TCHAR *nameStr = (name != NULL) ? name->GetString() : _T("unknown"); MessageError(_T("LUA: %s Message TO %s failed:\n"), msg, nameStr); } return retVal; }
//////////////////////////////////////////////////////////// /// Create and run the thread //////////////////////////////////////////////////////////// void ThreadLaunch(Thread * ThreadEx, FuncType Function, void * UserData) { // Set data from thread ThreadEx->myFunction = Function; ThreadEx->myUserData = UserData; // Create the thread ThreadEx->myHandle = (HANDLE)(_beginthreadex(NULL, 0, &ThreadFunc, ThreadEx, 0, NULL)); // Error ? if (ThreadEx->myHandle == NULL) MessageError("ThreadLaunch", "Failed to create thread."); }
//////////////////////////////////////////////////////////// /// Change the window's icon //////////////////////////////////////////////////////////// void WindowSetIcon(UInt32 Width, UInt32 Height, UInt8* Pixels) { Int32 i; UInt8 * IconPixels; // First destroy the previous one if (WindowIcon) DestroyIcon(WindowIcon); IconPixels = (UInt8*)malloc(Width * Height * 4); // Windows wants BGRA pixels : swap red and blue channels for (i = 0; i < sizeof(IconPixels) / 4; ++i) { IconPixels[i * 4 + 0] = Pixels[i * 4 + 2]; IconPixels[i * 4 + 1] = Pixels[i * 4 + 1]; IconPixels[i * 4 + 2] = Pixels[i * 4 + 0]; IconPixels[i * 4 + 3] = Pixels[i * 4 + 3]; } // Create the icon from the pixels array WindowIcon = CreateIcon(GetModuleHandle(NULL), Width, Height, 1, 32, NULL, &IconPixels[0]); // Set it as both big and small icon of the window if (WindowIcon) { SendMessage(WindowhWnd, WM_SETICON, ICON_BIG, (LPARAM)WindowIcon); SendMessage(WindowhWnd, WM_SETICON, ICON_SMALL, (LPARAM)WindowIcon); } else { MessageError("WindowSetIcon", "Failed to set the window's icon."); } free(IconPixels); }
void mmErrorDialogs::MessageInvalid(wxWindow *parent, const wxString &message) { const wxString& msg = wxString::Format(_("Entry %s is invalid"), message); MessageError(parent, msg, _("Invalid Entry")); }
//////////////////////////////////////////////////////////// /// Construct the context from graphics settings //////////////////////////////////////////////////////////// void CreateContext(struct VideoMode * Mode, struct WindowSettings * Params) { int BestFormat, Color, Score; PIXELFORMATDESCRIPTOR ActualFormat; HGLRC CurrentContext; // Get the device context attached to the window WindowDeviceContext = GetDC(WindowhWnd); if (WindowDeviceContext == NULL) { MessageError("CreateContext", "Failed to get device context of window -- cannot create OpenGL context."); return; } // Let's find a suitable pixel format -- first try with antialiasing BestFormat = 0; if (Params->AntialiasingLevel > 0) { // Get the wglChoosePixelFormatARB function (it is an extension) PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)(wglGetProcAddress("wglChoosePixelFormatARB")); // Define the basic attributes we want for our window int IntAttributes[] = { WGL_DRAW_TO_WINDOW_ARB, GL_TRUE, WGL_SUPPORT_OPENGL_ARB, GL_TRUE, WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB, WGL_DOUBLE_BUFFER_ARB, GL_TRUE, WGL_SAMPLE_BUFFERS_ARB, (Params->AntialiasingLevel ? GL_TRUE : GL_FALSE), WGL_SAMPLES_ARB, Params->AntialiasingLevel, 0, 0 }; // Let's check how many formats are supporting our requirements int Formats[128]; UINT NbFormats; float FloatAttributes[] = {0, 0}; bool IsValid = wglChoosePixelFormatARB(WindowDeviceContext, IntAttributes, FloatAttributes, sizeof(Formats) / sizeof(*Formats), Formats, &NbFormats) != 0; if (!IsValid || (NbFormats == 0)) { if (Params->AntialiasingLevel > 2) { // No format matching our needs : reduce the multisampling level MessageError("CreateContext", "Failed to find a pixel format supporting %u antialiasing levels ; trying with 2 levels.", Params->AntialiasingLevel); Params->AntialiasingLevel = IntAttributes[1] = 2; IsValid = wglChoosePixelFormatARB(WindowDeviceContext, IntAttributes, FloatAttributes, sizeof(Formats) / sizeof(*Formats), Formats, &NbFormats) != 0; } if (!IsValid || (NbFormats == 0)) { // Cannot find any pixel format supporting multisampling ; disabling antialiasing MessageError("CreateContext", "Failed to find a pixel format supporting antialiasing ; antialiasing will be disabled."); Params->AntialiasingLevel = 0; } } // Get the best format among the returned ones if (IsValid && (NbFormats > 0)) { int BestScore = 0xFFFF; UINT i = 0; for (i = 0; i < NbFormats; ++i) { // Get the current format's attributes PIXELFORMATDESCRIPTOR Attribs; Attribs.nSize = sizeof(PIXELFORMATDESCRIPTOR); Attribs.nVersion = 1; DescribePixelFormat(WindowDeviceContext, Formats[i], sizeof(PIXELFORMATDESCRIPTOR), &Attribs); // Evaluate the current configuration Color = Attribs.cRedBits + Attribs.cGreenBits + Attribs.cBlueBits + Attribs.cAlphaBits; Score = EvaluateConfig(Mode, Params, Color, Attribs.cDepthBits, Attribs.cStencilBits, Params->AntialiasingLevel); // Keep it if it's better than the current best if (Score < BestScore) { BestScore = Score; BestFormat = Formats[i]; } } } } // Find a pixel format with no antialiasing, if not needed or not supported if (BestFormat == 0) { // Setup a pixel format descriptor from the rendering settings PIXELFORMATDESCRIPTOR PixelDescriptor; ZeroMemory(&PixelDescriptor, sizeof(PIXELFORMATDESCRIPTOR)); PixelDescriptor.nSize = sizeof(PIXELFORMATDESCRIPTOR); PixelDescriptor.nVersion = 1; PixelDescriptor.iLayerType = PFD_MAIN_PLANE; PixelDescriptor.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; PixelDescriptor.iPixelType = PFD_TYPE_RGBA; PixelDescriptor.cColorBits = (BYTE)(Mode->BitsPerPixel); PixelDescriptor.cDepthBits = (BYTE)(Params->DepthBits); PixelDescriptor.cStencilBits = (BYTE)(Params->StencilBits); // Get the pixel format that best matches our requirements BestFormat = ChoosePixelFormat(WindowDeviceContext, &PixelDescriptor); if (BestFormat == 0) { MessageError("CreateContext", "Failed to find a suitable pixel format for device context -- cannot create OpenGL context."); return; } } // Extract the depth and stencil bits from the chosen format ActualFormat.nSize = sizeof(PIXELFORMATDESCRIPTOR); ActualFormat.nVersion = 1; DescribePixelFormat(WindowDeviceContext, BestFormat, sizeof(PIXELFORMATDESCRIPTOR), &ActualFormat); Params->DepthBits = ActualFormat.cDepthBits; Params->StencilBits = ActualFormat.cStencilBits; // Set the chosen pixel format if (!SetPixelFormat(WindowDeviceContext, BestFormat, &ActualFormat)) { MessageError("CreateContext", "Failed to set pixel format for device context -- cannot create OpenGL context."); return; } // Create the OpenGL context from the device context WindowGLContext = wglCreateContext(WindowDeviceContext); if (WindowGLContext == NULL) { MessageError("CreateContext", "Failed to create an OpenGL context for this window."); return; } // Share display lists with other contexts CurrentContext = wglGetCurrentContext(); if (CurrentContext) wglShareLists(CurrentContext, WindowGLContext); // Activate the context WindowSetActive(true); // Enable multisampling if (Params->AntialiasingLevel > 0) glEnable(GL_MULTISAMPLE_ARB); }