Search code examples
c++winapistaticcstringsettext

Sending text to static control


I ve got problem here. I want to get info from AVI file and then ask user what he wants to do with it. For this I have dialogbox and there (among other things) I have static text control where I want the info text to appear. The code:

BOOL GetAviInfo(LPSTR szFileName)
    {
        AVIFileInit();

        PAVIFILE avi;
        int res=AVIFileOpen(&avi, szFileName, OF_READ, NULL);

        //some testing code

        AVIFILEINFO avi_info;
        AVIFileInfo(avi, &avi_info, sizeof(AVIFILEINFO));

        CString szFileInfo;
        szFileInfo.Format(  "Information about the AVI file: \n"
                "Dimention: %dx%d\n"
                "Max bytes per second: %d\n"
                "Samples per second: %d\n"
                "Streams: %d\n"
                "File Type: %d"
                "Length: %d frames\n\n"
                "What do you want to do?",
                                avi_info.dwWidth,
                                avi_info.dwHeight,
                                avi_info.dwLength,
                                avi_info.dwMaxBytesPerSec,
                                (DWORD) (avi_info.dwRate / avi_info.dwScale),
                                avi_info.dwStreams,
                                avi_info.szFileType
                            );
        MessageBox(NULL, szFileInfo, "Info", MB_OK); //this works
        int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_AVIINF_DIALOG), aviinfhwnd, AviInfDlgProc);
        SetDlgItemText(aviinfhwnd, AVIINF_STATIC_INFO, szFileInfo); //this doesnt work

        AVIFileExit();
        return TRUE;
    }

So I am confused why sending the Cstring to messagebox works fine while sending text to static control doesnt. Both functions (MessageBox and SetDlgItemText) require the same data type for the text (LPCTSTR). I was also trying to send the the text via WM_SETTEXT message and it didnt work either:

LPSTR lpstrChar=  szFileInfo.GetBuffer(0);
SendMessage(GetDlgItem(aviinfhwnd, AVIINF_STATIC_INFO), aviinfMsg, NULL, lpstrChar);

Please tell me what Im doing wrong and how to make the text appear in the static because I dont want to use the message box (redundant window). Thank you


Solution

  • DialogBox only returns after the dialog ends. DialogBox returns a hwnd which is where you should be sending the messages.