Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

msn92

@msn92
About
Posts
38
Topics
12
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • ListBox.PreferredSize.Width interesting event
    M msn92

    Hello I think I've discovered some kind of bug here: I have a ListBox control. I fill its content through DataSource property. First time I set its width equal to ListBox.PreferredSize.Width, no matter what the real preferred width is, it is set to 120. From the second time use of PreferredSize.Width it works fine: the width is changed according to the content.

    class MyCtrl:UserControl
    {
    ListBox lb;
    public MyCtrl()
    {
    ...
    lb = new ListBox();
    lb.Visible = false;
    lb.Width = 50; //initially the width is set to 50
    this.Controls.Add(lb);
    ...
    }
    public ShowMyListBox(string[] data)
    {
    lb.DataSource = data;
    lb.Width = lb.PreferredSize.Width;
    //even though initially the Width is set to 50, lb.PreferredSize.Width returns 120 on the first call
    //but the following calls returns reliable preferred widths.
    lb.Visible = true;
    }
    }

    Interesting... Is it a bug? Is there any way to fix it?

    C# help question

  • MFC: Use firefox in MFC
    M msn92

    Hi everyone I'm interested in coding programs that work with the web. Most of the times, I need to host some web-browser in my application and use CHtmlView for it. I would like to try to host Firefox in my applications too. Since it is opensource, is not it possible to use it in the mfc application? Thank you in advance.

    C / C++ / MFC c++ question

  • CInternetSession: https certificate problem
    M msn92

    Code-o-mat, thanks for your reply. I tried the code that should ignore the invalid certifacate as said in the link you gave. But, it doesn't seem to work, the code's working, but my problem didn't get solved. Please see the code:

    CFile* f=NULL;
    MyTry:
    try{
    f=(CFile*)ises.OpenURL(L"https://mysite.com/login.jsp");
    }
    catch(CInternetException* s){
    if(s->m_dwError==ERROR_INTERNET_INVALID_CA){
    DWORD dwFlags;
    DWORD dwBufferLen=sizeof(dwFlags);
    ises.QueryOption(INTERNET_OPTION_SECURITY_FLAGS,(LPVOID)&dwFlags,&dwBufferLen);
    dwFlags|=SECURITY_FLAG_IGNORE_UNKNOWN_CA|SECURITY_FLAG_IGNORE_CERT_CN_INVALID;
    ises.SetOption(INTERNET_OPTION_SECURITY_FLAGS,&dwFlags,sizeof(dwFlags));
    goto MyTry;
    }
    }
    ...

    Is there any other way to workaround this problem?

    C / C++ / MFC help java com cryptography question

  • CInternetSession: https certificate problem
    M msn92

    Hello everybody. This is my problem: I need to connect to https webpage which has a self-signed certificate. Regular webbrowsers warn me when I open that page. I want to connect to it and POST some data. When I connect to the https webpage, I'm getting an error saying "The certificate authority is invalid or incorrect". Here's my code:

    CInternetSession ises;
    CFile* f=NULL;
    f=(CFile*)ises.OpenURL(L"https://mysite.com/login.jsp"); //I get the error here
    ...

    Is there any way to accept that certificate or any other solution? Thanks in advance.

    C / C++ / MFC help java com cryptography question

  • Minimizing the traffic
    M msn92

    Marc Firth, Thank you for your reply. Yes, I meant minimizing the amount of bandwidth. :) I guess I know those things. You're looking at the problem from the server's point of view. Look at it from client's point of view. I want to minimize the amount of traffic for my computer(not for server) as Internet Providers in my country charge a lot for bandwidth tariffs. Please review my idea once more. Would that be any help in my case? Thanks again.

    Web Development php sysadmin help question

  • Minimizing the traffic
    M msn92

    Hi I want to minimize the traffic as much as possible. Since most of the traffic is in plain text, I think compressing the traffic will help. This is the idea I came up with: 1. WebBrowser creates a request to the web server, The request will be send through the Proxy Program on the computer. 2. Proxy program on the computer compresses all the requests to be made to the web server, and sends it to "MyProxy.php" on my server. 3. "MyProxy.php" decompresses the request and sends it to the web server. "MyProxy.php" recieves the response from the web server, compresses it, and returns it to the Proxy Program on the computer. 4. The Proxy Program decompresses the response and returns it to the WebBrowser. 5. The WebBrowser shows the response to the user. Please see the figure[^] for more info. Do you think that's a good idea? Would it minimize the traffic by any percent?

    Web Development php sysadmin help question

  • Uploading a file using CHttpFile
    M msn92

    Hi I'm uploading a file using CInternetSession, CHttpConnection and CHttpFile. The program is working properly. However, I have some questions: 1. Does the program send data each time CHttpFile::Write() called? Or are all data sent when CHttpFile::EndRequest() called? 2. How big should the buffer size be(while reading from local file and writing to CHttpFile)?[Please see the source code below] 3. Does using Keep-alive connection(INTERNET_FLAG_KEEP_CONNECTION) help in any way?[Please see the source code below]

    CInternetSession ises = NULL;
    CHttpFile* httpf = NULL;
    CHttpConnection *connection = NULL;

    file=new CFile(L"file2upload.txt",CFile::modeRead);

    connection = ises.GetHttpConnection(L"myserver.com");

    http = connection->OpenRequest(CHttpConnection::HTTP_VERB_POST, L"upload.php",0,1,0,0,INTERNET_FLAG_KEEP_CONNECTION);

    CString hdrs /* = My appropriate headers to send */;
    httpf->AddRequestHeaders(hdrs);

    PreFileData /* = prefile data */;
    PostFileData /* = postfile data */;

    httpf->SendRequestEx(DWORD(PreFileData.GetLength()+file->GetLength()+PostFileData.GetLength()), HSR_SYNC | HSR_INITIATE);

    httpf->Write((LPSTR)(LPCSTR)PreFileData, PreFileData.GetLength());

    UINT len=1024;
    char buf[1024]; /*BUFFER SIZE = 1024 HOW BIG ACTUALLY SHOULD IT BE?*/
    while(len>0){
    len=f->Read(&buf,1024);
    if(len>0)httpf->Write(&buf,len);
    }

    httpf->Write((LPSTR)(LPCSTR)PostFileData, PostFileData.GetLength());

    httpf->EndRequest(HSR_SYNC);

    file->Close();
    httpf->Close();
    connection->Close();

    Thanks in advance

    C / C++ / MFC php com help question

  • Closing CDialog when it looses the focus
    M msn92

    Thank you Iain! I'm able to pass data between my dialogs. I have the last question. Promise, the last one :) I can catch outside clicks by using SetCapture & OnLButtonUp, but since I run SetCapture() my options dialog receiving no mouse messages inside(If I click on a button in the dialog, the button doesn't get clicked.) What can I do to fix that?

    C / C++ / MFC question help

  • Closing CDialog when it looses the focus
    M msn92

    Iain, thanks once more! I tried what you suggested: I created a class that holds the options:

    //I think you know graphing calculators...
    class WindowOptions {
    public:
    double xmin;
    double xmax;
    double xscl;
    double ymin;
    double ymax;
    double yscl;
    };

    When I create my optionsdialog, I'm passing a pointer to variable of WindowOptions class. But I'm unable to compile my project, I'm getting LNK2005 errors. "...You could have a structure of information somewhere in the main program, and pass COptionsDlg a pointer to it. Then, if the dialog is closed "properly" (ie, OK button), fill in the structure with the DoDataExchange / UpdateDate method." Can you give me an example please? Or link where I can read more about it?

    C / C++ / MFC question help

  • Closing CDialog when it looses the focus
    M msn92

    LOLz, Yes I've really missed it! :-D Thanks man! All I need is to override OnNcDestroy() and OnLButtonUp(), and it's working!!!

    BOOL COptionsDlg::OnInitDialog()
    {
    CDialog::OnInitDialog();
    SetCapture();//Thank you Iain
    return TRUE;
    }

    void COptionsDlg::OnNcDestroy()
    {//Thanks to DavidCrow
    CDialog::OnNcDestroy();
    delete this;
    }

    void COptionsDlg::OnLButtonUp(UINT nFlags, CPoint point)
    {//Thanks to Iain
    CDialog::OnLButtonUp(nFlags,point);
    CRect rect;
    this->GetWindowRect(rect);
    DWORD pos=GetMessagePos();
    point=CPoint(LOWORD(pos),HIWORD(pos));
    if(!rect.PtInRect(point)){this->DestroyWindow();}//close only if click was outside of the window
    }

    Thank you Iain and DavidCrow!!! :-D And one last question: How do I exchange data between my main window and that dialog I show?

    C / C++ / MFC question help

  • Extracting data from the webpages using MFC
    M msn92

    I have struggled with loading web page sources and parsing them too. This is the way I prefer and it's the easiest one I know:

    #include "afxinet.h"
    ...
    BOOL GetPageSource(CString& url, CString& source){
    CInternetSession ises;
    CFile* file=new CFile();
    try{//There might occur a connection error
    file=ises.OpenURL(url);//CInternetSession::OpenURL(url) returns a source code in CHttpFile;
    }
    catch(CInternetException* e){ //If an error occured, show messagebox with errorcode
    CString error=L"";
    error.Format(L"Connection error!\nError code: %ld",e->m_dwError);
    AfxMessageBox(error);
    return FALSE;
    }
    UINT len=1024;
    char buf[1024];
    source=L"";
    while(len>0){
    len=file->Read(buf,1024);
    if(len>0)source.Append(CString(buf),len);
    }
    file->Close();
    ises.Close();
    return TRUE;
    }

    You can use GetPageSource() function to get a page source. For the parsing part, I use regex.

    C / C++ / MFC c++ sharepoint com collaboration json

  • Closing CDialog when it looses the focus
    M msn92

    Joe Woodbury, thank you for your reply. EndDialog(IDOK); That works, but how do I catch the mouseclick outside of the CDialog that I show? I should close it when user clicks outside of the CDialog. Is it possible?

    C / C++ / MFC question help

  • Closing CDialog when it looses the focus
    M msn92

    Iain, thank you for your reply. It gets called. The problem is it crashes when I use DestroyWindow() inside OnKillFocus(). Looks like you had the same problem(quote from your source code):

    void CGenericPickerPopup::OnKillFocus(CWnd* pNewWnd)
    {
    CWnd::OnKillFocus(pNewWnd);

    ReleaseCapture();
    //DestroyWindow(); - causes crash when Custom colour dialog appears.
    

    }

    // KillFocus problem fix suggested by Paul Wilkerson.
    void CGenericPickerPopup::OnActivateApp(BOOL bActive, HTASK hTask)
    {
    CWnd::OnActivateApp(bActive, hTask);

    // If Deactivating App, cancel this selection
    if (!bActive)
    	EndSelection(CPN\_SELENDCANCEL);
    

    }

    Now I tried overriding OnActivateApp():

    void COptionsDlg::OnActivateApp(BOOL bActive, HTASK hTask)
    {
    CDialog::OnActivateApp(bActive, hTask);
    if (!bActive)DestroyWindow();
    }

    But nothing seems to be happening. What I'm doing wrong?

    C / C++ / MFC question help

  • Closing CDialog when it looses the focus
    M msn92

    Hi I have a COptionsDlg class delivered from CDialog. I open it when user right clicks on the main window:

    ...
    COptionsDlg* dlg=new COptionsDlg();
    dlg->Create(COptionsDlg::IDD,this);
    dlg->ShowWindow(TRUE);
    ...

    Now once it's shown I want to close it when user clicks anywhere outside of COptionsDlg. I tried overriding OnKillFocus() of COptionsDlg but it didn't work. And also one more question: How can I exchange data between my main window and COptionsDlg? Any help would be greatly appreciated :)

    C / C++ / MFC question help

  • Dictionaries: How do they work?
    M msn92

    Thank you for your reply Eddy Vluggen! Could MS-Access database be "A fast, embedded database" ? :)

    Database database question

  • Project
    M msn92

    Nobody is going to write the whole code for you. You should start yourself and if you'll have problems, then ask here. And please read How-to-get-an-answer-to-your-question[^] before posting next time.

    C / C++ / MFC help lounge

  • Dictionaries: How do they work?
    M msn92

    Hi everybody. I would like to know about dictionaries: How do they work? By "dictionary" I mean a program that translates a word from one language to another. So my questions are: 1. What kind of database do they usually use to store data? 2. How do they search so quickly? 3. Where can I get more info about dictionaries/their development? PS if it's not the right place I posted at.

    Database database question

  • TO place SetCaretPos at The end of the text
    M msn92

    You cannot move the caret using SetCaretPos() for CEdit and CRichEditCtrl. INFO[^] To move the caret use SetSel and specify the same start pos and end pos. Example:

    ...
    int p=m_RichEditCtrl.GetWindowTextLength()-1;
    m_RichEditCtrl.SetSel(p,p);
    ...

    Hope that helps.

    C / C++ / MFC question

  • Unicode to Hex conversion
    M msn92

    Ok, I figured it out. It is because of the charset (windows-1251). And to convert them to the hex format that firefox is using(windows-1251 charset), I had to replace each russian letter by hand with its hex equivalent in windows-1251 charset. I know, it's not the best way, but I couldn't find better one: Just in case, if someone needs it:

    /*----------------------------------*/
    //***Windows-1251 charset to Hex***
    //If works, it is written by
    //Siroj Matchanov(aka tech,msn92)
    //if it doesn't I dunno who wrote it
    //Recources used:
    //http://www.science.co.il/language/Character-Code.asp?s=1251
    /*----------------------------------*/

    void Win1251ToHex(
    CString &input, /*(windows-1251/ascii charset)*/
    CString &hex /*Output (in hex)*/
    )
    {
    hex=L"";
    for (int i=0;i<input.GetLength();i++)
    {
    //each char represents a unique number (e.g. int('Ў')=1038)
    int ii=input[i];
    //russian letters represent numbers that are greater than 1000
    if(ii>1024){
    //---------------------------------//
    // Uppercase&Lowercase Letters //
    // А-Я-а-я (1040-1071-1072-1103) //
    //---------------------------------//
    if((ii>1039)&&(ii<1104)){
    BYTE x=0xC0;
    x=x+(ii-1040);
    hex.Append(L"%");
    hex.AppendFormat(L"%x",x);
    }else{
    //------------------------//
    // Special symbols //
    //------------------------//
    switch (ii)
    {
    case 8218:
    {
    hex.Append(L"%82");//‚
    break;
    }
    case 8222:
    {
    hex.Append(L"%84");//„
    break;
    }
    case 8230:
    {
    hex.Append(L"%85");//…
    break;
    }
    case 1038:
    {
    hex.Append(L"%A1");//Ў
    break;
    }
    case 1118:
    {
    hex.Append(L"%A2");//ў
    break;
    }
    case 1025:
    {
    hex.Append(L"%A8");//Ё
    break;
    }
    case 1105:
    {
    hex.Append(L"%B8");//ё
    break;
    }
    case 8470:
    {
    hex.Append(L"%B9");//№
    break;
    }
    }
    }
    //Because they are not used usually,
    //this code doesn't convert the following symbols:
    //ЂЃ‚ѓ„…†‡€‰Љ‹ЊЌЋЏђ‘’“”•–—™љ›њќћџЈ¤Ґ¦§©«¬®Ї°±Ііґµ¶·є»јЅѕї
    //If you want them to be in windows-1251 charset format hex...
    //...then continue the code yourself please :)
    //(Almost) any other symbol in windows-1251 charset has
    //the same hex value as ascii symbols do.
    }else if(ii<127){
    hex.Append(L"%");
    hex.AppendFormat(L"%x",ascii[i]);
    }
    }
    }

    modified on Sunday, August 30, 2009 2:09 AM

    C / C++ / MFC tutorial question help

  • Unicode to Hex conversion
    M msn92

    CPallini, thank you for your reply. I have a web form that I need to submit programmatically and data should be in unicode. When I submit that web form using Firefox with the text символ, this is what Firefox is sending to the server:

    %F1%E8%EC%E2%EE%EB

    And I'm trying to send the same thing programmatically. So if символ = %F1%E8%EC%E2%EE%EB is wrong, why Firefox is sending it like that? Is it because of charset=WINDOWS-1251 in the source code of the web page:

    What should I do to convert to the same hex format Firefox is using? Please let me know, if I'm not clear enough.

    C / C++ / MFC tutorial question help
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups