BOOL CALLBACK ProxySettingsDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED LPARAM lParam) { HICON hIcon; switch (msg) { case WM_INITDIALOG: hIcon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(APP_ICON), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR); if (hIcon) { SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_SMALL), (LPARAM) (hIcon)); SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_BIG), (LPARAM) (hIcon)); } /* Limit Port editboxs to 5 chars. */ SendMessage(GetDlgItem(hwndDlg, EDIT_PROXY_HTTP_PORT), EM_SETLIMITTEXT, 5, 0); SendMessage(GetDlgItem(hwndDlg, EDIT_PROXY_SOCKS_PORT), EM_SETLIMITTEXT, 5, 0); LoadProxySettings(hwndDlg); break; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: if (CheckProxySettings(hwndDlg)) { SaveProxySettings(hwndDlg); EndDialog(hwndDlg, LOWORD(wParam)); return TRUE; } return FALSE; case IDCANCEL: EndDialog(hwndDlg, LOWORD(wParam)); return TRUE; case RB_PROXY_USE_OPENVPN: if (HIWORD(wParam) == BN_CLICKED) { EnableWindow(GetDlgItem(hwndDlg, RB_PROXY_HTTP), FALSE); EnableWindow(GetDlgItem(hwndDlg, RB_PROXY_SOCKS), FALSE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_HTTP_ADDRESS), FALSE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_HTTP_PORT), FALSE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_HTTP_ADDRESS), FALSE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_HTTP_PORT), FALSE); EnableWindow(GetDlgItem(hwndDlg, CHECKB_PROXY_AUTH), FALSE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_SOCKS_ADDRESS), FALSE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_SOCKS_PORT), FALSE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_SOCKS_ADDRESS), FALSE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_SOCKS_PORT), FALSE); break; } case RB_PROXY_USE_IE: if (HIWORD(wParam) == BN_CLICKED) { EnableWindow(GetDlgItem(hwndDlg, RB_PROXY_HTTP), FALSE); EnableWindow(GetDlgItem(hwndDlg, RB_PROXY_SOCKS), FALSE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_HTTP_ADDRESS), FALSE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_HTTP_PORT), FALSE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_HTTP_ADDRESS), FALSE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_HTTP_PORT), FALSE); EnableWindow(GetDlgItem(hwndDlg, CHECKB_PROXY_AUTH), TRUE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_SOCKS_ADDRESS), FALSE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_SOCKS_PORT), FALSE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_SOCKS_ADDRESS), FALSE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_SOCKS_PORT), FALSE); break; } case RB_PROXY_USE_MANUAL: if (HIWORD(wParam) == BN_CLICKED) { EnableWindow(GetDlgItem(hwndDlg, RB_PROXY_HTTP), TRUE); EnableWindow(GetDlgItem(hwndDlg, RB_PROXY_SOCKS), TRUE); if (IsDlgButtonChecked(hwndDlg, RB_PROXY_HTTP) == BST_CHECKED) { EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_HTTP_ADDRESS), TRUE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_HTTP_PORT), TRUE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_HTTP_ADDRESS), TRUE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_HTTP_PORT), TRUE); EnableWindow(GetDlgItem(hwndDlg, CHECKB_PROXY_AUTH), TRUE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_SOCKS_ADDRESS), FALSE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_SOCKS_PORT), FALSE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_SOCKS_ADDRESS), FALSE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_SOCKS_PORT), FALSE); } else { EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_HTTP_ADDRESS), FALSE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_HTTP_PORT), FALSE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_HTTP_ADDRESS), FALSE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_HTTP_PORT), FALSE); EnableWindow(GetDlgItem(hwndDlg, CHECKB_PROXY_AUTH), FALSE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_SOCKS_ADDRESS), TRUE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_SOCKS_PORT), TRUE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_SOCKS_ADDRESS), TRUE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_SOCKS_PORT), TRUE); } break; } case RB_PROXY_HTTP: if (HIWORD(wParam) == BN_CLICKED) { EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_HTTP_ADDRESS), TRUE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_HTTP_PORT), TRUE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_HTTP_ADDRESS), TRUE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_HTTP_PORT), TRUE); EnableWindow(GetDlgItem(hwndDlg, CHECKB_PROXY_AUTH), TRUE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_SOCKS_ADDRESS), FALSE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_SOCKS_PORT), FALSE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_SOCKS_ADDRESS), FALSE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_SOCKS_PORT), FALSE); break; } case RB_PROXY_SOCKS: if (HIWORD(wParam) == BN_CLICKED) { EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_HTTP_ADDRESS), FALSE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_HTTP_PORT), FALSE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_HTTP_ADDRESS), FALSE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_HTTP_PORT), FALSE); EnableWindow(GetDlgItem(hwndDlg, CHECKB_PROXY_AUTH), FALSE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_SOCKS_ADDRESS), TRUE); EnableWindow(GetDlgItem(hwndDlg, EDIT_PROXY_SOCKS_PORT), TRUE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_SOCKS_ADDRESS), TRUE); EnableWindow(GetDlgItem(hwndDlg, TEXT_PROXY_SOCKS_PORT), TRUE); break; } } break; case WM_CLOSE: EndDialog(hwndDlg, LOWORD(wParam)); return TRUE; } return FALSE; }
glWindow::glWindow (bool fullScreen, bool border, int width, int height, int bpp, bool stencil, std::string title, bool allowResizing, bool fitToWorkArea, ResetGLModeType resetGLMode) { m_resetGLMode = resetGLMode; // Null default values // If constructor is aborted, then destructor wont try to deallocate garbage handles. m_HDC = 0; m_HGLRC = 0; m_HWnd = 0; m_HInstance = 0; m_active = false; m_focused = false; m_visible = false; m_closing = false; m_bufStart = 0; m_bufEnd = 0; m_scanBufStart = 0; m_scanBufEnd = 0; m_showingCursor = true; // Clear key buffers ClearKeyBuffers (); // Defaults m_fov = 60; m_nearClip = 1; m_farClip = 1000; m_painting = false; m_dontPaint = false; m_pausePressed = false; m_mouseX = 0; m_mouseY = 0; m_mouseButton [0] = 0; m_mouseButton [1] = 0; m_mouseButton [2] = 0; m_mouseWheel = 0; m_mouseWheelDelta = 0; m_mouseCentred = false; m_HInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window // Create open GL window. // Note: Caller should check error state after construction. If error set, // then the window is probably unusable WNDCLASS wc; // Windows Class Structure wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window. wc.lpfnWndProc = (WNDPROC) ::WndProc; // WndProc Handles Messages wc.cbClsExtra = 0; // No Extra Window Data wc.cbWndExtra = 0; // No Extra Window Data wc.hInstance = m_HInstance; // Set The Instance wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer wc.hbrBackground = NULL; // No Background Required For GL wc.lpszMenuName = NULL; // We Don't Want A Menu wc.lpszClassName = "gbOpenGL"; // Set The Class Name if (!RegisterClass(&wc)) // Attempt To Register The Window Class { SetError ("Window class registration failed"); return; } RecreateWindow (fullScreen, border, width, height, bpp, stencil, title, allowResizing, fitToWorkArea); }
///////////////////////////////// // Constructor and destructor // ///////////////////////////////// SpoutReceiverSDK2::SpoutReceiverSDK2() :CFreeFrameGLPlugin(), m_initResources(1), m_maxCoordsLocation(-1) { HMODULE module; char path[MAX_PATH]; /* // Debug console window so printf works FILE* pCout; AllocConsole(); freopen_s(&pCout, "CONOUT$", "w", stdout); #ifdef DX9Mode printf("SpoutReceiver2 DX9 Vers 3.025\n"); #else printf("SpoutReceiver2 DX11 Vers 3.025\n"); #endif */ // Input properties - this is a source and has no inputs SetMinInputs(0); SetMaxInputs(0); // // ======== initial values ======== // #ifdef DX9Mode bDX9mode = true; // DirectX 9 mode rather than default DirectX 11 #else bDX9mode = false; #endif bInitialized = false; // not initialized yet by either means bAspect = false; // preserve aspect ratio of received texture in draw bUseActive = true; // connect to the active sender bStarted = false; // Do not allow a starting cycle UserSenderName[0] = 0; // User entered sender name g_Width = 512; g_Height = 512; // arbitrary initial image size myTexture = 0; // only used for memoryshare mode // // Parameters // // Memoryshare define // if set to true (memory share only), it connects as memory share // and there is no user option to select a sender // default is false (automatic) #ifndef MemoryShareMode SetParamInfo(FFPARAM_SharingName, "Sender Name", FF_TYPE_TEXT, ""); SetParamInfo(FFPARAM_Update, "Update", FF_TYPE_EVENT, false ); SetParamInfo(FFPARAM_Select, "Select", FF_TYPE_EVENT, false ); bMemoryMode = false; #else bMemoryMode = true; #endif SetParamInfo(FFPARAM_Aspect, "Aspect", FF_TYPE_BOOLEAN, false ); // For memory mode, tell Spout to use memoryshare if(bMemoryMode) { receiver.SetMemoryShareMode(); // Give it an arbitrary user name for ProcessOpenGL strcpy_s(UserSenderName, 256, "0x8e14549a"); } // Set DirectX mode depending on DX9 flag if(bDX9mode) receiver.SetDX9(true); else receiver.SetDX9(false); // Find the host executable name module = GetModuleHandle(NULL); GetModuleFileNameA(module, path, MAX_PATH); _splitpath_s(path, NULL, 0, NULL, 0, HostName, MAX_PATH, NULL, 0); // Isadora and Resolume act on button down // Isadora activates all parameters on plugin load, so allow one cycle for starting. // Magic reacts on button-up, so when the dll loads the parameters are not activated. // Magic and default Windows apps act on button up so all is OK. if(strstr(HostName, "Avenue") == 0 || strstr(HostName, "Arena") == 0 || strstr(HostName, "Isadora") == 0) { bStarted = false; } else { bStarted = true; } }
BOOL INPUTCLASS::Init(HWND hParentWnd, INPUTPROC inputProc) { if (hParentWnd == NULL) return FALSE; if (inputProc == NULL) return FALSE; this->hParentWnd = hParentWnd; pDI = NULL; pKeyboard = NULL; pJoystick = NULL; Feedback = FALSE; memset(cDIBuf, 0, sizeof(cDIBuf)); memset(JoystickName, 0, sizeof(JoystickName)); if(FAILED(DirectInput8Create(GetModuleHandle(NULL),DIRECTINPUT_VERSION,IID_IDirectInput8,(void**)&pDI,NULL))) return FALSE; if (!FAILED(pDI->CreateDevice(GUID_SysKeyboard,&pKeyboard,NULL))) { if (!FAILED(pKeyboard->SetDataFormat(&c_dfDIKeyboard))) { if (FAILED(pKeyboard->SetCooperativeLevel(hParentWnd,DISCL_FOREGROUND|DISCL_NONEXCLUSIVE))) { pKeyboard->Release(); pKeyboard = NULL; } } else { pKeyboard->Release(); pKeyboard = NULL; } } pJoystick = EnumDevices(pDI); if (pJoystick) { if(!FAILED(pJoystick->SetDataFormat(&c_dfDIJoystick2))) { if(FAILED(pJoystick->SetCooperativeLevel(hParentWnd,DISCL_FOREGROUND|DISCL_EXCLUSIVE))) { pJoystick->Release(); pJoystick = NULL; } else { tmp_Joystick = pJoystick; pJoystick->EnumObjects(::EnumObjects, (VOID*)hParentWnd, DIDFT_ALL); memset(&DIJoycap,0,sizeof(DIDEVCAPS)); DIJoycap.dwSize=sizeof(DIDEVCAPS); pJoystick->GetCapabilities(&DIJoycap); } } else { pJoystick->Release(); pJoystick = NULL; } } if (pJoystick) { DIPROPDWORD dipdw; dipdw.diph.dwSize = sizeof(DIPROPDWORD); dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); dipdw.diph.dwObj = 0; dipdw.diph.dwHow = DIPH_DEVICE; dipdw.dwData = 0; if ( !FAILED( pJoystick->SetProperty(DIPROP_AUTOCENTER, &dipdw.diph) ) ) { DWORD rgdwAxes[1] = { DIJOFS_Y }; LONG rglDirection[2] = { 0 }; DICONSTANTFORCE cf = { 0 }; DIEFFECT eff; cf.lMagnitude = (DI_FFNOMINALMAX * 100); memset(&eff, 0, sizeof(eff)); eff.dwSize = sizeof(DIEFFECT); eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; eff.dwDuration = INFINITE; eff.dwSamplePeriod = 0; eff.dwGain = DI_FFNOMINALMAX; eff.dwTriggerButton = DIEB_NOTRIGGER; eff.dwTriggerRepeatInterval = 0; eff.cAxes = 1; eff.rgdwAxes = rgdwAxes; eff.rglDirection = rglDirection; eff.lpEnvelope = 0; eff.cbTypeSpecificParams = sizeof( DICONSTANTFORCE ); eff.lpvTypeSpecificParams = &cf; eff.dwStartDelay = 0; if( FAILED( pJoystick->CreateEffect(GUID_ConstantForce, &eff, &pEffect, NULL) ) ) Feedback = FALSE; } else Feedback = FALSE; } if (pKeyboard == NULL && pJoystick == NULL) return FALSE; this->inputProc = inputProc; INFO("DirectX Input: \n"); if (pKeyboard != NULL) INFO(" - keyboard successfully inited\n"); if (pJoystick != NULL) { INFO(" - gamecontrol successfully inited: %s\n", JoystickName); if (Feedback) INFO("\t\t\t\t (with FeedBack support)\n"); } paused = FALSE; return TRUE; }
bool CCEGLView::Create() { bool bRet = false; do { CC_BREAK_IF(m_hWnd); HINSTANCE hInstance = GetModuleHandle( NULL ); WNDCLASS wc; // Windows Class Structure // Redraw On Size, And Own DC For Window. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.lpfnWndProc = _WindowProc; // WndProc Handles Messages wc.cbClsExtra = 0; // No Extra Window Data wc.cbWndExtra = 0; // No Extra Window Data wc.hInstance = hInstance; // Set The Instance wc.hIcon = LoadIcon( NULL, IDI_WINLOGO ); // Load The Default Icon wc.hCursor = LoadCursor( NULL, IDC_ARROW ); // Load The Arrow Pointer wc.hbrBackground = NULL; // No Background Required For GL wc.lpszMenuName = m_menu; // wc.lpszClassName = kWindowClassName; // Set The Class Name CC_BREAK_IF(! RegisterClass(&wc) && 1410 != GetLastError()); // center window position RECT rcDesktop; GetWindowRect(GetDesktopWindow(), &rcDesktop); WCHAR wszBuf[50] = {0}; MultiByteToWideChar(CP_UTF8, 0, m_szViewName, -1, wszBuf, sizeof(wszBuf)); // create window m_hWnd = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, // Extended Style For The Window kWindowClassName, // Class Name wszBuf, // Window Title WS_CAPTION | WS_POPUPWINDOW | WS_MINIMIZEBOX, // Defined Window Style 0, 0, // Window Position //TODO: Initializing width with a large value to avoid getting a wrong client area by 'GetClientRect' function. 1000, // Window Width 1000, // Window Height NULL, // No Parent Window NULL, // No Menu hInstance, // Instance NULL ); CC_BREAK_IF(! m_hWnd); bRet = initGL(); if(!bRet) destroyGL(); CC_BREAK_IF(!bRet); s_pMainWindow = this; bRet = true; } while (0); #if(_MSC_VER >= 1600) m_bSupportTouch = CheckTouchSupport(); if(m_bSupportTouch) { m_bSupportTouch = (s_pfRegisterTouchWindowFunction(m_hWnd, 0) != 0); } #endif /* #if(_MSC_VER >= 1600) */ return bRet; }
/** * Below CheckMessageBoxProc adds everyones favorite "don't show again" checkbox to the dialog * much of the layout code (especially for XP and older windows versions) is copied with changes * from a GPL'ed project emabox at SourceForge. **/ LRESULT CALLBACK CheckMessageBoxProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_COMMAND: { if (HIWORD(wParam) == BN_CLICKED && LOWORD(wParam) == 2025) { const LRESULT res = SendMessage((HWND)lParam, BM_GETSTATE, 0, 0); bool bCheckedAfter = ((res & BST_CHECKED) == 0); // Update usedata ExMessageBox::SetUserData((void*)(bCheckedAfter ? BST_CHECKED : BST_UNCHECKED)); SendMessage((HWND)lParam, BM_SETCHECK, bCheckedAfter ? BST_CHECKED : BST_UNCHECKED, 0); } } break; case WM_ERASEBKGND: { // Vista+ has grey strip if (WinUtil::getOsMajor() >= 6) { RECT rc = {0}; HDC dc = (HDC)wParam; // Fill the entire dialog GetClientRect(hWnd, &rc); FillRect(dc, &rc, GetSysColorBrush(COLOR_WINDOW)); // Calculate strip height RECT rcButton = {0}; GetWindowRect(FindWindowEx(hWnd, NULL, L"BUTTON", NULL), &rcButton); int stripHeight = (rcButton.bottom - rcButton.top) + 24; // Fill the strip rc.top += (rc.bottom - rc.top) - stripHeight; FillRect(dc, &rc, GetSysColorBrush(COLOR_3DFACE)); // Make a line HGDIOBJ oldPen = SelectObject(dc, CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DLIGHT))); MoveToEx(dc, rc.left - 1, rc.top, (LPPOINT)NULL); LineTo(dc, rc.right, rc.top); DeleteObject(SelectObject(dc, oldPen)); return S_OK; } } break; case WM_CTLCOLORSTATIC: { // Vista+ has grey strip if ((WinUtil::getOsMajor() >= 6) && ((HWND)lParam == GetDlgItem(hWnd, 2025))) { HDC hdc = (HDC)wParam; SetBkMode(hdc, TRANSPARENT); return (LRESULT)GetSysColorBrush(COLOR_3DFACE); } } break; case WM_INITDIALOG: { RECT rc = {0}; HWND current = NULL; int iWindowWidthBefore; int iWindowHeightBefore; int iClientHeightBefore; int iClientWidthBefore; pair<LPCTSTR, UINT> checkdata = (*(pair<LPCTSTR, UINT>*)ExMessageBox::GetUserData()); GetClientRect(hWnd, &rc); iClientHeightBefore = rc.bottom - rc.top; iClientWidthBefore = rc.right - rc.left; GetWindowRect(hWnd, &rc); iWindowWidthBefore = rc.right - rc.left; iWindowHeightBefore = rc.bottom - rc.top; // Create checkbox (resized and moved later) HWND check = CreateWindow(L"BUTTON", checkdata.first, WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_VCENTER | BS_CHECKBOX, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hWnd, (HMENU)2025, GetModuleHandle(NULL), NULL ); // Assume checked by default SendMessage(check, BM_SETCHECK, checkdata.second, 0); ExMessageBox::SetUserData((void*)checkdata.second); // Apply default font const int cyMenuSize = GetSystemMetrics(SM_CYMENUSIZE); const int cxMenuSize = GetSystemMetrics(SM_CXMENUSIZE); const HFONT hNewFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT); HFONT hOldFont; SIZE size; SendMessage(check, WM_SETFONT, (WPARAM)hNewFont, (LPARAM)TRUE); // Get the size of the checkbox HDC hdc = GetDC(check); hOldFont = (HFONT)SelectObject(hdc, GetStockObject(DEFAULT_GUI_FONT)); GetTextExtentPoint32(hdc, checkdata.first, wcslen(checkdata.first), &size); SelectObject(hdc, hOldFont); ReleaseDC(check, hdc); // Checkbox dimensions int iCheckboxWidth = cxMenuSize + size.cx + 1; int iCheckboxHeight = (cyMenuSize > size.cy) ? cyMenuSize : size.cy; // Vista+ has a different kind of layout altogether if (WinUtil::getOsMajor() >= 6) { // Align checkbox with buttons (aproximately) int iCheckboxTop = int(iClientHeightBefore - (iCheckboxHeight * 1.70)); MoveWindow(check, 5, iCheckboxTop, iCheckboxWidth, iCheckboxHeight, FALSE); // Resize and re-center dialog int iWindowWidthAfter = iWindowWidthBefore + iCheckboxWidth; int iWindowLeftAfter = rc.left + (iWindowWidthBefore - iWindowWidthAfter) / 2; MoveWindow(hWnd, iWindowLeftAfter, rc.top, iWindowWidthAfter, iWindowHeightBefore, TRUE); // Go through the buttons and move them while ((current = FindWindowEx(hWnd, current, L"BUTTON", NULL)) != NULL) { if (current == check) continue; RECT rc; GetWindowRect(current, &rc); ScreenToClient(hWnd, &rc); MoveWindow(current, rc.left + iCheckboxWidth, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE); } } else { RECT rt = {0}, rb = {0}; // Let's find us the label while ((current = FindWindowEx(hWnd, current, L"STATIC", NULL)) != NULL) { if (GetWindowTextLength(current) > 0) { GetWindowRect(current, &rt); ScreenToClient(hWnd, &rt); current = NULL; break; } } // For correcting width, here just to make lines shorter int iWidthAdjustment = (rt.left + iCheckboxWidth) - iWindowWidthBefore; // Go through the buttons and move them current = NULL; while ((current = FindWindowEx(hWnd, current, L"BUTTON", NULL)) != NULL) { if (current == check) continue; GetWindowRect(current, &rb); ScreenToClient(hWnd, &rb); MoveWindow(current, rb.left + (iWidthAdjustment > 0 ? (iWidthAdjustment + 15) / 2 : 0), rb.top + iCheckboxHeight, rb.right - rb.left, rb.bottom - rb.top, FALSE); } // Move the checkbox int iCheckboxTop = rt.top + (rt.bottom - rt.top) + ((rb.top - rt.bottom) / 2); MoveWindow(check, rt.left, iCheckboxTop, iCheckboxWidth, iCheckboxHeight, FALSE); // Resize and re-center dialog int iWindowHeightAfter = iWindowHeightBefore + iCheckboxHeight; int iWindowTopAfter = rc.top + (iWindowHeightBefore - iWindowHeightAfter) / 2; int iWindowWidthAfter = (iWidthAdjustment > 0) ? iWindowWidthBefore + iWidthAdjustment + 15 : iWindowWidthBefore; int iWindowLeftAfter = rc.left + (iWindowWidthBefore - iWindowWidthAfter) / 2; MoveWindow(hWnd, iWindowLeftAfter, iWindowTopAfter, iWindowWidthAfter, iWindowHeightAfter, TRUE); } } break; } return CallWindowProc(ExMessageBox::GetMessageBoxProc(), hWnd, uMsg, wParam, lParam); }
IDirect3DDevice9 *d3dwin_open( char *title, unsigned int width_, unsigned int height_, D3DFORMAT format, BOOL fullscreen_ ){ DIRECT3DCREATE9 Direct3DCreate9; RECT rect; WNDCLASS wc; UINT32 style; D3DDISPLAYMODE displaymode; D3DPRESENT_PARAMETERS presentparameters; D3DCAPS9 caps; width = width_; height = height_; fullscreen = fullscreen_; inst = GetModuleHandle(NULL); library = (HMODULE) LoadLibrary("d3d9.dll"); if(!library) return NULL; Direct3DCreate9 = (DIRECT3DCREATE9) GetProcAddress(library,"Direct3DCreate9"); if(!Direct3DCreate9) return NULL; direct3d=Direct3DCreate9(D3D_SDK_VERSION); if(!direct3d) return NULL; if(!fullscreen) style = WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU; else{ style = WS_POPUP; ShowCursor(FALSE); } rect.left = 0; rect.top = 0; rect.right = width; rect.bottom = height; if(!fullscreen) AdjustWindowRect( &rect, style, FALSE ); wc.style = CS_VREDRAW|CS_HREDRAW; wc.lpfnWndProc = window_proc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = 0; wc.hIcon = LoadIcon(inst,MAKEINTRESOURCE(IDI_ICON)); wc.hCursor = LoadCursor(inst,IDC_ARROW); wc.hbrBackground = 0; wc.lpszMenuName = 0; wc.lpszClassName = "d3d9"; RegisterClass(&wc); win = CreateWindowEx(0, "d3d9", title, (style)|WS_VISIBLE, 0, 0, rect.right-rect.left, rect.bottom-rect.top, 0, 0, inst, 0); if(!win) return NULL; memset(&presentparameters, 0, sizeof(D3DPRESENT_PARAMETERS)); if(!fullscreen){ if(FAILED(IDirect3D9_GetAdapterDisplayMode( direct3d, D3DADAPTER_DEFAULT, &displaymode ))){ d3dwin_close(); return NULL; } } if(!fullscreen) presentparameters.Windowed = TRUE; presentparameters.SwapEffect = D3DSWAPEFFECT_DISCARD; presentparameters.BackBufferWidth = width; presentparameters.BackBufferHeight = height; if( fullscreen ) presentparameters.BackBufferFormat = format; else presentparameters.BackBufferFormat = displaymode.Format; presentparameters.AutoDepthStencilFormat = D3DFMT_D24S8; presentparameters.EnableAutoDepthStencil = TRUE; IDirect3D9_GetDeviceCaps(direct3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps); if(FAILED(IDirect3D9_CreateDevice( direct3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, win, (caps.DevCaps&D3DDEVCAPS_HWTRANSFORMANDLIGHT) ? D3DCREATE_HARDWARE_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentparameters, &device))){ d3dwin_close(); return NULL; } IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0); IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); return device; }
void ToolsOptionsWindow::OnCreate (HWND hWnd) { // Make this window handle global m_hwnd = hWnd; g_hWnd = hWnd; // Need to do this otherwise the control creation wrapper functions don't work. HFONT hfDefault = (HFONT) GetStockObject (DEFAULT_GUI_FONT); // The status list box m_lstcategory = CreateWindow ("listbox", NULL, WS_CHILD | WS_BORDER | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL, 10, 10, 100, 480, hWnd, (HMENU) ID_LSTOPTIONCATEGORY, GetModuleHandle (NULL), NULL); SendMessage (m_lstcategory, WM_SETFONT, (WPARAM) hfDefault, MAKELPARAM (FALSE, 0)); SendMessage (m_lstcategory, LB_SETITEMHEIGHT, 0, 32); CreateGeneralPanel (); //ID_OPTWINDOWCLOSE m_btnclose = CreateButton ("Close", 455, 440, 70, 23, ID_OPTWINDOWCLOSE); // Add the categories to the list box char szGeneral[SIZE_NAME]; ZeroMemory (szGeneral, SIZE_NAME); strcpy_s (szGeneral, SIZE_NAME, "General"); SendMessage (m_lstcategory, LB_ADDSTRING, 0, (LPARAM) szGeneral); // Read the registry settings, and set the control values ReadRegistrySettings (); }
int main_skin_open(char *name) { char pathbuf[MAX_PATH]; char values[32768]; char *textposition; char buffer[4096]; char errorbuf[4096] = ""; // int teller = 0; int returnval; HINSTANCE hInstance; Associate associate[] = { { "PlaySwitch", PlaySwitch }, { "StopSwitch", StopSwitch }, { "PauseSwitch", PauseSwitch }, { "EjectButton", EjectButton }, { "RepeatSwitch", RepeatSwitch }, { "ShuffleSwitch", ShuffleSwitch }, { "EqSwitch", EqSwitch }, { "NextButton", NextButton }, { "PrevButton", PrevButton }, { "PlaylistButton", PlaylistButton }, { "MinimizeButton", MinimizeButton }, { "NextSkinButton", NextSkinButton }, { "ExitButton", ExitButton }, { "MoveArea", MoveArea }, { "VolumeSlider", VolumeSlider }, { "PositionSlider", PositionSlider }, { "Eq1", Eq1 }, { "Eq2", Eq2 }, { "Eq3", Eq3 }, { "Eq4", Eq4 }, { "Eq5", Eq5 }, { "Eq6", Eq6 }, { "Eq7", Eq7 }, { "Eq8", Eq8 }, { "SongtitleText", SongtitleText }, { "TrackText", TrackText }, { "TimeText", TimeText }, { "BitrateText", BitrateText }, { "FreqText", FreqText } }; float positionpercentage; if (Skin.Object[PositionSlider].maxw == 1) { positionpercentage = (float) globals.main_int_track_position / (float) Skin.Object[PositionSlider].h; } else { positionpercentage = (float) globals.main_int_track_position / (float) Skin.Object[PositionSlider].w; } globals.main_int_title_scroll_position = 0; globals.mail_int_title_scroll_max_position = 0; if (*options.main_skin_file == 0) { MessageBox(GetForegroundWindow(), "No Skin file selected!", "Error", MB_ICONERROR); options.use_default_skin = TRUE; return FALSE; } else strcpy(pathbuf, options.main_skin_file); memset(&Skin, 0, sizeof(Skin)); GetPrivateProfileString(NULL, NULL, NULL, buffer, sizeof(buffer), pathbuf); returnval = GetPrivateProfileSection("CoolPlayer Skin", // address of section name values, // address of return buffer 32767, // size of return buffer pathbuf // address of initialization filename ); if (returnval == 0) { char textbuf[MAX_PATH + 50]; sprintf(textbuf, "Not a valid CoolPlayer Skin file: %s", pathbuf); MessageBox(GetForegroundWindow(), textbuf, "error", MB_ICONERROR); options.use_default_skin = TRUE; return FALSE; } textposition = values; while (*textposition != 0) { main_skin_check_ini_value(textposition, associate); textposition = textposition + strlen(textposition) + 1; } path_remove_filespec(pathbuf); strcat(pathbuf, Skin.CoolUp); hInstance = GetModuleHandle(NULL); DeleteObject(graphics.bmp_main_up); graphics.bmp_main_up = (HBITMAP) LoadImage(hInstance, pathbuf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if (!graphics.bmp_main_up) { strcat(errorbuf, pathbuf); strcat(errorbuf, "\n"); } path_remove_filespec(pathbuf); strcat(pathbuf, Skin.CoolDown); DeleteObject(graphics.bmp_main_down); graphics.bmp_main_down = (HBITMAP) LoadImage(hInstance, pathbuf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if (!graphics.bmp_main_down) { strcat(errorbuf, pathbuf); strcat(errorbuf, "\n"); } path_remove_filespec(pathbuf); strcat(pathbuf, Skin.CoolSwitch); DeleteObject(graphics.bmp_main_switch); graphics.bmp_main_switch = (HBITMAP) LoadImage(hInstance, pathbuf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if (!graphics.bmp_main_switch) { strcat(errorbuf, pathbuf); strcat(errorbuf, "\n"); } path_remove_filespec(pathbuf); strcat(pathbuf, Skin.aTimeFont); DeleteObject(graphics.bmp_main_time_font); graphics.bmp_main_time_font = (HBITMAP) LoadImage(hInstance, pathbuf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if (!graphics.bmp_main_time_font) { strcat(errorbuf, pathbuf); strcat(errorbuf, "\n"); } path_remove_filespec(pathbuf); strcat(pathbuf, Skin.aTrackFont); DeleteObject(graphics.bmp_main_track_font); graphics.bmp_main_track_font = (HBITMAP) LoadImage(hInstance, pathbuf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if (!graphics.bmp_main_track_font) { strcat(errorbuf, pathbuf); strcat(errorbuf, "\n"); } path_remove_filespec(pathbuf); strcat(pathbuf, Skin.aTextFont); DeleteObject(graphics.bmp_main_title_font); graphics.bmp_main_title_font = (HBITMAP) LoadImage(hInstance, pathbuf, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if (!graphics.bmp_main_title_font) { strcat(errorbuf, pathbuf); strcat(errorbuf, "\n"); } if (!graphics.bmp_main_up || !graphics.bmp_main_down || !graphics.bmp_main_switch || !graphics.bmp_main_time_font || !graphics.bmp_main_title_font || !graphics.bmp_main_track_font) { char errorstring[5000]; sprintf(errorstring, "Can\'t load bitmaps!\n%s", errorbuf); MessageBox(GetForegroundWindow(), errorstring, "error", MB_ICONERROR); options.use_default_skin = TRUE; return FALSE; } if (Skin.Object[PositionSlider].maxw == 1) { globals.main_int_track_position = (int)((float)(Skin.Object[PositionSlider].h) * positionpercentage); } else { globals.main_int_track_position = (int)((float)(Skin.Object[PositionSlider].w) * positionpercentage); } main_update_title_text(); return 1; }
////////////////////////////////////////////////////////// // // BeginD3DStuff // // Look all busy and important in case any graphic drivers are looking // ////////////////////////////////////////////////////////// void BeginD3DStuff( void ) { pD3D9 = Direct3DCreate9( D3D_SDK_VERSION ); if ( !pD3D9 ) { WriteDebugEvent( "D3DStuff - Direct3DCreate9 failed" ); return; } WriteDebugEvent( "D3DStuff -------------------------" ); WriteDebugEvent( SString( "D3DStuff - Direct3DCreate9: 0x%08x", pD3D9 ) ); // Get info about each connected adapter uint uiNumAdapters = pD3D9->GetAdapterCount(); WriteDebugEvent( SString( "D3DStuff - %d Adapters", uiNumAdapters ) ); for ( uint i = 0 ; i < uiNumAdapters ; i++ ) { D3DADAPTER_IDENTIFIER9 Identifier; D3DDISPLAYMODE DisplayMode; D3DCAPS9 Caps9; HRESULT hr1 = pD3D9->GetAdapterIdentifier( i, 0, &Identifier ); HRESULT hr2 = pD3D9->GetAdapterDisplayMode( i, &DisplayMode ); HRESULT hr3 = pD3D9->GetDeviceCaps( i, D3DDEVTYPE_HAL, &Caps9 ); UINT ModeCount = pD3D9->GetAdapterModeCount( i, D3DFMT_X8R8G8B8 ); HMONITOR hMonitor = pD3D9->GetAdapterMonitor( i ); if ( FAILED( hr1 ) || FAILED( hr2 ) || FAILED( hr3 ) ) { WriteDebugEvent( SString( "D3DStuff %d Failed GetAdapterIdentifier(%x) GetAdapterDisplayMode(%x) GetDeviceCaps(%x) ", i, hr1, hr2, hr3 ) ); continue; } // Detect Optimus combo if ( SStringX( Identifier.Driver ).BeginsWithI( "nv" ) && SStringX( Identifier.Description ).BeginsWithI( "Intel" ) ) { bDetectedOptimus = true; WriteDebugEvent( SString( "D3DStuff %d - Detected Optimus Combo", i ) ); } if ( GetModuleHandle( "nvd3d9wrap.dll" ) != NULL ) { bDetectedOptimus = true; WriteDebugEvent( SString( "D3DStuff %d - Detected nvd3d9wrap", i ) ); } WriteDebugEvent( SString( "D3DStuff %d Identifier - %s", i, *ToString( Identifier ) ) ); WriteDebugEvent( SString( "D3DStuff %d DisplayMode - %s", i, *ToString( DisplayMode ) ) ); WriteDebugEvent( SString( "D3DStuff %d hMonitor:0x%08x ModeCount:%d", i, hMonitor, ModeCount ) ); WriteDebugEvent( SString( "D3DStuff %d Caps9 - %s ", i, *ToString( Caps9 ) ) ); } if ( GetApplicationSettingInt( "nvhacks", "optimus-force-detection" ) ) bDetectedOptimus = true; SetApplicationSettingInt( "nvhacks", "optimus", bDetectedOptimus ); if ( bDetectedOptimus ) { ShowOptimusDialog ( g_hInstance ); HideOptimusDialog (); } else { SetApplicationSettingInt( "nvhacks", "optimus-alt-startup", 0 ); SetApplicationSettingInt( "nvhacks", "optimus-rename-exe", 0 ); SetApplicationSettingInt( "nvhacks", "optimus-export-enablement", 0 ); SetApplicationSettingInt( "nvhacks", "optimus-force-windowed", 0 ); } }
BOOL CreateAppWindow(const char* title, int width, int height, int bits, bool fullscreenflag) { windowWidth = width; windowHeight = height; windowName = title; GLuint PixelFormat; // Holds The Results After Searching For A Match WNDCLASS wc; // Windows Class Structure DWORD dwExStyle; // Window Extended Style DWORD dwStyle; // Window Style RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values WindowRect.left=(long)0; // Set Left Value To 0 WindowRect.right=(long)width; // Set Right Value To Requested Width WindowRect.top=(long)0; // Set Top Value To 0 WindowRect.bottom=(long)height; // Set Bottom Value To Requested Height gFullscreen=fullscreenflag; // Set The Global Fullscreen Flag HICON hIcon = (HICON)LoadImage(0,IDI_WINLOGO,IMAGE_ICON,0,0,LR_SHARED); hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window. wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages wc.cbClsExtra = 0; // No Extra Window Data wc.cbWndExtra = 0; // No Extra Window Data wc.hInstance = hInstance; // Set The Instance wc.hIcon = 0; wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer wc.hbrBackground = NULL; // No Background Required For GL wc.lpszMenuName = NULL; // We Don't Want A Menu wc.lpszClassName = "OpenGL"; // Set The Class Name if (!RegisterClass(&wc)) // Attempt To Register The Window Class { MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if (gFullscreen) // Attempt Fullscreen Mode? { DEVMODE dmScreenSettings; // Device Mode memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure dmScreenSettings.dmPelsWidth = width; // Selected Screen Width dmScreenSettings.dmPelsHeight = height; // Selected Screen Height dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT; // Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar. if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) { // If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode. if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES) { gFullscreen=FALSE; // Windowed Mode Selected. Fullscreen = FALSE } else { // Pop Up A Message Box Letting User Know The Program Is Closing. MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP); return FALSE; // Return FALSE } } } if (gFullscreen) // Are We Still In Fullscreen Mode? { dwExStyle=WS_EX_APPWINDOW; // Window Extended Style dwStyle=WS_POPUP; // Windows Style ShowCursor(FALSE); // Hide Mouse Pointer } else { dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style } AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size // Create The Window if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window "OpenGL", // Class Name title, // Window Title dwStyle | // Defined Window Style WS_CLIPSIBLINGS | // Required Window Style WS_CLIPCHILDREN, // Required Window Style 0, 0, // Window Position WindowRect.right-WindowRect.left, // Calculate Window Width WindowRect.bottom-WindowRect.top, // Calculate Window Height NULL, // No Parent Window NULL, // No Menu hInstance, // Instance NULL))) // Dont Pass Anything To WM_CREATE { CloseWindow(); // Reset The Display MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format bits, // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored 0, // No Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 16, // 16Bit Z-Buffer (Depth Buffer) 0, // No Stencil Buffer 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved 0, 0, 0 // Layer Masks Ignored }; if (!(hDC=GetDC(hWnd))) // Did We Get A Device Context? { CloseWindow(); // Reset The Display MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format? { CloseWindow(); // Reset The Display MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are We Able To Set The Pixel Format? { CloseWindow(); // Reset The Display MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if (!(hRC=wglCreateContext(hDC))) // Are We Able To Get A Rendering Context? { CloseWindow(); // Reset The Display MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } if(!wglMakeCurrent(hDC,hRC)) // Try To Activate The Rendering Context { CloseWindow(); // Reset The Display MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } ShowWindow(hWnd,SW_SHOW); // Show The Window SetForegroundWindow(hWnd); // Slightly Higher Priority SetFocus(hWnd); // Sets Keyboard Focus To The Window ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen if (!InitGL()) // Initialize Our Newly Created GL Window { CloseWindow(); // Reset The Display MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION); return FALSE; // Return FALSE } return TRUE; // Success }
void* getProcessHandle() { return (void*)GetModuleHandle(NULL); }
bool getWindowsVersion(char* version) { int index = 0; OSVERSIONINFOEX osvi = {}; osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); if (!GetVersionEx((OSVERSIONINFO*)&osvi)) return false; if (osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) return false; // Vista if (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0) { if (osvi.wProductType == VER_NT_WORKSTATION) { index += sprintf(version + index, "Microsoft Windows Vista"); uint32_t productType = 0; HMODULE hKernel = GetModuleHandle("KERNEL32.DLL"); if (hKernel) { typedef bool (*funcGetProductInfo)(uint32_t, uint32_t, uint32_t, uint32_t, uint32_t*); funcGetProductInfo pGetProductInfo = (funcGetProductInfo)GetProcAddress(hKernel, "GetProductInfo"); if (pGetProductInfo) pGetProductInfo(6, 0, 0, 0, &productType); switch (productType) { case PRODUCT_STARTER: { index += sprintf(version + index, " Starter"); break; } case PRODUCT_HOME_BASIC_N: { index += sprintf(version + index, " Home Basic N"); break; } case PRODUCT_HOME_BASIC: { index += sprintf(version + index, " Home Basic"); break; } case PRODUCT_HOME_PREMIUM: { index += sprintf(version + index, " Home Premium"); break; } case PRODUCT_BUSINESS_N: { index += sprintf(version + index, " Business N"); break; } case PRODUCT_BUSINESS: { index += sprintf(version + index, " Business"); break; } case PRODUCT_ENTERPRISE: { index += sprintf(version + index, " Enterprise"); break; } case PRODUCT_ULTIMATE: { index += sprintf(version + index, " Ultimate"); break; } default: break; } } } else if (osvi.wProductType == VER_NT_SERVER) { index += sprintf(version + index, "Microsoft Windows Server 2008"); if (osvi.wSuiteMask & VER_SUITE_DATACENTER) index += sprintf(version + index, " Datacenter Edition"); else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) index += sprintf(version + index, " Enterprise Edition"); else if (osvi.wSuiteMask == VER_SUITE_BLADE) index += sprintf(version + index, " Web Edition"); else index += sprintf(version + index, " Standard Edition"); } } // Windows Server 2003 else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2) { index += sprintf(version + index, "Microsoft Windows Server 2003"); if (GetSystemMetrics(SM_SERVERR2)) index += sprintf(version + index, " R2"); if (osvi.wSuiteMask & VER_SUITE_DATACENTER) index += sprintf(version + index, " Datacenter Edition"); else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) index += sprintf(version + index, " Enterprise Edition"); else if (osvi.wSuiteMask == VER_SUITE_BLADE) index += sprintf(version + index, " Web Edition"); else index += sprintf(version + index, " Standard Edition"); } // Windows XP else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) { index += sprintf(version + index, "Microsoft Windows XP"); if (GetSystemMetrics(SM_MEDIACENTER)) index += sprintf(version + index, " Media Center Edition"); else if (GetSystemMetrics(SM_STARTER)) index += sprintf(version + index, " Starter Edition"); else if (GetSystemMetrics(SM_TABLETPC)) index += sprintf(version + index, " Tablet PC Edition"); else if (osvi.wSuiteMask & VER_SUITE_PERSONAL) index += sprintf(version + index, " Home Edition"); else index += sprintf(version + index, " Professional"); } // Windows 2000 else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0) { index += sprintf(version + index, "Microsoft Windows 2000"); if (osvi.wProductType == VER_NT_WORKSTATION) { index += sprintf(version + index, " Professional"); } else if (osvi.wProductType == VER_NT_SERVER) { if (osvi.wSuiteMask & VER_SUITE_DATACENTER) index += sprintf(version + index, " Datacenter Server"); else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) index += sprintf(version + index, " Advanced Server"); else index += sprintf(version + index, " Server"); } } // Windows NT 4 else if (osvi.dwMajorVersion == 4) { index += sprintf(version + index, "Microsoft Windows NT 4"); if (osvi.wProductType == VER_NT_WORKSTATION) { index += sprintf(version + index, " Workstation"); } else if (osvi.wProductType == VER_NT_SERVER) { if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) index += sprintf(version + index, " Server, Enterprise Edition"); else index += sprintf(version + index, " Server"); } } else { index += sprintf(version + index, "Microsoft Windows"); } // Service pack and full version info if (strlen(osvi.szCSDVersion) > 0) { index += sprintf(version + index, " %s", osvi.szCSDVersion); } index += sprintf(version + index, " (%d.%d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.dwBuildNumber & 0xFFFF); // 64-bit Windows bool isWow64 = false; HMODULE hKernel = GetModuleHandle("kernel32.dll"); if (hKernel) { typedef bool (*funcIsWow64Process)(void*, bool*); funcIsWow64Process pIsWow64Process = (funcIsWow64Process)GetProcAddress(hKernel, "IsWow64Process"); if (pIsWow64Process) { pIsWow64Process(GetCurrentProcess(), &isWow64); } } if (isWow64) index += sprintf(version + index, "; 64-bit"); else index += sprintf(version + index, "; 32-bit"); index += sprintf(version + index, ")"); return true; }
PTABDEF OEMDEF::GetXdef(PGLOBAL g) { typedef PTABDEF (__stdcall *XGETDEF) (PGLOBAL, void *); char c, getname[40] = "Get"; PTABDEF xdefp; XGETDEF getdef = NULL; PCATLG cat = Cat; #if defined(WIN32) // Is the DLL already loaded? if (!Hdll && !(Hdll = GetModuleHandle(Module))) // No, load the Dll implementing the function if (!(Hdll = LoadLibrary(Module))) { char buf[256]; DWORD rc = GetLastError(); sprintf(g->Message, MSG(DLL_LOAD_ERROR), rc, Module); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, rc, 0, (LPTSTR)buf, sizeof(buf), NULL); strcat(strcat(g->Message, ": "), buf); return NULL; } // endif hDll // The exported name is always in uppercase for (int i = 0; ; i++) { c = Subtype[i]; getname[i + 3] = toupper(c); if (!c) break; } // endfor i // Get the function returning an instance of the external DEF class if (!(getdef = (XGETDEF)GetProcAddress((HINSTANCE)Hdll, getname))) { sprintf(g->Message, MSG(PROCADD_ERROR), GetLastError(), getname); FreeLibrary((HMODULE)Hdll); return NULL; } // endif getdef #else // !WIN32 const char *error = NULL; // Is the library already loaded? // if (!Hdll && !(Hdll = ???)) // Load the desired shared library if (!(Hdll = dlopen(Module, RTLD_LAZY))) { error = dlerror(); sprintf(g->Message, MSG(SHARED_LIB_ERR), Module, SVP(error)); return NULL; } // endif Hdll // The exported name is always in uppercase for (int i = 0; ; i++) { c = Subtype[i]; getname[i + 3] = toupper(c); if (!c) break; } // endfor i // Get the function returning an instance of the external DEF class if (!(getdef = (XGETDEF)dlsym(Hdll, getname))) { error = dlerror(); sprintf(g->Message, MSG(GET_FUNC_ERR), getname, SVP(error)); dlclose(Hdll); return NULL; } // endif getdef #endif // !WIN32 // Just in case the external Get function does not set error messages sprintf(g->Message, MSG(DEF_ALLOC_ERROR), Subtype); // Get the table definition block if (!(xdefp = getdef(g, NULL))) return NULL; // Have the external class do its complete definition if (!cat->Cbuf) { // Suballocate a temporary buffer for the entire column section cat->Cblen = cat->GetSizeCatInfo("Colsize", "8K"); cat->Cbuf = (char*)PlugSubAlloc(g, NULL, cat->Cblen); } // endif Cbuf // Here "OEM" should be replace by a more useful value if (xdefp->Define(g, cat, Name, "OEM")) return NULL; // Ok, return external block return xdefp; } // end of GetXdef
int TCOD_sys_get_num_cores() { #ifdef TCOD_WINDOWS /* what a crap !!! works only on xp sp3 & vista */ typedef enum _PROCESSOR_CACHE_TYPE { CacheUnified, CacheInstruction, CacheData, CacheTrace } PROCESSOR_CACHE_TYPE; typedef struct _CACHE_DESCRIPTOR { BYTE Level; BYTE Associativity; WORD LineSize; DWORD Size; PROCESSOR_CACHE_TYPE Type; } CACHE_DESCRIPTOR, *PCACHE_DESCRIPTOR; typedef enum _LOGICAL_PROCESSOR_RELATIONSHIP { RelationProcessorCore, RelationNumaNode, RelationCache, RelationProcessorPackage } LOGICAL_PROCESSOR_RELATIONSHIP; typedef struct _SYSTEM_LOGICAL_PROCESSOR_INFORMATION { ULONG_PTR ProcessorMask; LOGICAL_PROCESSOR_RELATIONSHIP Relationship; union { struct { BYTE Flags; } ProcessorCore; struct { DWORD NodeNumber; } NumaNode; CACHE_DESCRIPTOR Cache; ULONGLONG Reserved[2]; }; } SYSTEM_LOGICAL_PROCESSOR_INFORMATION, *PSYSTEM_LOGICAL_PROCESSOR_INFORMATION; typedef BOOL (WINAPI *LPFN_GLPI)( PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, PDWORD); LPFN_GLPI glpi; BOOL done = FALSE; PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL; PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr = NULL; DWORD returnLength = 0; DWORD logicalProcessorCount = 0; DWORD byteOffset = 0; glpi = (LPFN_GLPI) GetProcAddress( GetModuleHandle(TEXT("kernel32")), "GetLogicalProcessorInformation"); if (! glpi) { return 1; } while (!done) { DWORD rc = glpi(buffer, &returnLength); if (FALSE == rc) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) { if (buffer) free(buffer); buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc( returnLength); if (NULL == buffer) { return 1; } } else { return 1; } } else { done = TRUE; } } ptr = buffer; while (byteOffset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= returnLength) { switch (ptr->Relationship) { case RelationProcessorCore: /* A hyperthreaded core supplies more than one logical processor. */ logicalProcessorCount += CountSetBits(ptr->ProcessorMask); break; default: break; } byteOffset += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); ptr++; } free(buffer); return logicalProcessorCount; #else return sysconf(_SC_NPROCESSORS_ONLN); #endif }
int main_set_default_skin(void) { HINSTANCE hInstance; float positionpercentage; if (Skin.Object[PositionSlider].maxw == 1) { positionpercentage = (float) globals.main_int_track_position / (float) Skin.Object[PositionSlider].h; } else { positionpercentage = (float) globals.main_int_track_position / (float) Skin.Object[PositionSlider].w; } globals.main_int_title_scroll_position = 0; globals.mail_int_title_scroll_max_position = 0; memset(&Skin, 0, sizeof(Skin)); main_skin_set_struct_value(PlaySwitch, 172, 23, 24, 16, 0, 19, 60, 24, 7, ""); main_skin_set_struct_value(StopSwitch, 222, 23, 24, 16, 0, 0, 0, 0, 0, ""); main_skin_set_struct_value(PauseSwitch, 197, 23, 24, 16, 0, 197, 23, 25, 17, ""); main_skin_set_struct_value(RepeatSwitch, 197, 57, 24, 16, 0, 96, 60, 35, 7, ""); main_skin_set_struct_value(ShuffleSwitch, 158, 57, 38, 16, 0, 50, 60, 39, 7, ""); main_skin_set_struct_value(EqSwitch, 97, 93, 17, 28, 0, 97, 93, 18, 29, ""); main_skin_set_struct_value(MinimizeButton, 230, 5, 7, 8, 0, 0, 0, 0, 0, ""); main_skin_set_struct_value(ExitButton, 239, 5, 7, 8, 0, 0, 0, 0, 0, ""); main_skin_set_struct_value(NextSkinButton, 254, 44, 9, 27, 0, 0, 0, 0, 0, ""); main_skin_set_struct_value(EjectButton, 222, 40, 24, 16, 0, 0, 0, 0, 0, ""); main_skin_set_struct_value(NextButton, 197, 40, 24, 16, 0, 0, 0, 0, 0, ""); main_skin_set_struct_value(PrevButton, 172, 40, 24, 16, 0, 0, 0, 0, 0, ""); main_skin_set_struct_value(MoveArea, 0, 0, 229, 12, 0, 0, 0, 0, 0, ""); main_skin_set_struct_value(PlaylistButton, 222, 57, 24, 16, 0, 0, 0, 0, 0, ""); main_skin_set_struct_value(VolumeSlider, 84, 95, 9, 75, 1, 0, 0, 0, 0, ""); main_skin_set_struct_value(PositionSlider, 12, 78, 233, 8, 0, 0, 0, 0, 0, ""); main_skin_set_struct_value(Eq1, 115, 95, 9, 75, 1, 0, 0, 0, 0, ""); main_skin_set_struct_value(Eq2, 132, 95, 9, 75, 1, 0, 0, 0, 0, ""); main_skin_set_struct_value(Eq3, 149, 95, 9, 75, 1, 0, 0, 0, 0, ""); main_skin_set_struct_value(Eq4, 166, 95, 9, 75, 1, 0, 0, 0, 0, ""); main_skin_set_struct_value(Eq5, 183, 95, 9, 75, 1, 0, 0, 0, 0, ""); main_skin_set_struct_value(Eq6, 200, 95, 9, 75, 1, 0, 0, 0, 0, ""); main_skin_set_struct_value(Eq7, 217, 95, 9, 75, 1, 0, 0, 0, 0, ""); main_skin_set_struct_value(Eq8, 234, 95, 9, 75, 1, 0, 0, 0, 0, ""); main_skin_set_struct_value(SongtitleText, 18, 21, 6, 13, 23, 0, 0, 0, 0, ""); main_skin_set_struct_value(TrackText, 18, 44, 13, 14, 0, 0, 0, 0, 0, ""); main_skin_set_struct_value(TimeText, 59, 35, 13, 14, 0, 0, 0, 0, 0, ""); main_skin_set_struct_value(BitrateText, 83, 48, 0, 0, 0, 0, 0, 0, 0, ""); main_skin_set_struct_value(FreqText, 125, 48, 0, 0, 0, 0, 0, 0, 0, ""); Skin.transparentcolor = 0x0000ff00; hInstance = GetModuleHandle(NULL); graphics.bmp_main_up = (HBITMAP) LoadImage(hInstance, MAKEINTRESOURCE(IDB_MAINUP), IMAGE_BITMAP, 0, 0, 0L); graphics.bmp_main_down = (HBITMAP) LoadImage(hInstance, MAKEINTRESOURCE(IDB_MAINDOWN), IMAGE_BITMAP, 0, 0, 0L); graphics.bmp_main_switch = graphics.bmp_main_down; graphics.bmp_main_time_font = (HBITMAP) LoadImage(hInstance, MAKEINTRESOURCE(IDB_MAINBIGFONT), IMAGE_BITMAP, 0, 0, 0L); graphics.bmp_main_track_font = graphics.bmp_main_time_font; graphics.bmp_main_title_font = (HBITMAP) LoadImage(hInstance, MAKEINTRESOURCE(IDB_MAINSMALLFONT), IMAGE_BITMAP, 0, 0, 0L); if (Skin.Object[PositionSlider].maxw == 1) { globals.main_int_track_position = (int)((float)(Skin.Object[PositionSlider].h) * positionpercentage); } else { globals.main_int_track_position = (int)((float)(Skin.Object[PositionSlider].w) * positionpercentage); } globals.main_bool_skin_next_is_default = FALSE; main_update_title_text(); main_skin_select_menu("Default"); return TRUE; }
int main(){ HWND hWnd; WNDCLASSEX wc; ZeroMemory(&wc, sizeof(wc)); wc.cbSize = sizeof(WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)WndProc; wc.hInstance = GetModuleHandle(NULL); wc.hCursor = LoadCursorW(NULL, IDC_ARROW); wc.lpszClassName= L"QuadTree"; if(!RegisterClassEx(&wc)) MessageBoxW(NULL, L"RegisterClass Failed", L"ERROR...", MB_OK); if(!(hWnd = CreateWindowEx(NULL, L"QuadTree", L"QuadTree", WS_OVERLAPPEDWINDOW, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, wc.hInstance, NULL))) MessageBoxW(NULL, L"RegisterClass Failed", L"ERROR...", MB_OK); ShowWindow(hWnd, SW_SHOWNORMAL); UpdateWindow(hWnd); srand((unsigned) time(NULL)); dx->SetParameters(hWnd); dx->Light(); dx->SetCamera(); qt = new QuadTree(dx->getDevice()); qt->RunOnce(hWnd); #ifdef GUI_TREE Node* node = new Node(-512, -512, 1024, 1024, dx->getDevice()); #else Node* node = new Node(-512, -512, 1024, 1024); #endif for(int i = 0; i < NUM_OF_SQUARES; i++) node->AddCoordsToRoot(qt->GetModel(i)); node->BuildQuad(); srand(GetTickCount()); MSG msg; while(TRUE){ if(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)){ if(msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } else{ dx->ClearBackBuffer(); dx->Begin(); { node->MoveNode(); //dx->SetCamera(); qt->RenderSquare(); qt->SimulateSquare(); #ifdef GUI_TREE node->DrawGrid(); #endif } dx->End(); } } return msg.wParam; }
void main_skin_check_ini_value(char *textposition, Associate * associate) { char name[128] = ""; int x = 0, y = 0, w = 0, h = 0, maxw = 0, x2 = 0, y2 = 0, w2 = 0, h2 = 0; char tooltip[100] = ""; int teller = 0; while (teller < strlen(textposition)) { if (textposition[teller] == '=' || textposition[teller] == ',') textposition[teller] = ' '; teller++; } // sscanf(textposition, "%s %d %d %d %d %d %d %d %d %d %[^\0]", sscanf(textposition, "%s %d %d %d %d %d %d %d %d %d %s", name, &x, &y, &w, &h, &maxw, &x2, &y2, &w2, &h2, tooltip); for (teller = 0; teller < Lastone; teller++) { if (stricmp(name, associate[teller].name) == 0) { main_skin_set_struct_value(associate[teller].Object, x, y, w, h, maxw, x2, y2, w2, h2, tooltip); return; } if (stricmp(name, "PlaylistSkin") == 0) { char pathbuf[MAX_PATH]; if (path_is_relative(textposition + strlen(name) + 1)) { strcpy(pathbuf, options.main_skin_file); path_remove_filespec(pathbuf); strcat(pathbuf, textposition + strlen(name) + 1); } else strcpy(pathbuf, textposition + strlen(name) + 1); if (!globals.playlist_bool_force_skin_from_options) strcpy(options.playlist_skin_file, pathbuf); } if (stricmp(name, "transparentcolor") == 0) { int colortext; sscanf(textposition, "%s %x", name, &colortext); Skin.transparentcolor = colortext; return; } if (stricmp(name, "BmpCoolUp") == 0) { strcpy(Skin.CoolUp, textposition + strlen(name) + 1); } if (stricmp(name, "BmpCoolDown") == 0) { strcpy(Skin.CoolDown, textposition + strlen(name) + 1); } if (stricmp(name, "BmpCoolSwitch") == 0) { strcpy(Skin.CoolSwitch, textposition + strlen(name) + 1); } if (stricmp(name, "BmpTextFont") == 0) { strcpy(Skin.aTextFont, textposition + strlen(name) + 1); } if (stricmp(name, "BmpTimeFont") == 0) { strcpy(Skin.aTimeFont, textposition + strlen(name) + 1); } if (stricmp(name, "BmpTrackFont") == 0) { strcpy(Skin.aTrackFont, textposition + strlen(name) + 1); } if (stricmp(name, "NextSkin") == 0) { if (stricmp(textposition + strlen(name) + 1, "default") == 0) { globals.main_bool_skin_next_is_default = TRUE; } else { char drive[_MAX_DRIVE]; char fname[MAX_PATH]; char modpathbuf[MAX_PATH]; char ext[_MAX_EXT]; char dir[_MAX_DIR]; char skinfile2[MAX_PATH]; strcpy(skinfile2, options.main_skin_file); path_remove_filespec(skinfile2); main_get_program_path(GetModuleHandle(NULL), modpathbuf, MAX_PATH); _splitpath(textposition + strlen(name) + 1, drive, dir, fname, ext); if (strcmp(drive, "") == 0) { sprintf(options.main_skin_file, "%s%s%s", skinfile2, fname, ext); } else strcpy(options.main_skin_file, textposition + strlen(name) + 1); if (_access(options.main_skin_file, 0) == -1) { sprintf(options.main_skin_file, "%s%s%s%s", modpathbuf, dir, fname, ext); } globals.main_bool_skin_next_is_default = FALSE; } } } }
bool Instance_LocateModule(char * name, char * fileName) { #if defined(__WIN32__) HMODULE hModule = null; if(name && name[0]) { uint16 _wmoduleName[MAX_LOCATION]; UTF8toUTF16Buffer(name, _wmoduleName, MAX_LOCATION); hModule = GetModuleHandle(_wmoduleName); if(!hModule) { wcscat(_wmoduleName, L".exe"); hModule = GetModuleHandle(_wmoduleName); } if(hModule) { uint16 _wfileName[MAX_LOCATION]; GetModuleFileNameW(hModule, _wfileName, MAX_LOCATION); UTF16toUTF8Buffer(_wfileName, (byte *)fileName, MAX_LOCATION); return true; } } else { uint16 _wfileName[MAX_LOCATION]; GetModuleFileNameW(null, _wfileName, MAX_LOCATION); UTF16toUTF8Buffer(_wfileName, (byte *)fileName, MAX_LOCATION); return true; } #elif defined(__APPLE__) if(name && name[0]) { int imageCount = _dyld_image_count(); int c; int nameLen = strlen(name); for(c = 0; c<imageCount; c++) { struct mach_header * header = _dyld_get_image_header(c); char * path = _dyld_get_image_name(c); int pathLen = strlen(path); char * subStr = RSearchString(path, name, pathLen, false, false); if(subStr) { if(( *(subStr-1) == '/' || !strncmp(subStr - 4, "/lib", 4)) && (!subStr[nameLen] || !strncmp(subStr + nameLen, ".dylib", 6))) { strcpy(fileName, path); return true; } } } } else { int size = MAX_LOCATION; _NSGetExecutablePath(fileName, &size); return true; } #elif defined(__unix__) //File f = FileOpen("/proc/self/maps", read); FILE * f; char exeName[MAX_FILENAME]; exeName[0] = 0; #if defined(__linux__) f = fopen("/proc/self/status", "r"); #else f = fopen("/proc/curproc/status", "r"); #endif if(f) { char line[1025]; while(fgets(line, sizeof(line), f)) { char * name = strstr(line, "Name:\t"); if(name) { int nameLen; name += 6; nameLen = strlen(name); name[--nameLen] = 0; strcpy(exeName, name); break; } } fclose(f); } #if defined(__linux__) f = fopen("/proc/self/maps", "r"); #else f = fopen("/proc/curproc/map", "r"); #endif if(f) { char line[1025]; //while(f.GetLine(line, sizeof(line))) while(fgets(line, sizeof(line), f)) { char * path = strstr(line, "/"); if(path) { int pathLen = strlen(path); path[--pathLen] = 0; if(name && name[0]) { int nameLen = strlen(name); char * subStr; subStr = RSearchString(path, name, pathLen, false, false); if(subStr) { if(( *(subStr-1) == '/' || !strncmp(subStr - 4, "/lib", 4)) && (!subStr[nameLen] || !strncmp(subStr + nameLen, ".so", 3))) { char * space = strchr(path, ' '); if(space) *space = 0; strcpy(fileName, path); fclose(f); return true; } } } else { char name[MAX_FILENAME]; GetLastDirectory(path, name); if(!exeName[0] || !strcmp(name, exeName)) { char * space = strchr(path, ' '); if(space) *space = 0; strcpy(fileName, path); fclose(f); return true; } } } } fclose(f); } if(!name || !name[0]) { strcpy(fileName, exeLocation); return true; } #endif return false; }
//游戏结束 LRESULT CGameClientDlg::OnGameOver(WPARAM wParam,LPARAM lParam) { //设置状态 SetGameStatus(GS_FREE); if(!m_bExitTag) { if(m_cbPlayStatus[m_wMeChairID] == TRUE) m_GameClientView.m_CardControl[m_wMeChairID].SetCardData(m_cbHandCardData[m_wMeChairID],2); } else { //胜利列表 UserWinList WinnerList; //临时数据 BYTE bTempData[GAME_PLAYER][MAX_CENTERCOUNT]; CopyMemory(bTempData,m_cbOverCardData,GAME_PLAYER*MAX_CENTERCOUNT); //查找胜利者 m_GameLogic.SelectMaxUser(bTempData,WinnerList,NULL); ASSERT(WinnerList.bSameCount>0); //设置扑克 for (WORD i = 0;i<GAME_PLAYER;i++) { if(m_cbPlayStatus[i] == TRUE) m_GameClientView.m_CardControl[i].SetCardData(m_cbHandCardData[i],2); else m_GameClientView.m_CardControl[i].SetCardData(NULL,0); } //特效变量 bool wIsMyWin =false ; WORD wWinnerID = INVALID_CHAIR; BYTE cbEffectHandCard[MAX_COUNT]; BYTE cbEffectCenterCardData[MAX_CENTERCOUNT]; ZeroMemory(cbEffectHandCard,sizeof(cbEffectHandCard)); ZeroMemory(cbEffectCenterCardData,sizeof(cbEffectCenterCardData)); BYTE bTempCount1,bTempCount2; //查找胜利扑克 for (WORD i=0;i<WinnerList.bSameCount;i++) { wWinnerID=WinnerList.wWinerList[i]; if(!wIsMyWin && m_wMeChairID==WinnerList.wWinerList[i]) { wIsMyWin = true; } //查找扑克数据 BYTE bTempCount1=m_GameLogic.GetSameCard(m_cbHandCardData[wWinnerID],bTempData[wWinnerID],MAX_COUNT,MAX_CENTERCOUNT,cbEffectHandCard); BYTE bTempCount2=m_GameLogic.GetSameCard(m_cbCenterCardData,bTempData[wWinnerID],MAX_CENTERCOUNT,MAX_CENTERCOUNT,cbEffectCenterCardData); ASSERT(bTempCount1+bTempCount2<=MAX_CENTERCOUNT); //设置扑克特效数据 m_GameClientView.m_CardControl[wWinnerID].SetCardEffect(cbEffectHandCard,bTempCount1); m_GameClientView.m_CenterCardControl.SetCardEffect(cbEffectCenterCardData,bTempCount2); } //自己扑克 if(!wIsMyWin) { wWinnerID = m_wMeChairID; //自己扑克数据 ZeroMemory(cbEffectHandCard,sizeof(cbEffectHandCard)); ZeroMemory(cbEffectCenterCardData,sizeof(cbEffectCenterCardData)); //查找扑克数据 bTempCount1=m_GameLogic.GetSameCard(m_cbHandCardData[wWinnerID],bTempData[wWinnerID],MAX_COUNT,MAX_CENTERCOUNT,cbEffectHandCard); bTempCount2=m_GameLogic.GetSameCard(m_cbCenterCardData,bTempData[wWinnerID],MAX_CENTERCOUNT,MAX_CENTERCOUNT,cbEffectCenterCardData); ASSERT(bTempCount1+bTempCount2<=MAX_CENTERCOUNT); //设置标志扑克数据 m_GameClientView.m_CardControl[wWinnerID].SetMyCard(cbEffectHandCard,bTempCount1); m_GameClientView.m_CenterCardControl.SetMyCard(cbEffectCenterCardData,bTempCount2); } //游戏结束 m_GameClientView.SetGameEndStart(); } //赢金币 for (WORD i =0;i<GAME_PLAYER;i++) { if(m_cbPlayStatus[i] == FALSE) continue; if(m_dEndScore[i]>0L) { m_lCenterScore = m_lCenterScore -m_dEndScore[i]-m_lTotalScore[i]; m_GameClientView.UpdateWindow(); m_GameClientView.DrawMoveAnte(i,CGameClientView::AA_CENTER_TO_BASEFROM,m_dEndScore[i]+m_lTotalScore[i]); m_GameClientView.SetCenterScore(m_lCenterScore); } else if(m_dEndScore[i] == 0L) { m_GameClientView.DrawMoveAnte(i,CGameClientView::AA_CENTER_TO_BASEFROM,m_lTotalScore[i]); m_lCenterScore = m_lCenterScore-m_lTotalScore[i]; m_GameClientView.SetCenterScore(m_lCenterScore); m_GameClientView.UpdateWindow(); } m_GameClientView.SetTotalScore(i,0L); m_GameClientView.UpdateWindow(); } //播放声音 if (IsLookonMode()==false) { if (m_dEndScore[m_wMeChairID]>=0L) PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_WIN")); else PlayGameSound(AfxGetInstanceHandle(),TEXT("GAME_LOST")); } else PlayGameSound(GetModuleHandle(NULL),TEXT("GAME_END")); if(m_cbPlayStatus[m_wMeChairID]==TRUE && !IsLookonMode()) { //调整位置 CRect rcControl; m_GameClientView.m_ScoreView.GetWindowRect(&rcControl); CRect rcView ; m_GameClientView.GetWindowRect( &rcView ); m_GameClientView.m_ScoreView.MoveWindow(rcView.left+5,rcView.bottom-15-rcControl.Height()*3/2,rcControl.Width(),rcControl.Height()/*nWidth/2-rcControl.Width()/2,nHeight/2+56,0,0,SWP_NOZORDER|SWP_NOSIZE*/); m_GameClientView.m_ScoreView.SetGameScore(m_wMeChairID,m_dEndScore[m_wMeChairID]); m_GameClientView.m_ScoreView.ShowWindow(SW_SHOW); m_GameClientView.m_ScoreView.SetShowTimes(); } if(!IsLookonMode()) { //开牌按钮 if(m_bOpenCard) { m_GameClientView.m_btOpenCard.ShowWindow(SW_SHOW); } if (m_GameClientView.m_ScoreView.IsWindowVisible()==TRUE) { m_GameClientView.m_ScoreView.SetStartTimes(); } else if(m_bAutoStart==FALSE) { SetGameTimer(m_wMeChairID,IDI_START_GAME,TIME_START_GAME); } else //自动开始 { m_GameClientView.m_ScoreView.SetStartTimes(); m_GameClientView.m_ScoreView.SetShowTimes(); //OnStart(0,0); } } //状态设置 KillGameTimer(IDI_USER_ADD_SCORE); //开始按钮 if (!IsLookonMode() && m_bAutoStart==FALSE) { m_GameClientView.m_btStart.ShowWindow(SW_SHOW); m_GameClientView.m_btExit.ShowWindow(SW_SHOW); } //成绩显示在即时聊天对话框 TCHAR szBuffer[256]=TEXT(""); _snprintf(szBuffer,CountArray(szBuffer),TEXT("\n本局结束,成绩统计")); InsertGeneralString(szBuffer,RGB(0,128,255),true); if(m_bReset) { for (WORD i=0;i<GAME_PLAYER;i++) { if(m_lTotalScore[i]==0)continue; const tagUserData * pUserData=GetUserData(i); //成绩输出 if (pUserData!=NULL) { _snprintf(szBuffer,CountArray(szBuffer),TEXT("%s:%+ld"),/*%s玩家\n得分:%ld*/ pUserData->szName,m_dEndScore[i]); InsertGeneralString(szBuffer,RGB(0,128,255),true); } else { _snprintf(szBuffer,CountArray(szBuffer),TEXT("用户已离开:%+ld"),-m_lTotalScore[i]);/*\n得分:%ld*/ InsertGeneralString(szBuffer,RGB(0,128,255),true); } } } else //不足金额 { for (WORD i=0;i<GAME_PLAYER;i++) { if(m_lTotalScore[i]==0)continue; //成绩输出 if (m_bUserName[i]!=NULL) { _snprintf(szBuffer,CountArray(szBuffer),TEXT("%s:%+ld"), &m_bUserName[i],m_dEndScore[i]); InsertGeneralString(szBuffer,RGB(0,128,255),true); } else { _snprintf(szBuffer,CountArray(szBuffer),TEXT("用户已离开:%+ld"),-m_lTotalScore[i]); InsertGeneralString(szBuffer,RGB(0,128,255),true); } } } //重值变量 ZeroMemory(m_lTotalScore,sizeof(m_lTotalScore)); ZeroMemory(m_lTableScore,sizeof(m_lTableScore)); m_lCenterScore = 0L; return 0; }
int usb_install_driver_np(const char *inf_file) { HDEVINFO dev_info; SP_DEVINFO_DATA dev_info_data; INFCONTEXT inf_context; HINF inf_handle; DWORD config_flags, problem, status; BOOL reboot; char inf_path[MAX_PATH]; char id[MAX_PATH]; char tmp_id[MAX_PATH]; char *p; int dev_index; HINSTANCE newdev_dll = NULL; HMODULE setupapi_dll = NULL; update_driver_for_plug_and_play_devices_t UpdateDriverForPlugAndPlayDevices; setup_copy_oem_inf_t SetupCopyOEMInf; newdev_dll = LoadLibrary("newdev.dll"); if(!newdev_dll) { usb_error("usb_install_driver(): loading newdev.dll failed\n"); return -1; } UpdateDriverForPlugAndPlayDevices = (update_driver_for_plug_and_play_devices_t) GetProcAddress(newdev_dll, "UpdateDriverForPlugAndPlayDevicesA"); if(!UpdateDriverForPlugAndPlayDevices) { usb_error("usb_install_driver(): loading newdev.dll failed\n"); return -1; } setupapi_dll = GetModuleHandle("setupapi.dll"); if(!setupapi_dll) { usb_error("usb_install_driver(): loading setupapi.dll failed\n"); return -1; } SetupCopyOEMInf = (setup_copy_oem_inf_t) GetProcAddress(setupapi_dll, "SetupCopyOEMInfA"); if(!SetupCopyOEMInf) { usb_error("usb_install_driver(): loading setupapi.dll failed\n"); return -1; } dev_info_data.cbSize = sizeof(SP_DEVINFO_DATA); /* retrieve the full .inf file path */ if(!GetFullPathName(inf_file, MAX_PATH, inf_path, NULL)) { usb_error("usb_install_driver(): .inf file %s not found\n", inf_file); return -1; } /* open the .inf file */ inf_handle = SetupOpenInfFile(inf_path, NULL, INF_STYLE_WIN4, NULL); if(inf_handle == INVALID_HANDLE_VALUE) { usb_error("usb_install_driver(): unable to open .inf file %s\n", inf_file); return -1; } /* find the .inf file's device description section marked "Devices" */ if(!SetupFindFirstLine(inf_handle, "Devices", NULL, &inf_context)) { usb_error("usb_install_driver(): .inf file %s does not contain " "any device descriptions\n", inf_file); SetupCloseInfFile(inf_handle); return -1; } do { /* get the device ID from the .inf file */ if(!SetupGetStringField(&inf_context, 2, id, sizeof(id), NULL)) { continue; } /* convert the string to lowercase */ strlwr(id); reboot = FALSE; /* copy the .inf file to the system directory so that is will be found */ /* when new devices are plugged in */ SetupCopyOEMInf(inf_path, NULL, SPOST_PATH, 0, NULL, 0, NULL, NULL); /* update all connected devices matching this ID, but only if this */ /* driver is better or newer */ UpdateDriverForPlugAndPlayDevices(NULL, id, inf_path, INSTALLFLAG_FORCE, &reboot); /* now search the registry for device nodes representing currently */ /* unattached devices */ /* get all USB device nodes from the registry, present and non-present */ /* devices */ dev_info = SetupDiGetClassDevs(NULL, "USB", NULL, DIGCF_ALLCLASSES); if(dev_info == INVALID_HANDLE_VALUE) { SetupCloseInfFile(inf_handle); break; } dev_index = 0; /* enumerate the device list to find all attached and unattached */ /* devices */ while(SetupDiEnumDeviceInfo(dev_info, dev_index, &dev_info_data)) { /* get the harware ID from the registry, this is a multi-zero string */ if(SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_HARDWAREID, NULL, (BYTE *)tmp_id, sizeof(tmp_id), NULL)) { /* check all possible IDs contained in that multi-zero string */ for(p = tmp_id; *p; p += (strlen(p) + 1)) { /* convert the string to lowercase */ strlwr(p); /* found a match? */ if(strstr(p, id)) { /* is this device disconnected? */ if(CM_Get_DevNode_Status(&status, &problem, dev_info_data.DevInst, 0) == CR_NO_SUCH_DEVINST) { /* found a device node that represents an unattached */ /* device */ if(SetupDiGetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_CONFIGFLAGS, NULL, (BYTE *)&config_flags, sizeof(config_flags), NULL)) { /* mark the device to be reinstalled the next time it is */ /* plugged in */ config_flags |= CONFIGFLAG_REINSTALL; /* write the property back to the registry */ SetupDiSetDeviceRegistryProperty(dev_info, &dev_info_data, SPDRP_CONFIGFLAGS, (BYTE *)&config_flags, sizeof(config_flags)); } } /* a match was found, skip the rest */ break; } } } /* check the next device node */ dev_index++; } SetupDiDestroyDeviceInfoList(dev_info); /* get the next device ID from the .inf file */ } while(SetupFindNextLine(&inf_context, &inf_context)); /* we are done, close the .inf file */ SetupCloseInfFile(inf_handle); usb_registry_stop_libusb_devices(); /* stop all libusb devices */ usb_registry_start_libusb_devices(); /* restart all libusb devices */ return 0; }
extern "C" LONG APIENTRY CPlApplet(HWND hwndCPl, UINT uMsg, LONG lParam1, LONG lParam2) { LPNEWCPLINFO lpNewCPlInfo; LPCPLINFO lpCPlInfo; SHELLEXECUTEINFO shellExecInfo; switch (uMsg) { case CPL_INIT: /* first message, sent once */ hinst = GetModuleHandle("afs_cpa.cpl"); hinstResources = TaLocale_LoadCorrespondingModule (hinst); CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); return (hinst != 0); case CPL_GETCOUNT: /* second message, sent once */ return 1; case CPL_INQUIRE: /* in case we receive this we should indicate that we like NEWINQUIRE better. */ lpCPlInfo = (CPLINFO *) lParam2; lpCPlInfo->idIcon = ((IsClientInstalled() || !IsWindowsNT())? IDI_AFSD : IDI_CCENTER); lpCPlInfo->idName = CPL_DYNAMIC_RES; lpCPlInfo->idInfo = CPL_DYNAMIC_RES; lpCPlInfo->lData = 0; break; case CPL_NEWINQUIRE: /* third message, sent once per app */ lpNewCPlInfo = (LPNEWCPLINFO) lParam2; lpNewCPlInfo->dwSize = (DWORD) sizeof(NEWCPLINFO); lpNewCPlInfo->dwFlags = 0; lpNewCPlInfo->dwHelpContext = 0; lpNewCPlInfo->lData = 0; if (IsClientInstalled() || !IsWindowsNT()) lpNewCPlInfo->hIcon = TaLocale_LoadIcon(IDI_AFSD); else lpNewCPlInfo->hIcon = TaLocale_LoadIcon(IDI_CCENTER); lpNewCPlInfo->szHelpFile[0] = '\0'; GetString (lpNewCPlInfo->szName, (!IsWindowsNT()) ? IDS_CPL_NAME_95 : (!IsClientInstalled()) ? IDS_CPL_NAME_CCENTER : IDS_CPL_NAME_NT); GetString (lpNewCPlInfo->szInfo, (!IsWindowsNT()) ? IDS_CPL_DESC_95 : (!IsClientInstalled()) ? IDS_CPL_DESC_CCENTER : IDS_CPL_DESC_NT); break; case CPL_DBLCLK: /* applet icon double-clicked */ memset(&shellExecInfo, 0, sizeof(shellExecInfo)); shellExecInfo.cbSize = sizeof(shellExecInfo); shellExecInfo.nShow = SW_SHOWNORMAL; shellExecInfo.hwnd = hwndCPl; shellExecInfo.lpFile = "afs_config.exe"; if (!IsClientInstalled() && IsWindowsNT()) shellExecInfo.lpParameters = "/c"; ShellExecuteEx(&shellExecInfo); break; case CPL_EXIT: CoUninitialize(); if (hinstResources) FreeLibrary (hinstResources); break; } return 0; }
//----------------------------------------------------------------------------- // Name: wWinMain() // Desc: The application's entry point //----------------------------------------------------------------------------- INT WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, INT) { UNREFERENCED_PARAMETER(hInst); CKT::CFileReader* pIniReader = NULL; pIniReader = new CKT::CFileReader(); pIniReader->init(L"..\\RES\\STARTUP.INI"); pIniReader->read(); // Register the window class WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, CKT::CEngine::WINDOW_CLASS_NAME, NULL }; RegisterClassEx(&wc); // choose only, from graphicscard, supported Resolution RECT winRect; winRect.left = 8; winRect.right = 800 + winRect.left; winRect.top = 31; winRect.bottom = 600 + winRect.top; if (pIniReader && pIniReader->hasRead()) { winRect.right = winRect.left + pIniReader->getEntryAsInt(L"WIDTH", L"GRAPHIC"); winRect.bottom = winRect.top + pIniReader->getEntryAsInt(L"HEIGHT", L"GRAPHIC"); } AdjustWindowRect(&winRect, WS_OVERLAPPEDWINDOW, false); std::wstring sAppName = L"CKT - ENGINE : Test"; if (pIniReader && pIniReader->hasRead()) { sAppName = pIniReader->getEntryAsString(L"APPNAME", L"GENERAL"); } // Create the application's window HWND hWnd = CreateWindow( CKT::CEngine::WINDOW_CLASS_NAME, sAppName.c_str(), WS_OVERLAPPEDWINDOW, winRect.left, winRect.top, winRect.right, winRect.bottom, NULL, NULL, wc.hInstance, NULL); g_pGame = new CMyGame(hWnd, *pIniReader); g_pGame->GameLoop(); CKT_RELEASE(g_pGame); if (pIniReader) { delete pIniReader; pIniReader = NULL; } UnregisterClass(CKT::CEngine::WINDOW_CLASS_NAME, wc.hInstance); return 0; }
return true; } #endif static void do_symlink(const char *old, const char *new, int is_dir) { #ifndef GIT_WIN32 GIT_UNUSED(is_dir); cl_must_pass(symlink(old, new)); #else typedef DWORD (WINAPI *create_symlink_func)(LPCTSTR, LPCTSTR, DWORD); HMODULE module; create_symlink_func pCreateSymbolicLink; cl_assert(module = GetModuleHandle("kernel32")); cl_assert(pCreateSymbolicLink = (create_symlink_func)GetProcAddress(module, "CreateSymbolicLinkA")); cl_win32_pass(pCreateSymbolicLink(new, old, is_dir)); #endif } static void do_hardlink(const char *old, const char *new) { #ifndef GIT_WIN32 cl_must_pass(link(old, new)); #else typedef DWORD (WINAPI *create_hardlink_func)(LPCTSTR, LPCTSTR, LPSECURITY_ATTRIBUTES); HMODULE module; create_hardlink_func pCreateHardLink;
INT_PTR CALLBACK DlgVideoConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_INITDIALOG: { g_hDisplayAdapter = GetDlgItem(hWndDlg, IDC_VC_DISPLAY_ADAPTER); g_hDirect3DDevice = GetDlgItem(hWndDlg, IDC_VC_D3D_DEVICE); g_hVideoResolution = GetDlgItem(hWndDlg, IDC_VC_VIDEO_RESOLUTION); /*! set window icon */ SetClassLong(hWndDlg, GCL_HICON, (LONG)LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_CXBX))); /*! enumerate display adapters */ { SendMessage(g_hDisplayAdapter, CB_RESETCONTENT, 0, 0); for(uint32 v=0;v<g_dwAdapterCount;v++) { #ifndef D3D9 XTL::D3DADAPTER_IDENTIFIER8 adapterIdentifier; g_pD3D8->GetAdapterIdentifier(v, D3DENUM_NO_WHQL_LEVEL, &adapterIdentifier); #else XTL::D3DADAPTER_IDENTIFIER9 adapterIdentifier; g_pD3D8->GetAdapterIdentifier(v, 0, &adapterIdentifier); #endif if(v == 0) { SendMessage(g_hDisplayAdapter, CB_ADDSTRING, 0, (LPARAM)"Primary Display Adapter"); } else { SendMessage(g_hDisplayAdapter, CB_ADDSTRING, 0, (LPARAM)adapterIdentifier.Description); } } } /*! activate configured display adapter */ SendMessage(g_hDisplayAdapter, CB_SETCURSEL, g_XBVideo->GetDisplayAdapter(), 0); /*! refresh UI based on currently selected display adapter */ RefreshDisplayAdapter(); /*! check appropriate options */ { SendMessage(GetDlgItem(hWndDlg, IDC_CV_FULLSCREEN), BM_SETCHECK, (WPARAM)g_XBVideo->GetFullscreen(), 0); SendMessage(GetDlgItem(hWndDlg, IDC_CV_VSYNC), BM_SETCHECK, (WPARAM)g_XBVideo->GetVSync(), 0); SendMessage(GetDlgItem(hWndDlg, IDC_CV_HARDWAREYUV), BM_SETCHECK, (WPARAM)g_XBVideo->GetHardwareYUV(), 0); } } break; case WM_CLOSE: { /*! if changes have been made, check if the user wants to save them */ if(g_bHasChanges) { int ret = MessageBox(hWndDlg, "Do you wish to apply your changes?", "Cxbx", MB_ICONQUESTION | MB_YESNOCANCEL); switch(ret) { case IDYES: PostMessage(hWndDlg, WM_COMMAND, IDC_VC_ACCEPT, 0); break; case IDNO: PostMessage(hWndDlg, WM_COMMAND, IDC_VC_CANCEL, 0); break; } break; } PostMessage(hWndDlg, WM_COMMAND, IDC_VC_CANCEL, 0); } break; case WM_COMMAND: { HWND hWndButton = GetDlgItem(hWndDlg, LOWORD(wParam)); switch(LOWORD(wParam)) { case IDC_VC_ACCEPT: /*! save video resolution configuration */ { HWND hVideoResolution = GetDlgItem(hWndDlg, IDC_VC_VIDEO_RESOLUTION); LRESULT lRet = SendMessage(hVideoResolution, CB_GETCURSEL, 0, 0); char szBuffer[128]; lRet = SendMessage(hVideoResolution, CB_GETLBTEXT, (WPARAM)lRet, (LPARAM)szBuffer); g_XBVideo->SetVideoResolution(szBuffer); } /*! save fullscreen/vsync/YUV options */ { LRESULT lRet = SendMessage(GetDlgItem(hWndDlg, IDC_CV_FULLSCREEN), BM_GETCHECK, 0, 0); g_XBVideo->SetFullscreen(lRet == BST_CHECKED); lRet = SendMessage(GetDlgItem(hWndDlg, IDC_CV_VSYNC), BM_GETCHECK, 0, 0); g_XBVideo->SetVSync(lRet == BST_CHECKED); lRet = SendMessage(GetDlgItem(hWndDlg, IDC_CV_HARDWAREYUV), BM_GETCHECK, 0, 0); g_XBVideo->SetHardwareYUV(lRet == BST_CHECKED); } /*! save video configuration */ g_EmuShared->SetXBVideo(g_XBVideo); case IDC_VC_CANCEL: free(g_XBVideo); g_XBVideo = NULL; EndDialog(hWndDlg, wParam); break; case IDC_VC_DISPLAY_ADAPTER: { if(HIWORD(wParam) == CBN_SELCHANGE) { RefreshDisplayAdapter(); break; } } break; case IDC_VC_D3D_DEVICE: { if(HIWORD(wParam) == CBN_SELCHANGE) { RefreshDirect3DDevice(); break; } } break; } } break; } return FALSE; }
void System::InitializeWindows(int& screenWidth, int& screenHeight){ WNDCLASSEX wcex; DEVMODE dmScreenSettings; int posX, posY; // get an external pointed to this object ApplicationHandle = this; // get the instance of this application m_hInstance = GetModuleHandle(NULL); // give the application a name m_applicationName = L"Engine"; // setup the windows class with default settings wcex.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = m_hInstance; wcex.hIcon = LoadIcon(NULL, IDI_WINLOGO); wcex.hIconSm = wcex.hIcon; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); wcex.lpszMenuName = NULL; wcex.lpszClassName = m_applicationName; wcex.cbSize = sizeof(WNDCLASSEX); // register window class RegisterClassEx(&wcex); // get resolution of screen screenWidth = GetSystemMetrics(SM_CXSCREEN); screenHeight = GetSystemMetrics(SM_CYSCREEN); // setup screen settings if (FULL_SCREEN){ // set to max size of desktop memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); dmScreenSettings.dmSize = sizeof(dmScreenSettings); dmScreenSettings.dmPelsWidth = (unsigned long)screenWidth; dmScreenSettings.dmPelsHeight = (unsigned long)screenHeight; dmScreenSettings.dmBitsPerPel = 64; // 64-bit dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; // change display settings to fullscreen ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN); // position window top left posX = posY = 0; } else{ // windowed 800x600 screenWidth = 800; screenHeight = 600; // centre window posX = (GetSystemMetrics(SM_CXSCREEN) - screenWidth) / 2; posY = (GetSystemMetrics(SM_CYSCREEN) - screenHeight) / 2; } // create window with settings m_hwnd = CreateWindowEx(WS_EX_APPWINDOW, m_applicationName, m_applicationName, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUP, posX, posY, screenWidth, screenHeight, NULL, NULL, m_hInstance, NULL); // show and focus window ShowWindow(m_hwnd, SW_SHOW); SetForegroundWindow(m_hwnd); SetFocus(m_hwnd); // hide cursor ShowCursor(false); }
bool WinServiceInstall() { CSD_T ChangeService_Config2; HMODULE advapi32; SC_HANDLE serviceControlManager = OpenSCManager(0, 0, SC_MANAGER_CREATE_SERVICE); if (serviceControlManager) { char path[_MAX_PATH + 10]; if (GetModuleFileName( 0, path, sizeof(path)/sizeof(path[0]) ) > 0) { SC_HANDLE service; std::strcat(path, " -s run"); service = CreateService(serviceControlManager, serviceName, // name of service serviceLongName, // service name to display SERVICE_ALL_ACCESS, // desired access // service type SERVICE_WIN32_OWN_PROCESS | SERVICE_INTERACTIVE_PROCESS, SERVICE_AUTO_START, // start type SERVICE_ERROR_IGNORE, // error control type path, // service's binary 0, // no load ordering group 0, // no tag identifier 0, // no dependencies 0, // LocalSystem account 0); // no password if (service) { advapi32 = GetModuleHandle("ADVAPI32.DLL"); if(!advapi32) { CloseServiceHandle(service); CloseServiceHandle(serviceControlManager); return false; } ChangeService_Config2 = (CSD_T) GetProcAddress(advapi32, "ChangeServiceConfig2A"); if (!ChangeService_Config2) { CloseServiceHandle(service); CloseServiceHandle(serviceControlManager); return false; } SERVICE_DESCRIPTION sdBuf; sdBuf.lpDescription = serviceDescription; ChangeService_Config2( service, // handle to service SERVICE_CONFIG_DESCRIPTION, // change: description &sdBuf); // new data SC_ACTION _action[1]; _action[0].Type = SC_ACTION_RESTART; _action[0].Delay = 10000; SERVICE_FAILURE_ACTIONS sfa; ZeroMemory(&sfa, sizeof(SERVICE_FAILURE_ACTIONS)); sfa.lpsaActions = _action; sfa.cActions = 1; sfa.dwResetPeriod =INFINITE; ChangeService_Config2( service, // handle to service SERVICE_CONFIG_FAILURE_ACTIONS, // information level &sfa); // new data CloseServiceHandle(service); } } CloseServiceHandle(serviceControlManager); } return true; }
bool WindowWin32::Create( const unsigned int width, const unsigned int height, const bool requestFullscreen, const char* windowTitle, const unsigned int bits) { m_width = width; m_height = height; m_isFullscreen = requestFullscreen; DWORD dwExStyle; // extended window style DWORD dwStyle; // window style // setup window rectangle (size) m_windowRect.left = (long)0; m_windowRect.right = (long)width; m_windowRect.top = (long)0; m_windowRect.bottom = (long)height; m_moduleHandle = GetModuleHandle(NULL); // setup window parameters m_window.cbSize = sizeof(WNDCLASSEX); m_window.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; m_window.lpfnWndProc = WindowWin32::StaticWndProc; m_window.cbClsExtra = 0; m_window.cbWndExtra = 0; m_window.hInstance = m_moduleHandle; m_window.hIcon = LoadIcon(NULL, IDI_WINLOGO); m_window.hCursor = LoadCursor(NULL, IDC_ARROW); m_window.hbrBackground = NULL; m_window.lpszMenuName = NULL; m_window.lpszClassName = "Window"; // create window class if (!RegisterClassEx(&m_window)) { printf("Failed to rigister the window class", (LPWSTR)"ERROR", MB_OK | MB_ICONINFORMATION); return false; } // setup fullscreen parameters if (m_isFullscreen) { DEVMODE dmScreenSettings; // info about device init memset( &dmScreenSettings, 0, sizeof( dmScreenSettings)); dmScreenSettings.dmSize = sizeof( dmScreenSettings); dmScreenSettings.dmPelsWidth = width; dmScreenSettings.dmPelsHeight = height; dmScreenSettings.dmBitsPerPel = bits; // bits per pixel dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; // check if display settings can be switched if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { printf("The requested FullScreen Mode is not supported by your video card use window mode instead!"); m_isFullscreen = false; } } if (m_isFullscreen) { dwExStyle = WS_EX_APPWINDOW; dwStyle = WS_POPUP; ShowCursor(false); // Hide mouse pointer } else { dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle = WS_OVERLAPPEDWINDOW; } AdjustWindowRectEx(&m_windowRect, dwStyle, false, dwExStyle); if ( !(m_windowHandle = CreateWindowEx( dwExStyle, "Window", windowTitle, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle, 0, 0, m_windowRect.right - m_windowRect.left, m_windowRect.bottom - m_windowRect.top, NULL, NULL, m_moduleHandle, this))) // last var is a pointer to the class that receives the lpfnWndProc { printf("Window creation Error"); return false; } if (!(m_deviceContext = GetDC( m_windowHandle))) // get handle to device context for client erea of specified window or for the entire screen { printf("Cant create a Device Context."); return false; } ShowWindow( m_windowHandle, SW_SHOW); UpdateWindow( m_windowHandle); SetForegroundWindow(m_windowHandle); SetFocus(m_windowHandle); m_isInFocus = true; return true; }
CHookAPI::CHookAPI(void) { #ifdef _DEBUG CreateFileAPI=(pfnCreateFile)HookAPI(_T("KERNEL32.dll"),LPCSTR("CreateFileW"),(FARPROC)Hook_CreateFile,GetModuleHandle(_T("Duilib_ud.dll"))); EnableCreateFile(true); HookAPI(_T("Duilib_ud.dll"),LPCSTR("?Invalidate@CPaintManagerUI@DuiLib@@QAEXAAUtagRECT@@@Z"),(FARPROC)Hook_Invalidate,m_InvalidateHookInfo); EnableInvalidate(true); HookAPI(_T("Duilib_ud.dll"),LPCSTR("?GetImageEx@CPaintManagerUI@DuiLib@@QAEPAUtagTImageInfo@2@PB_W0K@Z"),(FARPROC)Hook_GetImageEx,m_GetImageExHookInfo); EnableGetImageEx(true); #else CreateFileAPI=(pfnCreateFile)HookAPI(_T("KERNEL32.dll"),LPCSTR("CreateFileW"),(FARPROC)Hook_CreateFile,GetModuleHandle(_T("Duilib_u.dll"))); EnableCreateFile(true); HookAPI(_T("Duilib_u.dll"),LPCSTR("?Invalidate@CPaintManagerUI@DuiLib@@QAEXAAUtagRECT@@@Z"),(FARPROC)Hook_Invalidate,m_InvalidateHookInfo); EnableInvalidate(true); HookAPI(_T("Duilib_u.dll"),LPCSTR("?GetImageEx@CPaintManagerUI@DuiLib@@QAEPAUtagTImageInfo@2@PB_W0K@Z"),(FARPROC)Hook_GetImageEx,m_GetImageExHookInfo); EnableGetImageEx(true); #endif }
DWORD getMyBaseAddressGMH() { return (DWORD)GetModuleHandle(NULL); }