发送文本到静态控件

发布于 2024-11-14 07:37:39 字数 1847 浏览 4 评论 0原文

我这里有问题。 我想从 AVI 文件中获取信息,然后询问用户他想用它做什么。为此,我有对话框,并且(除其他外)我有静态文本控件,我希望在其中显示信息文本。代码:

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;
    }

所以我很困惑为什么将 Cstring 发送到消息框工作正常,而将文本发送到静态控件则不行。这两个函数(MessageBox 和 SetDlgItemText)都需要相同的文本数据类型 (LPCTSTR)。我还尝试通过 WM_SETTEXT 消息发送文本,但它也不起作用:

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

请告诉我我做错了什么以及如何使文本出现在静态中,因为我不想使用消息框(冗余窗口)。 谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

℡Ms空城旧梦 2024-11-21 07:37:39

DialogBox 仅在对话框结束后返回。 DialogBox 返回一个 hwnd,您应该在其中发送消息。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文