C ++奇文本行为 - 随机垃圾文本

时间:2012-04-25 05:18:43

标签: c++ class

解决

重新安装我的操作系统(2008 Server)之后,我发现我的程序中有一些奇怪的事情。

以下是部分来源http://phantomworksstudios.com/cpp/ss/sof-odd.h

的链接

首先是代码:

定制data.h

class INI_{

public:
const char* error;
stringstream CharToStr2;


Layout layout;      
Settings settings;

string file; 

int OpenFile(string open_file){
    CharToStr2.str("");
    ifstream SSMAIN_FILE_SETTINGS; 
    CharToStr2<<open_file;
    cout<<"CharToStr: "<<CharToStr2<<endl;
    cout<<"CharToStr.str(): "<<CharToStr2.str()<<endl; 
    cout<<"CharToStr.str.c_str(): "<<CharToStr2.str().c_str()<<endl;

    SSMAIN_FILE_SETTINGS.open(CharToStr2.str().c_str());
        if(!SSMAIN_FILE_SETTINGS){
        CharToStr2<<" is currupt or not found!. Loading default configuration!";
        cout<<"STRING1:"<<CharToStr2<<endl<<endl;
        cout<<"STRING2:"<<CharToStr2.str()<<endl<<endl;
        cout<<"STRING3:"<<CharToStr2.str().c_str()<<endl<<endl;
        error=CharToStr2.str().c_str(); 
        cout<<"ERROR:"<<error<<endl;   
        }
    cout <<"CLASS INI_: "<<SSMAIN_FILE_SETTINGS<<" : "<<file<<endl<<endl;
    }
};

INI_ SourceStudioConfiguration;

procedures.h

case WM_CREATE:  
SSMAIN_EXPLORERWINDOW_MENU=LoadMenu(SSMAIN_HINSTANCE,MAKEINTRESOURCE(ID_EXPLORER_MENU));
    SourceStudioConfiguration.layout.cx=0;   
    User_Buffer=32767;
    OpenProcessToken(GetCurrentProcess(),TOKEN_QUERY,&hToken);
    GetUserProfileDirectory(hToken,InfoBuf,&User_Buffer);
    User_Path=InfoBuf;
//      cout<<InfoBuf<<endl<<endl;
    CharToStr<<InfoBuf<<"\\Source Studio\\preference.ini";
    preference=CharToStr.str();
    cout<<User_Path<<" : "<<preference<<endl<<endl;
//       SourceStudioConfiguration.file=preference;
    SourceStudioConfiguration.OpenFile(preference);
    cout<<"CREATE:"<<SourceStudioConfiguration.error<<endl<<endl;

    cout<<"Class File"<<SourceStudioConfiguration.file<<endl<<endl;
    hbmPWSBUTTON = (HBITMAP)LoadBitmap(hInst_PWSBUTTON, MAKEINTRESOURCE(IMG_PWS_BUTTON));
    cout<<"Load PWS Bitmap: "<<hbmPWSBUTTON<<endl;
    hbmPWSCommandOVERVIEW=(HBITMAP)LoadBitmap(hInst_PWSCOMMANDTB,  MAKENTRESOURCE(IMG_PWS_COMMAND_OVERVIEW));
    hbmPWSCommandDOCUMENT=(HBITMAP)LoadBitmap(hInst_PWSCOMMANDTB, MAKEINTRESOURCE(IMG_PWS_COMMAND_DOCUMENT));
    hbmPWSCommandNEWFILE=(HBITMAP)LoadBitmap(hInst_PWSCOMMANDTB, MAKEINTRESOURCE(IMG_PWS_COMMAND_NEWFILE));
    hbmPWSCommandCLOSE=(HBITMAP)LoadBitmap(hInst_PWSCOMMANDTB, MAKEINTRESOURCE(IMG_PWS_COMMAND_CLOSE));
    cout<<"CREATE:"<<SourceStudioConfiguration.error<<endl<<endl;
    cout<<"Load PWS Command Toolbar Bitmap: "<<hbmPWSCommandOVERVIEW<<endl;
    cout<<"CREATE 277:"<<SourceStudioConfiguration.error<<endl<<endl;
    SSMAIN_REBARWINDOW = CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_TRANSPARENT, REBARCLASSNAME,NULL,            WS_CHILD|WS_BORDER|RBS_VARHEIGHT|TBS_HORZ|RBS_BANDBORDERS|CCS_NODIVIDER|CCS_NOPARENTALIGN,0,0,0,0,hwnd, NULL, 0, 0);     
    SSMAIN_EXPLORERWINDOW=CreateWindowEx(WS_EX_TRANSPARENT,"button",NULL, BS_GROUPBOX|WS_CHILD,0,79,150,SSMAIN_HEIGHT-157,hwnd, (HMENU)SSMAIN_EXPLORERWINDOW_MENU, SSMAIN_EXPLORERBAR_HINSTANCE, 0);     
    //SSMAIN_EXPLORERWINDOW_REBAR=CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_TRANSPARENT, REBARCLASSNAME, NULL, WS_CHILD|WS_BORDER|RBS_VARHEIGHT|TBS_HORZ|RBS_BANDBORDERS|CCS_NODIVIDER|CCS_NOPARENTALIGN, 0,0,0,0,SSMAIN_EXPLORERWINDOW,NULL,0,0);     
    SSMAIN_NAVIGATIONTOOLBAR=CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_TRANSPARENT, "TOOLBARWINDOW32", NULL, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT|TBSTYLE_ALTDRAG|TBSTYLE_LIST|CCS_NODIVIDER|CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NORESIZE, 0, 0, 0, 0,SSMAIN_REBARWINDOW, (HMENU)IDC_NAVIGATIONTOOLBAR, GetModuleHandle(NULL), NULL);
    SSMAIN_EXPLORERWINDOW_OVERVIEW=CreateWindowEx(0,"button", NULL,BS_BITMAP|BS_USERBUTTON|BS_TEXT|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, 4, 12, 18, 18,SSMAIN_EXPLORERWINDOW, (HMENU)IDC_EXPLORERWINDOW_REBAR_COMMANDBAR, GetModuleHandle(NULL), NULL);
    SSMAIN_EXPLORERWINDOW_DOCUMENT=CreateWindowEx(0, "button",NULL,BS_BITMAP|BS_USERBUTTON|BS_TEXT|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, 24, 12, 18, 18,SSMAIN_EXPLORERWINDOW, (HMENU)IDC_EXPLORERWINDOW_REBAR_COMMANDBAR, GetModuleHandle(NULL), NULL);
    SSMAIN_EXPLORERWINDOW_NEWFILE=CreateWindowEx(0,"button",NULL, BS_BITMAP|BS_USERBUTTON|BS_TEXT|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, 44, 12, 18, 18,SSMAIN_EXPLORERWINDOW, (HMENU)IDC_EXPLORERWINDOW_REBAR_COMMANDBAR, GetModuleHandle(NULL), NULL);
    SSMAIN_EXPLORERWINDOW_CLOSE=CreateWindowEx(0,"button",NULL, BS_BITMAP|BS_USERBUTTON|BS_TEXT|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, 62, 12, 18, 18,SSMAIN_EXPLORERWINDOW, (HMENU)IDC_EXPLORERWINDOW_REBAR_COMMANDBAR, GetModuleHandle(NULL), NULL);

    //SSMAIN_PARENTCONTAINER=CreateWindow("SYSTABCONTROL32","", WS_EX_COMPOSITED|WS_CHILD|WS_VISIBLE,100,100,0,0,hwnd,(HMENU)ID_PARENTCONTAINER,SSMAIN_PARENTCONTAINER_HINSTANCE, NULL);                  
    SSMAIN_STATIC_RTF_CONTAINER=CreateWindowEx(WS_EX_TRANSPARENT|WS_EX_CLIENTEDGE, "static","",WS_CHILD,0,0,0,0,hwnd,(HMENU)IDC_STATIC_RTF_CONTAINER,0,0);
    SSMAIN_STATIC_RTFCONTROL_PARENT_HSCROLL=CreateWindow("SCROLLBAR","", WS_EX_COMPOSITED|WS_CHILD|WS_VISIBLE|SBS_BOTTOMALIGN,100,100,20,20,SSMAIN_STATIC_RTF_CONTAINER,(HMENU)IDC_STATIC_RTFCONTROL_PARENT_HSCROLL,SSMAIN_PARENTCONTAINER_HINSTANCE,NULL);        

    SSMAIN_LISTBOXRTFCOUNT= CreateWindowEx(0,"LISTBOX",NULL, WS_CHILD|WS_CLIPSIBLINGS|ECO_AUTOVSCROLL|LBS_NOINTEGRALHEIGHT|LBS_NOTIFY|WS_VISIBLE|WS_GROUP, 0,0,0,0,SSMAIN_STATIC_RTF_CONTAINER,(HMENU)IDC_LISTBOXRTFCOUNT,NULL,NULL);             

    SSMAIN_RTFCONTROL=CreateWindow("RICHEDIT","text", WS_CHILD|WS_VISIBLE|ES_MULTILINE|ES_AUTOHSCROLL|WS_VSCROLL|WS_HSCROLL|WS_GROUP, 0,0,0,0,SSMAIN_STATIC_RTF_CONTAINER,(HMENU)IDC_RTFCONTROL,SSMAIN_RTFCONTROL_HINSTANCE,0);

    SSMAIN_TOOLBAR=CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_TRANSPARENT, "TOOLBARWINDOW32", NULL, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT|TBSTYLE_ALTDRAG|TBSTYLE_LIST|CCS_NODIVIDER|CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NORESIZE, 0, 0, 0, 0,hwnd, (HMENU)IDC_TOOLBAR, GetModuleHandle(NULL), NULL);
    SSMAIN_STATUSBAR = CreateWindow("MSCTLS_STATUSBAR32", "", WS_EX_COMPOSITED|WS_CHILD|WS_VISIBLE, 100, 100, 0, 0, hwnd, NULL, 0, NULL);                          

    cout<<"CREATE 300:"<<SourceStudioConfiguration.error<<endl<<endl;   SendMessage(SSMAIN_STATUSBAR,SB_SETPARTS,(WPARAM)3,(LPARAM)&panes);
    SSMAIN_TOOLBARSYNTAX = CreateWindowEx(WS_EX_TOOLWINDOW|WS_EX_TRANSPARENT, "TOOLBARWINDOW32", NULL, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|TBSTYLE_TOOLTIPS|TBSTYLE_FLAT|TBSTYLE_ALTDRAG|TBSTYLE_LIST|CCS_NODIVIDER|CCS_NOPARENTALIGN|CCS_ADJUSTABLE|CCS_NORESIZE, 0, 0, 0, 0,SSMAIN_REBARWINDOW, (HMENU)IDC_TOOLBARSYNTAX, GetModuleHandle(NULL), NULL);
    SSMAIN_PWSBUTTON = CreateWindowEx(WS_EX_TRANSPARENT, "static", NULL, SS_BITMAP|TBSTYLE_TOOLTIPS|SS_NOTIFY|WS_CHILD|WS_VISIBLE, 50, 50, 32, 32, hwnd, (HMENU)IDC_PWSBUTTON, 0, 0);     
                                                                                                         SSMAIN_TOOLTIP = CreateWindowEx(0, TOOLTIPS_CLASS, 0, WS_POPUP|TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, 0, SSMAIN_HINSTANCE, 0);

现在出于某种原因SSMAIN_RTFCONTROL=CreateWindow("RICHEDIT","...显示cout<<"CREATE 300:"<<SourceStudioConfiguration.error<<endl<<endl;后,文字全是随机文字。现在如果我在SSMAIN_RTFCONTROL=CreateWindow("RICHEDIT","...之前使用相同的东西,它将正确地显示它应该。

我的问题是它为什么这样做?

此外,如果我忽略SSMAIN_RTFCONTROL=CreateWindow("RICHEDIT","...作为评论,它会像它应该的那样工作,但是在cmd窗口上的更多行后,它将再次显示为随机文本。

有什么事我不明白吗?就像过多的信息一样,它开始混淆错误空间并且可能在其中设置一些东西,它不应该?

据我记得,在重新安装我的操作系统之前,我没有遇到这个问题。

谢谢,我真的对此感到困惑,如果您需要更多信息,请告诉我,我会发布它们

另外,我尝试通过应用像它所说的空格来设置代码的格式,但有时候它不允许在行前面有任何空格,有时它会这样做,所以我不知道是什么。< / p>

1 个答案:

答案 0 :(得分:0)

好的家伙在这里是解决方案,即使我不知道为什么这有任何意义......

class INI_{    

    public:
    const char* error;
    stringstream CharToStr2;
    string errordesc;
    Layout layout;      
    Settings settings;  
    string file; 

    int OpenFile(string open_file){
    CharToStr2.str("");
    ifstream SSMAIN_FILE_SETTINGS; 
    CharToStr2<<open_file;
    cout<<"CharToStr: "<<CharToStr2<<endl;
    cout<<"CharToStr.str(): "<<CharToStr2.str()<<endl; 
    cout<<"CharToStr.str.c_str(): "<<CharToStr2.str().c_str()<<endl;

    SSMAIN_FILE_SETTINGS.open(CharToStr2.str().c_str());
    if(!SSMAIN_FILE_SETTINGS){
        CharToStr2<<" is currupt or not found!. Loading default configuration!";
        cout<<"STRING1:"<<CharToStr2<<endl<<endl;
        cout<<"STRING2:"<<CharToStr2.str()<<endl<<endl;
        cout<<"STRING3:"<<CharToStr2.str().c_str()<<endl<<endl;
        errordesc=CharToStr2.str();
        error=errordesc.c_str(); 
        cout<<"ERROR:"<<error<<endl;   
    }
    cout <<"CLASS INI_: "<<SSMAIN_FILE_SETTINGS<<" : "<<file<<endl<<endl;
}
};

注意到我添加了一个变量字符串errordesc并将源流分配给它,然后将errordesc分配给错误