1. set font from file
Assume there is a font file "ladderkk.ttf" under work dir and declare member variable 「CFont m_font」 in class private section。
view plain
C++:
if (AddFontResource("ladderkk.ttf") == 0) {
AfxMessageBox("add font fail");
return FALSE;
}
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
lf.lfHeight = 20; // Request [...]
使用 microsoft sapi in mfc 合成語音(tts)最簡單的方式,轉貼自 CodeProject - 「MFC speaks easily!」
1. include "EasySpeech.h"
view plain
C++:
// EasySpeech.h 的內容
class CSpeechVoice : public COleDispatchDriver
{
public:
CSpeechVoice() {}
long Speak(LPCTSTR Text, long Flags)
{
long result;
static BYTE parms[] = VTS_BSTR VTS_I4 ;
InvokeHelper(0xc, DISPATCH_METHOD, VT_I4, (void*)&result, parms, Text, Flags);
return result;
}
};
class CEasySpeech
{
public:
CEasySpeech() { ::CoInitialize(NULL); m_oddSpeechVoice.CreateDispatch(_T("SAPI.SpVoice")); }
~CEasySpeech() { m_oddSpeechVoice.ReleaseDispatch(); ::CoUninitialize(); }
long Speak(const LPCTSTR psz) { return (psz && _tcslen(psz) [...]
處理 Ctrl+A select all
view plain
C++:
//假設 CUtf2ansiDlg 為 CEdit 的父視窗
BOOL CUtf2ansiDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message == WM_KEYDOWN)
{
if(pMsg->wParam == 0x41) //A is pressed
{
SHORT ret;
ret = GetKeyState(VK_CONTROL);
if(ret & 0xff00)
{
UpdateData();
CEdit *pEdit = (CEdit *)CEdit::FromHandle(pMsg->hwnd);
pEdit->SetSel(0,-1); // select all the text
return TRUE;
}
}
}
return CDialog::PreTranslateMessage(pMsg);
}
CEdit 有 GetLine method,那有無SetLine ?
view plain
C++:
// Set [...]
How to Disable Default Pushbutton Handling for MFC Dialog
* Disable the OK Button as the Default Button. You find it under Properties (from the OK Button) -> Styles ->Default button.
or
view plain
C++:
BOOL CMyDialog::PreTranslateMessage(MSG* pMsg)
{
// Check for [ENTER] being pressed
if( pMsg->message==WM_KEYDOWN &&
[...]
轉貼自 Sysoft 時空論壇,順便介紹msdn沒有說明的函數 AfxExtractSubString
view plain
C++:
// Open the text file we want
CFile cfFile ("C:\TextFile.txt", CFile::modeNoTruncate | CFile::modeRead);
CArchive ar (&cfFile, CArchive::load); // Load its contents into a CArchive
// Initialise the variable which holds each line's contents
CString strLine = "";
if(!ar.ReadString(strLine))
// Read the first line of the CArchive into the variable
return; // Failed, so quit out
do // Repeat while there [...]