LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HGLRC hRC; static DWORD timer = 1; HDC hDC; RECT WindowRect; int width; int height; switch (message) { case WM_CREATE: ReadRegistry(); hRC = InitOGLWindow(hWnd); GetClientRect (hWnd, &WindowRect); width = WindowRect.right - WindowRect.left; height = WindowRect.bottom - WindowRect.top; InitOpenGL(width,height); SetTimer(hWnd, timer, 5, NULL); break; case WM_TIMER: hDC = GetDC(hWnd); Display(); SwapBuffers(hDC); ReleaseDC(hWnd, hDC); break; case WM_DESTROY: wglMakeCurrent(NULL, NULL); wglDeleteContext(hRC); break; } return DefScreenSaverProc(hWnd, message, wParam, lParam); }
HANDLE WINAPI OpenPlugin(int /*OpenFrom*/, INT_PTR /*Item*/) { ReadRegistry(); struct FarDialogItem DialogItems[1]; ZeroMemory(DialogItems, sizeof(DialogItems)); p = NULL; FLI = NULL; hStdout = GetStdHandle(STD_OUTPUT_HANDLE); UpDateInfo(); DialogItems[0].Type = DI_LISTBOX; DialogItems[0].Flags = DIF_LISTNOAMPERSAND; DialogItems[0].X1 = 2; DialogItems[0].Y1 = 1; #ifdef FARAPI17 Info.DialogEx(Info.ModuleNumber,-1,-1,0,0,"Contents",DialogItems,ARRAYSIZE(DialogItems),0,0,DlgProc,0); #endif #ifdef FARAPI18 HANDLE h_dlg = Info.DialogInit(Info.ModuleNumber,-1,-1,0,0,L"Contents",DialogItems,ARRAYSIZE(DialogItems),0,0,DlgProc,0); if (h_dlg != INVALID_HANDLE_VALUE) { Info.DialogRun(h_dlg); Info.DialogFree(h_dlg); } #endif FLI = (FarListItem *) realloc(FLI, 0); p = (KeyInfo *) realloc(p, 0); return INVALID_HANDLE_VALUE; }
BOOL WINAPI ScreenSaverConfigureDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_INITDIALOG: ReadRegistry(); CheckDlgButton(hDlg, ROTATE, dRotate); return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: dRotate = (IsDlgButtonChecked(hDlg, ROTATE) == BST_CHECKED); WriteRegistry(); EndDialog(hDlg, TRUE); return TRUE; case IDCANCEL: EndDialog(hDlg, TRUE); break; case IDABOUT: DialogBox(hInstance, MAKEINTRESOURCE(IDD_DLG_ABOUT), hDlg, (DLGPROC)AboutProc); break; } } return FALSE; }
int WINAPI _export Start(const struct PluginStartupInfo *FarInfo,const struct MailPluginStartupInfo *FarMailInfo) { ::FarInfo=*FarInfo; FSF=*FarInfo->FSF; ::FarMailInfo=*FarMailInfo; FSF.sprintf(PluginRootKey,"%s\\Filter",::FarMailInfo.RootKey); ReadRegistry(); return 0; }
void WINAPI SetStartupInfo(const struct PluginStartupInfo *psInfo) { Info = *psInfo; FSF = *psInfo->FSF; Info.FSF = &FSF; InitHeap(); StringCchCopy(PluginRootKey,ARRAYSIZE(PluginRootKey),Info.RootKey); StringCchCat(PluginRootKey,ARRAYSIZE(PluginRootKey),_T("\\UnInstall")); ReadRegistry(); }
//------------------------------------------------------------------------- CUserColor::CUserColor(CUserColor& oColor) { Init(); ReadRegistry(); for (TColorRefMapIterator i = m_colColorRef.begin(); i != m_colColorRef.end(); i++) { int nID = i->first; m_colColorRef[nID] = oColor.Get(nID); } }
BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ulReason, LPVOID lpReserved) { char szLastAd[4]; char drive[_MAX_DRIVE]; char dir[_MAX_DIR]; char fname[_MAX_FNAME]; char ModuleFileName[_MAX_PATH]; boolean retVal= FALSE; switch( ulReason ) { case DLL_PROCESS_ATTACH: { // on process attach we can initialize the state of the filter. ReadRegistry(); InitializeCriticalSection(&g_CS); LogMe(1, "DllMain (PROCESS_ATTACH)"); if (GetModuleFileName(hInst, ModuleFileName, sizeof(ModuleFileName))) { char msg[_MAX_PATH+32]; _splitpath(ModuleFileName, drive, dir, fname, NULL); _makepath(IniFileName, drive, dir, fname, ".ini"); sprintf(msg,"target ini file: '%s'", IniFileName); LogMe(1, msg); retVal= TRUE; } else LogMe(1, "Cannot get module name"); /* giCurrentAd = GetPrivateProfileInt(TEXT("Info"), TEXT("LastAd"), 1, TEXT(INI_FILENAME)); */ break; } case DLL_PROCESS_DETACH: { /* WritePrivateProfileString(TEXT("Info"), TEXT("LastAd"), szLastAd, TEXT(INI_FILENAME)); */ DeleteCriticalSection(&g_CS); LogMe(1, "DllMain (PROCESS_DETACH)"); break; } // case DLL_THREAD_ATTACH: // case DLL_THREAD_DETACH: } return retVal; }
Object* HandlerServiceFactory::Create( const QString& serviceInterface, IServiceLocator* parentLocator, IServiceLocator* locator) const { if (serviceInterface != qobject_interface_iid<IHandlerService*>()) { return nullptr; } IWorkbenchLocationService* wls = locator->GetService<IWorkbenchLocationService>(); IWorkbench* const wb = wls->GetWorkbench(); if (wb == nullptr) { return nullptr; } Object* parent = parentLocator->GetService(serviceInterface); if (parent == nullptr) { ICommandService* commands = locator->GetService<ICommandService>(); IEvaluationService* evals = locator->GetService<IEvaluationService>(); auto handlerService = new HandlerService(commands, evals, locator); handlerService->Register(); handlerService->ReadRegistry(); handlerService->UnRegister(false); return handlerService; } return nullptr; IWorkbenchWindow* const window = wls->GetWorkbenchWindow(); IWorkbenchPartSite* const site = wls->GetPartSite(); if (site == nullptr) { Expression::Pointer exp(new WorkbenchWindowExpression(window)); return new SlaveHandlerService(dynamic_cast<IHandlerService*>(parent), exp); } if (SlaveHandlerService* slaveParent = dynamic_cast<SlaveHandlerService*>(parent)) { Expression::Pointer parentExp = slaveParent->GetDefaultExpression(); if (parentExp.Cast<ActivePartExpression>()) { return new NestableHandlerService(dynamic_cast<IHandlerService*>(parent), parentExp); } } Expression::Pointer exp(new ActivePartExpression(site->GetPart().GetPointer())); return new SlaveHandlerService(dynamic_cast<IHandlerService*>(parent), exp); }
/*------------------------------------------------------------------------ Procedure: GetOcamlPath ID:1 Purpose: Read the registry key HKEY_LOCAL_MACHINE\Software\Objective Caml or HKEY_CURRENT_USER\Software\Objective Caml, and creates it if it doesn't exists. If any error occurs, i.e. the given path doesn't exist, or the key didn't exist, it will put up a browse dialog box to allow the user to enter the path. The path will be verified that it points to a file that exists. If that file is in a directory called 'bin', it will look for another directory in the same level called lib' and set the Lib path to that. Input: None explicit Output: 1 means sucess, zero failure Errors: Almost all system calls will be verified ------------------------------------------------------------------------*/ int GetOcamlPath(void) { char path[1024], *p; while (( !ReadRegistry(HKEY_CURRENT_USER, "Software", "Objective Caml", "InterpreterPath", path) && !ReadRegistry(HKEY_LOCAL_MACHINE, "Software", "Objective Caml", "InterpreterPath", path)) || _access(path, 0) != 0) { /* Registry key doesn't exist or contains invalid path */ /* Ask user */ if (!BrowseForFile("Ocaml interpreter|ocaml.exe", path)) { ShowDbgMsg("Impossible to find ocaml.exe. I quit"); exit(0); } WriteRegistry(HKEY_CURRENT_USER, "Software", "Objective Caml", "InterpreterPath", path); /* Iterate to validate again */ } strcpy(OcamlPath, path); p = strrchr(OcamlPath,'\\'); if (p) { *p = 0; strcpy(LibDir,OcamlPath); *p = '\\'; p = strrchr(LibDir,'\\'); if (p && !stricmp(p,"\\bin")) { *p = 0; strcat(LibDir,"\\lib"); } } return 1; }
void Config(void) { struct InitDialogItem InitItems[] = { // type, x1, y1, x2, y2, focus, selected, flags, default, data { DI_DOUBLEBOX,3, 1,65,6, 0,0,0,0, (char*)mConfig_Title }, { DI_TEXT, 5, 2, 0,0, 0,0,0,0, (char*)mConfig_DefFiltersDir }, { DI_EDIT, 5, 3,63,0, 1,0,0,0, NULLSTR }, {DI_TEXT,3,4,0,0,0,0,DIF_SEPARATOR,0,NULLSTR}, { DI_BUTTON, 0, 5, 0,0 ,0,0,DIF_CENTERGROUP,1, (char *)mOk }, { DI_BUTTON, 0, 5, 0,0 ,0,0,DIF_CENTERGROUP,0, (char *)mCancel } }; enum { C2_FDIR = 2, C_TXT, C_OK, C_CANCEL }; struct FarDialogItem DialogItems[sizeofa(InitItems)]; InitDialogItems(InitItems,DialogItems,sizeofa(InitItems)); ReadRegistry(); lstrcpy( DialogItems[C2_FDIR].Data , DefFiltersDir ); if ( FarInfo.DialogEx(FarInfo.ModuleNumber,-1,-1,69,8,"Config",DialogItems,sizeofa(DialogItems),0,0,FarMailInfo.ShowHelpDlgProc,(long)FarMailInfo.ModuleName) == C_OK ) { lstrcpyn( DefFiltersDir, DialogItems[C2_FDIR].Data, MAX_PATH); if (!*DefFiltersDir) { char path[MAX_PATH]; lstrcpy(path,FarMailInfo.ModuleName); *(FSF.PointToName(path)) = 0; lstrcat(path,"FILTERS\\"); lstrcpy(DefFiltersDir,path); } else { FSF.Unquote(DefFiltersDir); FSF.AddEndSlash(DefFiltersDir); } SetRegKey2( HKEY_CURRENT_USER, PluginRootKey, NULLSTR, DEFFILTERSDIR, DefFiltersDir); } }
/* Returns heap string containing system font directory. E.g. 'C:\Windows\Fonts' */ char *GetSystemFontDir(void) { char path[MAX_PATH]; const char *key = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"; const char *option = "Fonts"; HRESULT hr = S_OK; if (SUCCEEDED(hr = ReadRegistry(key, option, path, sizeof(path)))) { remove_slash(path); return strdup(path); } return strdup("C:\\WINDOWS\\FONTS"); }
VOID QueryStartup(PSTARTUP_INFO Startup) { ReadRegistry(Startup,L"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon\\Notify",L"DllName"); //其实是读取Winlogon下的Userinit、UIHost、Shell ReadRegistry(Startup,L"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",L"Userinit"); ReadRegistry(Startup,L"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",L"UIHost"); ReadRegistry(Startup,L"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion",L"Shell"); ReadRegistry(Startup,L"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Active Setup\\Installed Components",L"Stubpath"); ReadRegistry(Startup,L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Print\\Monitors",L"Driver"); ReadRegistry(Startup,L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\Print\\Providers",L"Name"); }
BOOL CstarterDlg::OnInitDialog() { CDialogEx::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon regvals_t regVals; ReadRegistry(regVals); InitResolutions(); InitMaps(); int resId = m_cbResolution.FindStringExact(-1, regVals.resolution); if(resId == CB_ERR) m_cbResolution.AddString(regVals.resolution); m_cbResolution.SelectString(-1, regVals.resolution); m_bFullscreen.SetCheck(regVals.fullscreenChoice); m_iConnectChoice = regVals.connectChoice; m_eIP.SetWindowText(regVals.ip); std::set<TCHAR> charset; for(TCHAR c = _T('a'); c <= _T('z'); c++) charset.insert(c); for(TCHAR c = _T('A'); c <= _T('Z'); c++) charset.insert(c); for(TCHAR c = _T('0'); c <= _T('9'); c++) charset.insert(c); charset.insert('_'); m_eNickname.SetMask(charset); m_eNickname.SetWindowText(regVals.nickname); if(!regVals.map.IsEmpty()) m_cbMap.SetWindowText(regVals.map); else m_cbMap.SetCurSel(0); UpdateData(FALSE); return TRUE; // return TRUE unless you set the focus to a control }
/* Returns heap string containing default application data path. Creates suffix subdirectory (only one level). E.g. C:\Documents and Settings\jfp\Application Data\suffix */ char *GetDefaultSaveDir(const char *suffix) { char prefix[MAX_PATH]; char path[2 * MAX_PATH]; const char *key = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"; const char *option = "AppData"; HRESULT hr = S_OK; if (SUCCEEDED(hr = ReadRegistry(key, option, prefix, sizeof(prefix)))) { remove_slash(prefix); snprintf(path, sizeof(path), "%s/%s", prefix, suffix); _mkdir(path); return strdup(path); } return strdup("userdata"); }
CodecInst::CodecInst() : mLog(nullptr) , fps_num(30) , fps_den(1) , mCLConv(true) , mSubmitter(nullptr) { InitSettings(); ReadRegistry(); mLog = new Logger(!!mConfigTable[S_LOG]); mCLConv = !mConfigTable[S_DISABLE_OCL]; if (mConfigTable[S_FPS_ENABLED]) { fps_num = mConfigTable[S_FPS_NUM]; fps_den = mConfigTable[S_FPS_DEN]; } #if _DEBUG BindDLLs(); #endif }
static int GetRepositoryEncodingFromRegistory() { return ReadRegistry(HKEY_CURRENT_USER, _T("Software\\TortoiseGit\\RepositoryEncoding"), CP_ACP); }
// // EXAMPLES: // m_hWnd, _T("Message \r\nDisplay it"), _T("Captain"),MB_DEFBUTTON2, FALSE, TRUE, // 5, NULL, _T("OK\nCancel"), // RGB(255,0,0), RGB(255,255,255), NULL, 10 // // Return Value; // IDOK, IDCANCEL, IDCUSTOM1, IDCUSTOM2, IDCUSTOM3 u32 MessageBox_i(HWND hWnd, // if NULL, use the active window LPCTSTR pszText, // Pointer to a null-terminated string that contains the message to display. LPCTSTR pszCaption, // Pointer to a null-terminated string that is used in the title bar of the message box. UINT nStyle, // MB_TOPMOST, MB_SETFOREGROUND, MB_SYSTEMMODAL,MB_ICONSTOP,MB_ICONINFOMATION, MB_ICONINFORMATION,MB_ICONWARNING,MB_ICONERROR bool bCheckBox, // if need check box, return IDCHECKBOX u32 ulDisplayTimeOut, // UINT uDefaultButton, // causes specific info(like timeout) to display on, from MB_DEFBUTTON1 to MB_DEFBUTTON3 HICON hIcon, // if NULL use system default icon. TCHAR szButtons[BUTTONS_TEXT_MAX_LEN], // button string, seprate by '\n' like _T("OK\nCancel"), the last button is checkbox button if bCheckBox=TRUE. LPCTSTR pszIdentifier, // = NULL, used for CheckBox if need and save to registry and check it next time. COLORREF crText, // MESSAGE_BOX_VALUE_INVALID // message text color COLORREF crBackground, // =MESSAGE_BOX_VALUE_INVALID // message background LPCTSTR pszFaceName, // NULL INT32 nFontSize // =10 ) { UINT32 ret = 0; CDlgBoxItem m_pDlgItemArray[MaxItems]; HWND m_hWndOwner = hWnd; // handle of owner window TCHAR szButtonTxtSeq[IDCUST_NUM][DEFAULT_BUTTON_TXT_LEN] = {{_T("")}, }; TCHAR szCheckButtonTxt[DEFAULT_BUTTON_TXT_LEN]; szCheckButtonTxt[0] = _T('\0'); // check input parameters. if (szButtons[0] == _T('\0')) { return -1; } CDlgBoxEntry* pDlgBox = new CDlgBoxEntry; if(pDlgBox == NULL) { return -2; } pDlgBox->m_bNeedCheck = FALSE; if(pszIdentifier) { DWORD dwData = ReadRegistry(pszIdentifier); // Note: dwData will be 0 if either ReadRegistry or // GetPrivateProfileString fail to find key if (LOWORD(dwData) == IDCHECKBOX) { pDlgBox->m_bNeedCheck = HIWORD(dwData); } } // Save to process in MessageBoxProc pDlgBox->m_crText = crText; pDlgBox->m_crBackground = crBackground; pDlgBox->m_nStyle = nStyle; if(pszIdentifier) { lstrcpyn(pDlgBox->m_szIdentifier, pszIdentifier, COUNTOF(pDlgBox->m_szIdentifier)); } if (crBackground == MESSAGE_BOX_VALUE_INVALID) crBackground = ::GetSysColor(COLOR_WINDOW); if (crBackground != MESSAGE_BOX_VALUE_INVALID) pDlgBox->m_hBackgroundBrush = ::CreateSolidBrush(crBackground); // translate dialog units to pixels int nBaseunitX = LOWORD(GetDialogBaseUnits()); int nBaseunitY = HIWORD(GetDialogBaseUnits()); int m_nButtonWidth = MulDiv(ButtonWidth, nBaseunitX, 4); // button width in pixels int m_nButtonHeight = MulDiv(ButtonHeight, nBaseunitY, 8); int m_nButtonTimeoutExtraWidth = MulDiv(ButtonTimeoutExtraWidth, nBaseunitX, 4); // timeout button extra width in pixels int m_nDoNotAskAgainHeight = MulDiv(CHECKBOXHEIGHT, nBaseunitY, 8); // checkbox height in pixels // Specify the default button to change dispaly text for timeout switch (uDefaultButton) { case MB_DEFBUTTON1 : pDlgBox->m_nDefaultButtonId = IDCUSTOM1; break; case MB_DEFBUTTON2 : pDlgBox->m_nDefaultButtonId = IDCUSTOM2; break; case MB_DEFBUTTON3 : pDlgBox->m_nDefaultButtonId = IDCUSTOM3; break; case MB_DEFBUTTON4 : pDlgBox->m_nDefaultButtonId = IDCHECKBOX; break; default: pDlgBox->m_nDefaultButtonId = 0; break; } // m_szDefaultButton is used to save text for timeout option pDlgBox->m_szDefaultButton[0] = _T('\0'); // get dc for drawing HDC hdc = ::CreateDC(_T("DISPLAY"), NULL, NULL, NULL); pDlgBox->m_hFont = CreatFont_i(pszFaceName, nFontSize, FALSE, FALSE); HFONT hOldFont = (HFONT)::SelectObject(hdc, pDlgBox->m_hFont); int button_width = m_nButtonWidth; pDlgBox->m_nTimeoutSeconds = ulDisplayTimeOut; int nMaxWidth = (::GetSystemMetrics(SM_CXSCREEN) / 2) + 80; if (nStyle & MB_ICONMASK) nMaxWidth -= GetSystemMetrics(SM_CXICON) + 2*SpacingSize; SetRect(&pDlgBox->m_msgrect, 0, 0, nMaxWidth, nMaxWidth); // get output size of message text ::DrawText(hdc, pszText, -1, &pDlgBox->m_msgrect, DT_LEFT | DT_NOPREFIX | DT_WORDBREAK | DT_CALCRECT | DT_EXPANDTABS); int nMessageHeight = pDlgBox->m_msgrect.Height(); // get height of a single line SIZE nLineSize; ::GetTextExtentPoint32(hdc, _T("My"), 2, &nLineSize); pDlgBox->m_msgrect.right += 12; pDlgBox->m_msgrect.bottom += 5; pDlgBox->m_msgrect.left = 2 * SpacingSize; pDlgBox->m_msgrect.top = 2 * SpacingSize; pDlgBox->m_msgrect.right += 2 * SpacingSize; pDlgBox->m_msgrect.bottom += 3 * SpacingSize; // client rect CRectX mbrect; SetRect(&mbrect, 0, 0,pDlgBox->m_msgrect.Width() + (2 * SpacingSize), pDlgBox->m_msgrect.Height() + (2 * SpacingSize)); if (mbrect.Height() < MinimalHeight) mbrect.bottom = MinimalHeight; /////////////////////////////////////////////////////////////////////////// DLGTEMPLATE m_dlgTempl = {0, }; // message box dialog template // initialize the DLGTEMPLATE structure m_dlgTempl.x = 0; m_dlgTempl.y = 0; m_dlgTempl.cdit = 0; m_dlgTempl.style = WS_CAPTION | WS_VISIBLE | WS_SYSMENU | WS_POPUP | DS_MODALFRAME | DS_CENTER; m_dlgTempl.dwExtendedStyle = 0; if (nStyle & MB_SYSTEMMODAL) m_dlgTempl.style |= DS_SYSMODAL; if(hIcon == NULL) { if (nStyle & MB_ICONMASK) { LPTSTR lpIcon = (LPTSTR)IDI_EXCLAMATION; switch (nStyle & MB_ICONMASK) { case MB_ICONEXCLAMATION: lpIcon = (LPTSTR)IDI_EXCLAMATION; break; case MB_ICONHAND: lpIcon = (LPTSTR)IDI_HAND; break; case MB_ICONQUESTION: lpIcon = (LPTSTR)IDI_QUESTION; break; case MB_ICONASTERISK: lpIcon = (LPTSTR)IDI_ASTERISK; break; } if (lpIcon) pDlgBox->m_hIcon = ::LoadIcon(NULL, lpIcon); } } else { pDlgBox->m_hIcon = hIcon; } // Set Icon if (pDlgBox->m_hIcon) { int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); int icon_x = SpacingSize; int icon_y = SpacingSize; pDlgBox->m_msgrect.left += cxIcon + icon_x; pDlgBox->m_msgrect.right += cxIcon + icon_x; mbrect.right = pDlgBox->m_msgrect.right + SpacingSize; CRectX iconrect; SetRect(&iconrect, icon_x, icon_y, icon_x + cxIcon + 2, icon_y + cyIcon + 2); m_pDlgItemArray[m_dlgTempl.cdit++].AddItem(STATICTEXT, IconControlId, &iconrect, _T("")); // Set ICON control. } // Mesage control m_pDlgItemArray[m_dlgTempl.cdit++].AddItem(STATICTEXT /*EDITCONTROL*/, MessageControlId, &pDlgBox->m_msgrect, pszText); pDlgBox->m_nMessageId = MessageControlId; // process buttons int cItems = 0; int nWidthCustomButtons = 0; TCHAR* pszLastBtn = NULL; // process custom buttons TCHAR szCustomButtons[BUTTONS_TEXT_MAX_LEN]; lstrcpyn(szCustomButtons, szButtons, BUTTONS_TEXT_MAX_LEN); int i = 0; TCHAR * cp = _tcstok(szCustomButtons, _T("\n")); while (cp != NULL) { // Find the next token in a string. if(i < IDCUST_NUM) { szButtonTxtSeq[i][0] = _T('\0'); lstrcpyn(szButtonTxtSeq[i], cp, DEFAULT_BUTTON_TXT_LEN); } cp = _tcstok(NULL, _T("\n")); i++; } cItems = i; cItems = min(cItems, IDCUST_NUM); pDlgBox->m_bCheckBox = bCheckBox; pDlgBox->m_nReturnValueCheckBox = FALSE; if(bCheckBox) { szCheckButtonTxt[0] = _T('\0'); int k = cItems-1; if(k>=0 && k<IDCUST_NUM) { lstrcpyn(szCheckButtonTxt, szButtonTxtSeq[k], sizeof(szCheckButtonTxt)); szButtonTxtSeq[k][0] = _T('\0'); } } // Calculate Button width. i = 0; while ( (i<IDCUST_NUM) && (szButtonTxtSeq[i][0] != _T('\0')) ) { // Find the next token in a string. SIZE size; ::GetTextExtentPoint32(hdc, szButtonTxtSeq[i], lstrlen(szButtonTxtSeq[i]), &size); int w = size.cx + 20; w = (w > button_width) ? w : button_width; // allow for wider buttons if timeout specified if (ulDisplayTimeOut) w += m_nButtonTimeoutExtraWidth; nWidthCustomButtons += w; i++; } i = 0; CRectX iconrect; SetRect(&iconrect, 0, 0, 0, 0); int y = 0; int x = 0; CRectX buttonrow; y = (pDlgBox->m_msgrect.bottom > iconrect.bottom) ? pDlgBox->m_msgrect.bottom : iconrect.bottom; y += SpacingBetweenMessageAndButtons; if (pDlgBox->m_hIcon || pDlgBox->m_hBackgroundBrush) y += 9; int nTotalButtonWidth = nWidthCustomButtons + (ButtonSpacing * (cItems-1)); SetRect(&buttonrow, 0, y, nTotalButtonWidth, y + m_nButtonHeight); int nCheckBoxWidth = 0; // get checkbox width if (szCheckButtonTxt[0] != _T('\0')) { nCheckBoxWidth = m_nDoNotAskAgainHeight; // use height as width of box SIZE size = {0, }; ::GetTextExtentPoint32(hdc, szCheckButtonTxt, lstrlen(szCheckButtonTxt), &size); int w = size.cx + 20; w = (w > button_width) ? w : button_width; nCheckBoxWidth += w; } mbrect.bottom = buttonrow.bottom + BottomMargin; int bw = buttonrow.Width(); int bleft = 2 * SpacingSize; int bright = bleft + bw; if (mbrect.right <= (bright + (2 * SpacingSize))) mbrect.right = bright + (2 * SpacingSize); if (mbrect.Width() < nCheckBoxWidth) mbrect.right = bleft + nCheckBoxWidth; x = (mbrect.Width() - bw) / 2; y = buttonrow.top; if (m_bRightJustifyButtons) { x = mbrect.right - nTotalButtonWidth - 2*SpacingSize; } CRectX rect; ////////////////////////////////////////////////////////////////////////// // Add buttons i = 0; while ( (i<IDCUST_NUM) && (szButtonTxtSeq[i][0] != _T('\0')) ) { SIZE size; ::GetTextExtentPoint32(hdc, szButtonTxtSeq[i], lstrlen(szButtonTxtSeq[i]), &size); int w = size.cx + 20; w = (w > button_width) ? w : button_width; // allow for wider buttons if timeout specified if (ulDisplayTimeOut) w += m_nButtonTimeoutExtraWidth; rect.SetRect(x, y, x + w, y + m_nButtonHeight); m_pDlgItemArray[m_dlgTempl.cdit].AddItem(BUTTON, IDCUSTOM1 + i, &rect, szButtonTxtSeq[i]); m_dlgTempl.cdit++; x += w + ButtonSpacing; i++; } /////////////////////////////////////////////////////////////////////////// // add checkbox if (szCheckButtonTxt[0] != _T('\0')) { CRectX checkboxrect; SetRect(&checkboxrect, 0, 0, nCheckBoxWidth, m_nDoNotAskAgainHeight); AddCheckBox(x, y, rect, mbrect, buttonrow, checkboxrect, szCheckButtonTxt, m_nButtonHeight, m_nDoNotAskAgainHeight,m_pDlgItemArray,m_dlgTempl); } if (buttonrow.bottom >= mbrect.bottom) mbrect.bottom = buttonrow.bottom + (2 * SpacingSize); if (mbrect.right < (buttonrow.right + (2 * SpacingSize))) mbrect.right = buttonrow.right + (2 * SpacingSize); m_dlgTempl.x = 0; m_dlgTempl.y = 0; m_dlgTempl.cx = (short)((mbrect.Width() * 4) / nBaseunitX); m_dlgTempl.cy = (short)((mbrect.Height() * 8) / nBaseunitY); ::SelectObject(hdc, hOldFont); ::DeleteDC(hdc); ///////////////////////////////////////////////////////////////////////// // The first step is to allocate memory to define the dialog. // The information to be stored in the allocated buffer is the following: // // 1. DLGTEMPLATE structure // typedef struct // { // DWORD style; // DWORD dwExtendedStyle; // WORD cdit; // short x; // short y; // short cx; // short cy; // } DLGTEMPLATE; // 2. 0x0000 (Word) indicating the dialog has no menu // 3. 0x0000 (Word) Let windows assign default class to the dialog // 4. (Caption) Null terminated unicode string // 5. 0x000B (size of the font to be used) // 6. "MS Sans Serif" (name of the typeface to be used) // 7. DLGITEMTEMPLATE structure for the button (HAS TO BE DWORD ALIGNED) // typedef struct // { // DWORD style; // DWORD dwExtendedStyle; // short x; // short y; // short cx; // short cy; // WORD id; // } DLGITEMTEMPLATE; // 8. 0x0080 to indicate the control is a button // 9. (Title). Unicode null terminated string with the caption // 10. 0x0000 0 extra bytes of data for this control // 11. DLGITEMTEMPLATE structure for the Static Text (HAS TO BE DWORD ALIGNED) // 12. 0x0081 to indicate the control is static text // 13. (Title). Unicode null terminated string with the text // 14. 0x0000. 0 extra bytes of data for this control ////////////////////////////////////////////////////////////////////////// int nTitleLen = (int)lstrlen(pszCaption); int nBufferSize = sizeof(DLGTEMPLATE) + (2 * sizeof(WORD)) + // menu and class ((nTitleLen + 1) * sizeof(WCHAR)); // NOTE - font is set in MsgBoxDlgProc nBufferSize = (nBufferSize + 3) & ~3; // adjust size to make first control DWORD aligned // loop to calculate size of buffer we need add size of each control: // sizeof(DLGITEMTEMPLATE) + // sizeof(WORD) + // atom value flag 0xFFFF // sizeof(WORD) + // ordinal value of control's class // sizeof(WORD) + // no. of bytes in creation data array // sizeof title in WCHARs for (i = 0; i < m_dlgTempl.cdit; i++) { int nItemLength = sizeof(DLGITEMTEMPLATE) + 3 * sizeof(WORD); #ifdef _UNICODE int nActualChars = lstrlen(m_pDlgItemArray[i]->m_pszCaption) + 1; #else int nActualChars = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)m_pDlgItemArray[i].m_pszCaption, -1, NULL, 0); #endif if(nActualChars <= 0) break; nItemLength += nActualChars * sizeof(WCHAR); if (i != m_dlgTempl.cdit - 1) // the last control does not need extra bytes { nItemLength = (nItemLength + 3) & ~3; // take into account gap so next control is DWORD aligned } nBufferSize += nItemLength; } HLOCAL hLocal = LocalAlloc(LHND, nBufferSize); if (hLocal == NULL) { return IDCANCEL; } BYTE* pBuffer = (BYTE*)LocalLock(hLocal); if (pBuffer == NULL) { LocalFree(hLocal); return IDCANCEL; } BYTE* pdest = pBuffer; // transfer DLGTEMPLATE structure to the buffer memcpy(pdest, &m_dlgTempl, sizeof(DLGTEMPLATE)); pdest += sizeof(DLGTEMPLATE); *(WORD*)pdest = 0; // no menu pdest += sizeof(WORD); *(WORD*)pdest = 0; // use default window class pdest += sizeof(WORD); // transfer title WCHAR pchCaption[CAPTION_TEXT_MAX_LEN+80] = {0, }; nTitleLen = min(nTitleLen,CAPTION_TEXT_MAX_LEN); memset(pchCaption, 0, nTitleLen*sizeof(WCHAR)); #ifdef _UNICODE memcpy(pchCaption, pszCaption, nTitleLen*sizeof(WCHAR)); int nActualChars = nTitleLen + 1; #else int nActualChars = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pszCaption, -1, pchCaption, nTitleLen + 1); #endif if(nActualChars <= 0) return IDCANCEL; memcpy(pdest, pchCaption, nActualChars * sizeof(WCHAR)); pdest += nActualChars * sizeof(WCHAR); // will now transfer the information for each one of the item templates for (i = 0; i < m_dlgTempl.cdit; i++) { pdest = (BYTE*)(((DWORD)pdest + 3) & ~3); // make the pointer DWORD aligned memcpy(pdest, (void *)&m_pDlgItemArray[i].m_dlgItemTemplate, sizeof(DLGITEMTEMPLATE)); pdest += sizeof(DLGITEMTEMPLATE); *(WORD*)pdest = 0xFFFF; // indicating atom value pdest += sizeof(WORD); *(WORD*)pdest = (WORD)m_pDlgItemArray[i].m_controltype; // atom value for the control pdest += sizeof(WORD); // transfer the caption even when it is an empty string int nChars = (int)lstrlen(m_pDlgItemArray[i].m_pszCaption) + 1; WCHAR* pszchText = NULL; int nActualChars = 0; #ifdef _UNICODE pszchText = new TCHAR[nChars*sizeof(TCHAR)+4]; if(pszchText) { memset(pszchText, 0, nChars*sizeof(TCHAR) + 4); memcpy(pszchText, m_pDlgItemArray[i]->m_pszCaption, nChars * sizeof(TCHAR)); } nActualChars = nChars; #else pszchText = new WCHAR[nChars*sizeof(WCHAR)+4]; if(pszchText) { nActualChars = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)m_pDlgItemArray[i].m_pszCaption, -1, pszchText, nChars); } #endif if(nActualChars <= 0) break; if(pszchText) { memcpy(pdest, pszchText, nActualChars * sizeof(WCHAR)); } pdest += nActualChars * sizeof(WCHAR); if(pszchText) { delete [] pszchText ; pszchText = NULL; } *(WORD*)pdest = 0; // How many bytes in data for control pdest += sizeof(WORD); } // for if(pdest - pBuffer > nBufferSize) { return 0; } HINSTANCE hInstance = ::GetModuleHandle(NULL); HWND hDlg = ::CreateDialogIndirectParam(hInstance, (LPCDLGTEMPLATE) pBuffer, m_hWndOwner, (DLGPROC)MsgBoxDlgProc, (LPARAM) pDlgBox); DWORD dwError = ::GetLastError(); if (hDlg) { // disable owner - this is a modal dialog ::EnableWindow(m_hWndOwner, FALSE); MSG msg; memset(&msg, 0, sizeof(msg)); // message loop for dialog while (!pDlgBox->m_bShutdown) { msg.message = 0; if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { break; } if (msg.message == WM_KEYDOWN) { // returns TRUE if Ctrl-C processed if (OnKeyDown(hDlg, msg.wParam, msg.lParam)) continue; } if (!::IsDialogMessage(hDlg, &msg)) { ::TranslateMessage(&msg); ::DispatchMessage(&msg); } } else if (!pDlgBox->m_bShutdown) { ::WaitMessage(); // suspend thread until new message arrives } } if (msg.message == WM_QUIT) { PostQuitMessage((int)msg.wParam); } // re-enable owner if (::IsWindow(m_hWndOwner)) { ::EnableWindow(m_hWndOwner, TRUE); } ::DestroyWindow(hDlg); hDlg = NULL; } // if (hDlg) LocalUnlock(hLocal); LocalFree(hLocal); if (pDlgBox->m_hIcon) DestroyIcon(pDlgBox->m_hIcon); pDlgBox->m_hIcon = 0; if (pDlgBox->m_hFont) ::DeleteObject(pDlgBox->m_hFont); pDlgBox->m_hFont = NULL; if (pDlgBox->m_hBackgroundBrush) ::DeleteObject(pDlgBox->m_hBackgroundBrush); pDlgBox->m_hBackgroundBrush = 0; ret = MAKELONG(pDlgBox->m_nReturnValue, pDlgBox->m_nReturnValueCheckBox); delete pDlgBox; pDlgBox = NULL; return ret; }
/* * CGuiThread initialization: Load plugins, create windows & so on */ BOOL CGuiThread::InitInstance() { GUIThreadId = GetCurrentThreadId(); HANDLE hEvent = OpenEvent(EVENT_MODIFY_STATE,FALSE,"Injection_load_dll_event"); if(hEvent == 0) { // It is possible to load injection not with ILaunch. For example by // manually modifying client's import table OutputDebugString("Injection: DLL loaded not from ILaunch."); } else SetEvent(hEvent); // Initialize main window MainWindow = new CMainWindow(); if(!MainWindow->Create()) { char Buff[111]; sprintf(Buff,"Error creating main window %08X",GetLastError()); MessageBox(0,Buff,LoadString(IDS_ERROR),0); } // Enable error logging Log=new Logger; /* // DEBUG version always use verbose logging #ifdef _DEBUG Log->set_verbose(true); #else Log->set_verbose(false); #endif */ ReadRegistry(); ////////////////////////////////////////////////////////// // // Here goes Injection initialization // ////////////////////////////////////////////////////////// // Add predefined tabs MainTab = new CMainTab(MainWindow->GetTabCWnd()); MainWindow->AddTab(MainTab->m_hWnd,"Main"); DisplayTab = new CDisplayTab(MainWindow->GetTabCWnd()); MainWindow->AddTab(DisplayTab->m_hWnd,"Display"); ObjectsTab = new CObjectsTab(MainWindow->GetTabCWnd()); MainWindow->AddTab(ObjectsTab->m_hWnd,"Objects"); ObjectTypesTab = new CObjectTypesTab(MainWindow->GetTabCWnd()); MainWindow->AddTab(ObjectTypesTab->m_hWnd,"Object Types"); if(!HookClientWindowProc()) error_printf("Unable to hook CreateWindow function!\n"); if(!HookWinsockFunctions()) error_printf("Unable to hook winsock.dll!\n"); // Load plugins LoadPluginDLLs(); // This code was previously used to patch client using ignition. // It is no longer necessary, but is left here as it may be needed // in the future. if(!RemoveEncryptionFromClientWithPlugins()) { trace_printf("All plugins refused to patch client\n"); } // Find the encryption plugin in plugin list if(!InitEncryptionPlugin()) { error_printf("Unable to load encryption plugin."); if(IDNO==MessageBox(0,LoadString(IDS_NOENCRYPTIONPLUGIN),LoadString(IDS_ERROR), MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2)) { ExitProcess(1); } } // Make main window visible MainWindow->ShowWindow(SW_SHOW); // resume client execution SetEvent(hResumeClient); return TRUE; }
//------------------------------------------------------------------------- CUserColor::CUserColor() { Init(); ReadRegistry(); }
PRIVATE BOOL SpyInit( HANDLE hInstance, INT nCmdShow ) { WNDCLASS wc; HWND hwndT; CHAR szClassName[40]; BOOL bFoundPrevSpy = FALSE; INT i; INT j; ghInst = hInstance; /* * Loop through windows to find one of the spy class. */ for (hwndT = GetWindow(GetDesktopWindow(), GW_CHILD); hwndT; hwndT = GetWindow(hwndT, GW_HWNDNEXT)) { if (GetClassName(hwndT, szClassName, 40)) { if (!lstrcmpi(szClassName, gszSpyClassName)) { bFoundPrevSpy = TRUE; break; } } } if (bFoundPrevSpy) { if (hwndT) SendMessage(hwndT, WM_EXECINSTANCE, 0, 0); return FALSE; } if (!(ghaccelTbl = LoadAccelerators(ghInst, "spy"))) return FALSE; ReadRegistry(); gcxBorder = GetSystemMetrics(SM_CXBORDER); gcyBorder = GetSystemMetrics(SM_CYBORDER); // // Calculate the counts in the message groups. This is best // done at run time to be safe. // for (i = 0; i < gcMessages; i++) { // // If this message belongs to a message group, // increment the total for that group. // for (j = 0; j < gcMsgGroups; j++) { if (gaMsgGroup[j].flMask & gaMsgs[i].Flags) gaMsgGroup[j].cMsgs++; } } #ifdef JAPAN lstrcpy(gszWindowName,LoadResourceString(IDS_APPLICATION_NAME)); #endif wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(hInstance, gszAppName); wc.lpszMenuName = gszAppName; wc.lpszClassName = gszSpyClassName; wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.hInstance = hInstance; wc.style = CS_BYTEALIGNCLIENT; wc.lpfnWndProc = SpyWndProc; wc.cbWndExtra = 0; wc.cbClsExtra = 0; if (!RegisterClass(&wc)) return FALSE; #ifdef JAPAN ghwndSpyApp = CreateWindow(gszSpyClassName, gszWindowName, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, hInstance, NULL); #else ghwndSpyApp = CreateWindow(gszSpyClassName, gszAppName, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, hInstance, NULL); #endif if (!ghwndSpyApp) return FALSE; if (nCmdShow != SW_SHOWNORMAL) gwndpl.showCmd = nCmdShow; SetWindowPlacement(ghwndSpyApp, &gwndpl); return TRUE; }
co_rc_t console_window_t::start() { window = new console_main_window_t(this); window->callback(console_window_cb, this); // read font and font size from registry reg_font = ReadRegistry(REGISTRY_FONT); reg_font_size = ReadRegistry(REGISTRY_FONT_SIZE); reg_copyspaces = ReadRegistry(REGISTRY_COPYSPACES); reg_exitdetach = ReadRegistry(REGISTRY_EXITDETACH); if(reg_font==-1) reg_font = FL_SCREEN; if(reg_font_size==-1) reg_font_size = 18; if(reg_copyspaces==-1) reg_copyspaces = 1; if(reg_exitdetach==-1) reg_exitdetach = 0; Fl_Menu_Item console_menuitems[] = { { "File", 0, NULL, NULL, FL_SUBMENU }, { "Select" , 0, (Fl_Callback*)console_select_cb, this, FL_MENU_DIVIDER }, { "Attach" , 0, (Fl_Callback*)console_attach_cb, this, }, { "Detach" , 0, (Fl_Callback*)console_detach_cb, this, FL_MENU_DIVIDER }, { "Power off", 0, (Fl_Callback*)console_send_poweroff_cb, this, }, { "Reboot - Ctrl-Alt-Del", 0, (Fl_Callback *)console_send_ctrl_alt_del_cb, this, }, { "Shutdown" , 0, (Fl_Callback*)console_send_shutdown_cb, this, FL_MENU_DIVIDER }, { "Quit", 0, (Fl_Callback *)console_quit_cb, this }, { 0 }, { "Edit" , 0, NULL, NULL, FL_SUBMENU }, { "Copy (WinKey+C)", 0, (Fl_Callback*)console_copy_cb, this, }, { "Paste (WinKey+V)", 0, (Fl_Callback*)console_paste_cb, this, }, { 0 }, { "View" , 0, NULL, NULL, FL_SUBMENU }, { "Page up (WinKey+PgUp, mouse wheel)", 0, (Fl_Callback*)console_scrollpageup_cb, this, }, { "Page down (WinKey+PgDn, mouse wheel)", 0, (Fl_Callback*)console_scrollpagedown_cb, this, }, { 0 }, { "Config" , 0, NULL, NULL, FL_SUBMENU }, { "Font..." , 0, (Fl_Callback*)console_font_cb, this, FL_MENU_DIVIDER }, { "Copy trailing spaces", 0, (Fl_Callback*)console_copyspaces_cb, this, FL_MENU_TOGGLE | ((reg_copyspaces) ? FL_MENU_VALUE : 0)}, { "Exit on Detach", 0, (Fl_Callback*)console_exitdetach_cb, this, FL_MENU_TOGGLE | ((reg_exitdetach) ? FL_MENU_VALUE : 0)}, { 0 }, { "Help" , 0, NULL, NULL, FL_SUBMENU }, { "About", 0, (Fl_Callback*)console_about_cb, this, }, { 0 }, { 0 } }; unsigned int i; for (i = 0; i < sizeof(console_menuitems) / sizeof(console_menuitems[0]); i++) console_menuitems[i].user_data((void*)this); int swidth = 640; int sheight = 480; menu = new Fl_Menu_Bar(0, 0, swidth, MENU_SIZE_PIXELS); menu->box(FL_UP_BOX); menu->align(FL_ALIGN_CENTER); menu->when(FL_WHEN_RELEASE_ALWAYS); menu->copy(console_menuitems, window); Fl_Group* tile = new Fl_Group(0, MENU_SIZE_PIXELS, swidth, sheight-MENU_SIZE_PIXELS); widget = new console_widget_t(0, MENU_SIZE_PIXELS, swidth, sheight - 120); if(widget->get_copy_spaces()!=reg_copyspaces) widget->toggle_copy_spaces(); text_widget = new Fl_Text_Display(0, sheight - 120 + MENU_SIZE_PIXELS, swidth, 70); Fl_Group* tile2 = new Fl_Group(0, sheight - 120 + MENU_SIZE_PIXELS, swidth, 90); text_widget->buffer(new Fl_Text_Buffer()); text_widget->insert_position(0); Fl_Box* box = new Fl_Box(0, sheight - 20, swidth, 20); box->label(""); box->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); tile2->end(); tile->resizable(widget); tile->end(); window->resizable(tile); window->end(); window->show(); menu_item_activate(console_select_cb); menu_item_deactivate(console_send_poweroff_cb); menu_item_deactivate(console_send_ctrl_alt_del_cb); menu_item_deactivate(console_send_shutdown_cb); menu_item_deactivate(console_detach_cb); menu_item_deactivate(console_attach_cb); // Default Font is "Terminal" with size 18 // Sample WinNT environment: set COLINUX_CONSOLE_FONT=Lucida Console:12 // Change only font size: set COLINUX_CONSOLE_FONT=:12 char* env_font = getenv("COLINUX_CONSOLE_FONT"); if (env_font) { char* p = strchr (env_font, ':'); if (p) { int size = atoi (p+1); if (size >= 4 && size <= 24) { // Set size widget->set_font_size(size); } *p = 0; // End for Fontname } // Set new font style if(strlen(env_font)) { // Remember: set_font need a non stack buffer! // Environment is global static. Fl::set_font(FL_SCREEN, env_font); // Now check font width fl_font(FL_SCREEN, 18); // Use default High for test here if ((int)fl_width('i') != (int)fl_width('W')) { Fl::set_font(FL_SCREEN, "Terminal"); // Restore standard font log("%s: is not fixed font. Using 'Terminal'\n", env_font); } } } else { // use registry values and not environment variable widget->set_font_name(reg_font); widget->set_font_size(reg_font_size); } log("Cooperative Linux console started\n"); if (start_parameters.attach_id != CO_INVALID_ID) attached_id = start_parameters.attach_id; else attached_id = find_first_monitor(); if (attached_id != CO_INVALID_ID) attach(); /* Ignore errors, as we can attach latter */ return CO_RC(OK); }