发送文本到静态控件
我这里有问题。 我想从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DialogBox 仅在对话框结束后返回。 DialogBox 返回一个 hwnd,您应该在其中发送消息。
DialogBox only returns after the dialog ends. DialogBox returns a hwnd which is where you should be sending the messages.