⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ecutils.cpp

📁 ecos实时嵌入式操作系统
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    return stream;}wxOutputStream& operator <<(wxOutputStream& stream, long l){    wxString str;    str.Printf("%ld", l);    return stream << str;}wxOutputStream& operator <<(wxOutputStream& stream, const char c){    wxString str;    str.Printf("%c", c);    return stream << str;}/* * ecDialog * Supports features we want to have for all dialogs in the application. * So far, this just allows dialogs to be resizeable under MSW by * refreshing the controls in OnSize (otherwise there's a mess) */IMPLEMENT_CLASS(ecDialog, wxDialog)BEGIN_EVENT_TABLE(ecDialog, wxDialog)#ifdef __WXMSW__    EVT_SIZE(ecDialog::OnSize)#endifEND_EVENT_TABLE()void ecDialog::OnSize(wxSizeEvent& event){    wxDialog::OnSize(event);    wxRefreshControls(this);}/* * Implements saving/loading of window settings - fonts only for now */wxWindowSettingsObject* wxWindowSettings::FindSettings(const wxString& windowName) const{    wxNode* node = m_settings.First();    while (node)    {        wxWindowSettingsObject* obj = (wxWindowSettingsObject*) node->Data();        if (obj->m_windowName.CmpNoCase(windowName) == 0)            return obj;        node = node->Next();    }    return NULL;}bool wxWindowSettings::LoadConfig(wxConfigBase& config){    unsigned int i = 0;    for (i = 0; i < GetCount(); i++)    {        wxWindowSettingsObject* obj = GetNth(i);        wxString name(obj->m_windowName);        name.Replace(wxT(" "), wxT(""));        LoadFont(config, name, obj->m_font);    }    return TRUE;}bool wxWindowSettings::SaveConfig(wxConfigBase& config){    unsigned int i = 0;    for (i = 0; i < GetCount(); i++)    {        wxWindowSettingsObject* obj = GetNth(i);        wxString name(obj->m_windowName);        name.Replace(wxT(" "), wxT(""));        SaveFont(config, name, obj->m_font);    }    return TRUE;}// Load and save font descriptionsbool wxWindowSettings::LoadFont(wxConfigBase& config, const wxString& windowName, wxFont& font){    wxString pathBase(wxT("/Fonts/"));    pathBase += windowName;    pathBase += wxT("/");    int pointSize, family, style, weight;    bool underlined = FALSE;    wxString faceName;    if (!config.Read(pathBase + wxT("PointSize"), & pointSize))        return FALSE;    if (!config.Read(pathBase + wxT("Family"), & family))        return FALSE;    if (!config.Read(pathBase + wxT("Style"), & style))        return FALSE;    if (!config.Read(pathBase + wxT("Weight"), & weight))        return FALSE;    config.Read(pathBase + wxT("Underlined"), (bool*) & underlined);    config.Read(pathBase + wxT("FaceName"), & faceName);    wxFont font1(pointSize, family, style, weight, underlined, faceName);    font = font1;    return TRUE;    }bool wxWindowSettings::SaveFont(wxConfigBase& config, const wxString& windowName, const wxFont& font){    if (!font.Ok())        return FALSE;    wxString pathBase(wxT("/Fonts/"));    pathBase += windowName;    pathBase += wxT("/");    config.Write(pathBase + wxT("PointSize"), (long) font.GetPointSize());    config.Write(pathBase + wxT("Family"), (long) font.GetFamily());    config.Write(pathBase + wxT("Style"), (long) font.GetStyle());    config.Write(pathBase + wxT("Weight"), (long) font.GetWeight());    config.Write(pathBase + wxT("Underlined"), (long) font.GetUnderlined());    config.Write(pathBase + wxT("FaceName"), font.GetFaceName());    return TRUE;    }wxFont wxWindowSettings::GetFont(const wxString& name) const{    wxWindowSettingsObject* obj = FindSettings(name);    if (!obj)        return wxFont();    else        return obj->m_font;}void wxWindowSettings::SetFont(const wxString& name, const wxFont& font){    wxWindowSettingsObject* obj = FindSettings(name);    if (!obj)    {        obj = new wxWindowSettingsObject(name, NULL) ;        obj->m_font = font;        m_settings.Append(obj);    }    obj->m_font = font;}wxWindow* wxWindowSettings::GetWindow(const wxString& name) const{    wxWindowSettingsObject* obj = FindSettings(name);    if (!obj)        return NULL;    if (obj->m_arrWindow.GetCount() > 0)        return (wxWindow*) obj->m_arrWindow[0];    else        return NULL;}void wxWindowSettings::SetWindow(const wxString& name, wxWindow* win){    wxWindowSettingsObject* obj = FindSettings(name);    if (!obj)    {        obj = new wxWindowSettingsObject(name, win) ;        m_settings.Append(obj);    }    obj->m_arrWindow.Clear();    if (win)        obj->m_arrWindow.Add(win);}wxArrayPtrVoid* wxWindowSettings::GetWindows(const wxString& name) const{    wxWindowSettingsObject* obj = FindSettings(name);    if (!obj)        return NULL;    return & obj->m_arrWindow ;}void wxWindowSettings::SetWindows(const wxString& name, wxArrayPtrVoid& arr){    wxWindowSettingsObject* obj = FindSettings(name);    if (!obj)    {        obj = new wxWindowSettingsObject(name, NULL) ;        m_settings.Append(obj);    }    obj->m_arrWindow.Clear() ;    obj->m_arrWindow = arr;}bool wxWindowSettings::ApplyFontsToWindows(){    if (m_useDefaults)        return FALSE;    unsigned int i = 0;    for (i = 0; i < GetCount(); i++)    {        wxWindowSettingsObject* obj = GetNth(i);        unsigned int j = 0;        for (j = 0; j < obj->m_arrWindow.GetCount(); j++)        {            wxWindow* win = (wxWindow*) obj->m_arrWindow[j];            win->SetFont(obj->m_font);            win->Refresh();        }    }    return TRUE;}#ifdef __WIN32__// This will be obsolete when we switch to using the version included// in wxWindows (from wxWin 2.3.1 onwards)enum ecKillError{    ecKILL_OK,              // no error    ecKILL_BAD_SIGNAL,      // no such signal    ecKILL_ACCESS_DENIED,   // permission denied    ecKILL_NO_PROCESS,      // no such process    ecKILL_ERROR            // another, unspecified error};#endif// ----------------------------------------------------------------------------// process management// ----------------------------------------------------------------------------#ifdef __WIN32__// structure used to pass parameters from wxKill() to wxEnumFindByPidProc()struct wxNewFindByPidParams{    wxNewFindByPidParams() { hwnd = 0; pid = 0; }    // the HWND used to return the result    HWND hwnd;    // the PID we're looking from    DWORD pid;};// wxKill helper: EnumWindows() callback which is used to find the first (top// level) window belonging to the given processstatic BOOL CALLBACK wxEnumFindByPidProc(HWND hwnd, LPARAM lParam){    DWORD pid;    (void)::GetWindowThreadProcessId(hwnd, &pid);    wxNewFindByPidParams *params = (wxNewFindByPidParams *)lParam;    if ( pid == params->pid )    {        // remember the window we found        params->hwnd = hwnd;        // return FALSE to stop the enumeration        return FALSE;    }    // continue enumeration    return TRUE;}// This will be obsolete when we switch to using the version included// in wxWindows (from wxWin 2.3.1 onwards)int wxNewKill(long pid, wxSignal sig, ecKillError *krc = NULL){#ifdef __WIN32__    // get the process handle to operate on    HANDLE hProcess = ::OpenProcess(SYNCHRONIZE |                                    PROCESS_TERMINATE |                                    PROCESS_QUERY_INFORMATION,                                    FALSE, // not inheritable                                    (DWORD)pid);    if ( hProcess == NULL )    {        if ( krc )        {            if ( ::GetLastError() == ERROR_ACCESS_DENIED )            {                *krc = ecKILL_ACCESS_DENIED;            }            else            {                *krc = ecKILL_NO_PROCESS;            }        }        return -1;    }    bool ok = TRUE;    switch ( sig )    {        case wxSIGKILL:            // kill the process forcefully returning -1 as error code            if ( !::TerminateProcess(hProcess, (UINT)-1) )            {                wxLogSysError(_("Failed to kill process %d"), pid);                if ( krc )                {                    // this is not supposed to happen if we could open the                    // process                    *krc = ecKILL_ERROR;                }                ok = FALSE;            }            break;        case wxSIGNONE:            // do nothing, we just want to test for process existence            break;        default:            // any other signal means "terminate"            {                wxNewFindByPidParams params;                params.pid = (DWORD)pid;                // EnumWindows() has nice semantics: it returns 0 if it found                // something or if an error occured and non zero if it                // enumerated all the window                if ( !::EnumWindows(wxEnumFindByPidProc, (LPARAM)&params) )                {                    // did we find any window?                    if ( params.hwnd )                    {                        // tell the app to close                        //                        // NB: this is the harshest way, the app won't have                        //     opportunity to save any files, for example, but                        //     this is probably what we want here. If not we                        //     can also use SendMesageTimeout(WM_CLOSE)                        if ( !::PostMessage(params.hwnd, WM_QUIT, 0, 0) )                        {                            wxLogLastError(_T("PostMessage(WM_QUIT)"));                        }                    }                    else // it was an error then                    {                        wxLogLastError(_T("EnumWindows"));                        ok = FALSE;                    }                }                else // no windows for this PID                {                    if ( krc )                    {                        *krc = ecKILL_ERROR;                    }                    ok = FALSE;                }            }    }    // the return code    DWORD rc;    if ( ok )    {        // as we wait for a short time, we can use just WaitForSingleObject()        // and not MsgWaitForMultipleObjects()        switch ( ::WaitForSingleObject(hProcess, 500 /* msec */) )        {            case WAIT_OBJECT_0:                // process terminated                if ( !::GetExitCodeProcess(hProcess, &rc) )                {                    wxLogLastError(_T("GetExitCodeProcess"));                }                break;            default:                wxFAIL_MSG( _T("unexpected WaitForSingleObject() return") );                // fall through            case WAIT_FAILED:                wxLogLastError(_T("WaitForSingleObject"));                // fall through            case WAIT_TIMEOUT:                if ( krc )                {                    *krc = ecKILL_ERROR;                }                rc = STILL_ACTIVE;                break;        }    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -