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

📄 rc2xml.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//Grab width and height    int width,height;    width=wxAtoi(GetToken());    height=wxAtoi(GetToken());    int c=0;    wxString buttonname,msg,tip,longhelp;    token=GetToken();    while ((token!=_T("BEGIN"))&(token!=_T("{")))        token=GetToken();    while ((token!=_T("END"))&(token!=_T("}")))        {        if (token==_T("BUTTON"))            {            buttonname=GetToken();            m_xmlfile.Write(_T("\t\t\t<object class=\"tool\""));            WriteName(buttonname);            m_xmlfile.Write(_T(">\n"));    //Write tool tip if any            if (LookUpString(buttonname,msg))                {                SplitHelp(msg,tip,longhelp);                m_xmlfile.Write(_T("\t\t\t\t<tooltip>")+tip+_T("</tooltip>\n"));                m_xmlfile.Write(_T("\t\t<longhelp>")+longhelp+_T("</longhelp>\n"));                }            //Make a bitmap file name            buttonname=CleanName(buttonname);            buttonname+=_T(".bmp");            m_xmlfile.Write(_T("\t\t\t\t<bitmap>")+buttonname+_T("</bitmap>\n"));        WriteToolButton(buttonname,c,width,height,bitmap);        m_xmlfile.Write(_T("\t\t\t</object>\n"));        c++;        }    else if (token==_T("SEPARATOR"))    {    m_xmlfile.Write(_T("\t\t\t<object class=\"separator\"/>\n"));    }    token=GetToken();    }    m_xmlfile.Write(_T("\t</object>\n"));}//Extract bitmaps from larger toolbar bitmapvoid rc2xml::WriteToolButton(wxString name,int index, int width, int height, wxBitmap bitmap){    int x;    x=index*width;    wxRect r(x,0,width,height);    wxBitmap little;    little=bitmap.GetSubBitmap(r);    little.SaveFile(m_targetpath+name,wxBITMAP_TYPE_BMP);}void rc2xml::ParseStringTable(wxString WXUNUSED(varname)){    wxString token;    token=GetToken();    while ((token!=_T("BEGIN"))&(token!=_T("{")))        token=GetToken();    token=GetToken();    wxString *msg;    while ((token!=_T("END"))&(token!=_T("}")))    {        msg=new wxString;        *msg=GetStringQuote();        m_stringtable->Append(token,msg);        token=GetToken();    }}bool rc2xml::LookUpString(wxString strid,wxString & st){    wxNode *node=m_stringtable->Find(strid);    wxString *s;    if (node==NULL)        return false;    s=(wxString *)node->GetData();    st=*s;    return true;}bool rc2xml::SplitHelp(wxString msg, wxString &shorthelp, wxString &longhelp){    int spot;    spot=msg.Find(_T("\\n"));    if (spot==wxNOT_FOUND)        {        shorthelp=msg;        longhelp=msg;        }    longhelp=msg.Left(spot);    spot=msg.Length()-spot-2;    shorthelp=msg.Right(spot);    return true;}void rc2xml::ParseMenuItem(){    wxString token,name,msg,tip,longhelp;//int spot;    if (PeekToken()==_T("SEPARATOR"))        {        m_xmlfile.Write(_T("\t\t\t<object class=\"separator\"/>\n"));        return;        }    token=GetQuoteField();    name=GetToken();//Remove \t because it causes problems//spot=token.First("\\t");//token=token.Left(spot);    m_xmlfile.Write(_T("\t\t\t<object class=\"wxMenuItem\""));    WriteName(name);    m_xmlfile.Write(_T(">\n"));    WriteLabel(token);//Look up help if any listed in stringtable//can't assume numbers correlate, restrict to string identifiers    if ((!name.IsNumber())&&(LookUpString(name,msg)))        {        SplitHelp(msg,tip,longhelp);        m_xmlfile.Write(_T("\t\t\t<help>")            +longhelp+_T("</help>\n"));        }//look for extra attributes like checked and break    wxString ptoken;    ptoken=PeekToken();    ptoken.MakeUpper();    while ((ptoken!=_T("MENUITEM"))&(ptoken!=_T("POPUP"))&(ptoken!=_T("END")))        {        token=GetToken();        ptoken.MakeUpper();        if (token==_T("CHECKED"))            m_xmlfile.Write(_T("\t\t\t<checkable>1</checkable>\n"));        else if (token==_T("MENUBREAK"))            ;//m_xmlfile.Write("\t\t\t</break>\n");        else if (token==_T("GRAYED"))            ;        else            wxLogError(_T("Unknown Menu Item token:")+token);        ptoken=PeekToken();        ptoken.MakeUpper();        }    m_xmlfile.Write(_T("\t\t\t</object>\n"));}//ICON            IDR_MAINFRAME,IDC_STATIC,11,17,20,20void rc2xml::ParseIconStatic(){    wxString token;    wxString varname,iconname;    token = PeekToken();    if (token.Contains(_T("\"")))        iconname = GetQuoteField();    else    iconname=GetToken();//Look up icon    varname=GetToken();    int x,y,width,height;    ReadRect(x,y,width,height);    m_xmlfile.Write(_T("\t\t<object class=\"wxStaticBitmap\""));    WriteBasicInfo(x,y,width,height,varname);//Save icon as a bitmap    WriteIcon(iconname);    m_xmlfile.Write(_T("\t\t</object>\n"));}//IDR_MAINFRAME           ICON    DISCARDABLE     "res\\mfcexample.ico"void rc2xml::ParseIcon(wxString varname){    wxString token;    wxString *iconfile;    iconfile=new wxString;    token=PeekToken();    *iconfile=GetQuoteField();    m_iconlist->Append(varname,iconfile);}wxString rc2xml::CleanName(wxString name){    name.MakeLower();    name.Replace(_T("id_"),wxEmptyString);    name.Replace(_T("idr_"),wxEmptyString);    name.Replace(_T("idb_"),wxEmptyString);    name.Replace(_T("idc_"),wxEmptyString);    name.Replace(_T(".ico"),wxEmptyString);    name.Replace(_T(".bmp"),wxEmptyString);    return name;}// And the award for most messed up control goes to...//    CONTROL         IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30void rc2xml::ParseStaticBitmap(wxString bitmapname, wxString varname){    wxString token;    //Grab SS_BITMAP    ReadOrs(token);    int x,y,width,height;    ReadRect(x,y,width,height);    m_xmlfile.Write(_T("\t\t<object class=\"wxStaticBitmap\""));    WriteBasicInfo(x,y,width,height,varname);    WriteBitmap(bitmapname);    m_xmlfile.Write(_T("\t\t</object>\n"));}void rc2xml::ParseNormalMSControl(){    wxString label=GetQuoteField();    wxString varname=GetToken();    wxString kindctrl=GetQuoteField();    kindctrl.MakeUpper();    if (kindctrl==_T("MSCTLS_UPDOWN32"))        ParseSpinCtrl(label,varname);    else if (kindctrl==_T("MSCTLS_TRACKBAR32"))        ParseSlider(label,varname);    else if (kindctrl==_T("MSCTLS_PROGRESS32"))        ParseProgressBar(label,varname);    else if (kindctrl==_T("SYSTREEVIEW32"))        ParseTreeCtrl(label,varname);    else if (kindctrl==_T("SYSMONTHCAL32"))        ParseCalendar(label,varname);    else if (kindctrl==_T("SYSLISTVIEW32"))        ParseListCtrl(label,varname);    else if (kindctrl==_T("BUTTON"))        ParseCtrlButton(label,varname);    else if (kindctrl==_T("RICHEDIT"))        ParseRichEdit(label,varname);    else if (kindctrl==_T("STATIC"))    {        wxString token;        wxFileOffset p = m_rc.Tell();        ReadOrs(token);        m_rc.Seek(p);        if (token.Find(_T("SS_BITMAP"))!=wxNOT_FOUND)            ParseStaticBitmap(label,varname);        else            ParseStaticText(label,varname);    }    else if (kindctrl==_T("EDIT"))        ParseTextCtrl(varname);    else if (kindctrl==_T("LISTBOX"))        ParseListBox(varname);    else if (kindctrl==_T("COMBOBOX"))        ParseComboBox(varname);}void rc2xml::ParseWeirdMSControl(){    wxString id = GetToken();    wxString varname = GetToken();    wxString kindctrl = GetQuoteField();    kindctrl.MakeUpper();//    CONTROL         IDB_FACE,IDC_STATIC,"Static",SS_BITMAP,26,62,32,30    if (kindctrl==_T("STATIC"))    {        if (PeekToken()==_T("SS_BITMAP"))            ParseStaticBitmap(id,varname);        else            wxLogError(_T("Unknown MS Control Static token"));    }}//SCROLLBAR       IDC_SCROLLBAR1,219,56,10,40,SBS_VERTvoid rc2xml::ParseScrollBar(){    wxString token;    wxString varname;    varname=GetToken();    int x,y,width,height;    ReadRect(x,y,width,height);    wxString style;    ReadOrs(token);if (token.Find(_T("SBS_VERT"))!=wxNOT_FOUND)    style=_T("wxSB_VERTICAL");//Default MFC style is horizontal    else        style=_T("wxSB_HORIZONTAL");    m_xmlfile.Write(_T("\t\t<object class=\"wxScrollBar\""));    WriteBasicInfo(x,y,width,height,varname);    WriteStyle(style);    m_xmlfile.Write(_T("\n\t\t</object>\n"));}//    CONTROL         "Tree1",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_TABSTOP,//                      7,7,66,61void rc2xml::ParseTreeCtrl(wxString WXUNUSED(label), wxString varname){    wxString token;//while (ReadOrs(token));    ReadOrs(token);    int x,y,width,height;    ReadRect(x,y,width,height);    m_xmlfile.Write(_T("\t\t<object class=\"wxTreeCtrl\""));    WriteBasicInfo(x,y,width,height,varname);    m_xmlfile.Write(_T("\t\t</object>\n"));}//    CONTROL         "MonthCalendar1",IDC_MONTHCALENDAR1,"SysMonthCal32",                    //MCS_NOTODAY | WS_TABSTOP,105,71,129,89void rc2xml::ParseCalendar(wxString WXUNUSED(label), wxString varname){    wxString token;//while (ReadOrs(token));    ReadOrs(token);    int x,y,width,height;    ReadRect(x,y,width,height);    m_xmlfile.Write(_T("\t\t<object class=\"wxCalendarCtrl\""));    WriteBasicInfo(x,y,width,height,varname);    m_xmlfile.Write(_T("\t\t</object>\n"));}//    CONTROL         "List1",IDC_LIST1,"SysListView32",WS_BORDER | WS_TABSTOP,  //                  7,89,68,71void rc2xml::ParseListCtrl(wxString WXUNUSED(label), wxString varname){    wxString token;    //while (ReadOrs(token));    ReadOrs(token);    int x,y,width,height;    ReadRect(x,y,width,height);    m_xmlfile.Write(_T("\t\t<object class=\"wxListCtrl\""));    WriteBasicInfo(x,y,width,height,varname);    m_xmlfile.Write(_T("\t\t</object>\n"));}void rc2xml::WriteBitmap(wxString bitmapname){//Look up bitmap    wxNode *node=m_bitmaplist->Find(LookUpId(bitmapname));    if (node==NULL)        {        m_xmlfile.Write(_T("\t\t\t<bitmap>missingfile</bitmap>\n"));        wxLogError(_T("Unable to find bitmap:")+bitmapname);        return;        }    wxString *bitmappath;    bitmappath=(wxString *)node->GetData();    bitmapname=wxFileNameFromPath(*bitmappath);    wxBitmap bitmap;    if (!bitmap.LoadFile(*bitmappath,wxBITMAP_TYPE_BMP ))        wxLogError(_T("Unable to load bitmap:")+*bitmappath);    //Make a bitmap file name    bitmapname=CleanName(bitmapname);    bitmapname+=_T(".bmp");    m_xmlfile.Write(_T("\t\t\t<bitmap>")+bitmapname+_T("</bitmap>\n"));    bitmap.SaveFile(m_targetpath+bitmapname,wxBITMAP_TYPE_BMP);}void rc2xml::WriteIcon(wxString iconname){wxNode *node=m_iconlist->Find(iconname);    if (node==NULL)        {        m_xmlfile.Write(_T("\t\t\t<bitmap>missing_file</bitmap>\n"));        wxLogError(_T("Unable to find icon:")+iconname);        }    wxString *iconpath;    iconpath=(wxString *)node->GetData();    wxIcon icon;    wxBitmap bitmap;    if (!icon.LoadFile(*iconpath,wxBITMAP_TYPE_ICO ))        wxLogError(_T("Unable to load icon:")+*iconpath);#ifdef __WXMSW__    bitmap.CopyFromIcon(icon);#else    bitmap = icon;#endif    iconname=wxFileNameFromPath(*iconpath);    //Make a bitmap file name    iconname=CleanName(iconname);    iconname+=_T(".bmp");    m_xmlfile.Write(_T("\t\t\t<bitmap>")+iconname+_T("</bitmap>\n"));    bitmap.SaveFile(m_targetpath+iconname,wxBITMAP_TYPE_BMP);}/*Unfortunately sometimes the great MSVC Resource editor decidesto use numbers instead of the word id.  I have no idea why theydo this, but that is the way it is.*//* this is a quick and dirty way to parse the resource.h fileit will not recognize #ifdef so it can be easily fooled*/void rc2xml::ParseResourceHeader(){wxTextFile r;//Attempt to load resource.h in current path    if (!r.Open(_T("resource.h")))        {        wxLogError(_T("Warining Unable to load resource.h file"));        return;        }    wxString str;    wxString id,v;    wxStringTokenizer tok;    wxString *varname;    long n;//Read through entire file    for ( str = r.GetFirstLine(); !r.Eof(); str = r.GetNextLine() )    {    if (str.Find(_T("#define"))!=wxNOT_FOUND)        {        tok.SetString(str);        //Just ignore #define token        tok.GetNextToken();        v=tok.GetNextToken();        id=tok.GetNextToken();        if (id.IsNumber())            {            varname=new wxString;            id.ToLong(&n);            *varname=v;            m_resourcelist->Append(n,varname);            }        }    }}wxString rc2xml::LookUpId(wxString id){wxString st;if (!id.IsNumber())    return id;long n;id.ToLong(&n);wxNode *node=m_resourcelist->Find(n);    wxString *s;    if (node==NULL)        return id;    s=(wxString *)node->GetData();    st=*s;return st;}

⌨️ 快捷键说明

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