Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

SDI (Sound Device Interface)--A library for Auditory Display

, 2 May 2004
A GDI-like API for 3D positioning of speech, and MIDI composition using a single string.
newseverywhere.zip
newseverywhere_release.zip
release_sdi.zip
Release
sdi32.lib
sdi32.dll
a3dapi.dll
ibmeci.dll
SDI1.0Document.doc
TestSDI.exe
sdi.zip
sdi32.lib
sdi32.dll
a3dapi.dll
ibmeci.dll
SDI1.0Document.doc
TestSDI.exe
sdi_demo.zip
SDI_Demo
resource.aps
sdi32.lib
sdi32.dll
a3dapi.dll
TestSDIdll.dsp
ibmeci.dll
TestSDIdll.dsw
TestSDIdll.exe
comeacross.mid
sdi_src.zip
sdi32.lib
sdi32.dll
a3dapi.dll
ibmeci.dll
SDI1.0Document.doc
TestSDI.exe
src_sdi.zip
Source
sdi32
sdi32.dsw
exports.def
sdi32.dsp
DS_Buffer.gif
lib
ibmeci.lib
a3dapi.lib
ia3dutil.lib
ia3dutild.lib
ThirdParty
Document
DS_Buffer.gif
SDI1.0Document.doc
technote.doc
GNU General Public License.mht
General MIDI.mht
MIDI Specification.mht
MIDI File Format.mht
Downloadable Sounds (Level 1) Specification.pdf
Sample
NewsEverywhere_SourceCode
NewsEverywhereMFC
NewsEverywhereMFC.dsp
NewsEverywhereMFC.dsw
ParserDLLZXW
ParserDLLZXW.dsp
ParserDLLZXW.dsw
ParserDLLZXW.def
Parser
ParserDLLZXW.dll
res
NewsEverywhereMFC.ico
ico00002.ico
icon1.ico
title_ro.ico
buttonK1.ico
ico00001.ico
HTML.ico
Browser.ico
ico00003.ico
ico00004.ico
A3D_logo.bmp
Cursor
3dwarro.cur
move_r.cur
SDI_Demo
TestSDIdll.dsp
TestSDIdll.dsw
comeacross.mid
// NewsEverywhereMFCDlg.cpp : implementation file
//

#include "stdafx.h"
#include "NewsEverywhereMFC.h"
#include "NewsEverywhereMFCDlg.h"
#include "Helper.h"
#include "parser.h"
#include "sdi.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	CListBox	m_provider;
	CString	m_strCopyLeft;
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	virtual BOOL OnInitDialog();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
public:
	PARSERDESC** m_pParserDesc;
	INT			m_nParser;
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	m_strCopyLeft = _T("");
	//}}AFX_DATA_INIT
	m_strCopyLeft = _T(
"NewsEverywhere is free software; you can redistribute it and/or \
modify it under the terms of the GNU General Public License \
as published by the Free Software Foundation; either version 2 \
of the License, or (at your option) any later version. \
\r\n\
NewsEverywhere is distributed in the hope that it will be useful, \
but WITHOUT ANY WARRANTY; without even the implied warranty of \
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the \
GNU General Public License for more details. \
\r\n\
You should have received a copy of the GNU General Public License \
along with this program; if not, write to the Free Software \
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. \
\r\n\
����ʽ������ܛ�w��������������ܛ�w��������l���GNUͨ�ù����ڙ�l��Ҏ����\
�ͱ���ʽ�ٞ�ɢ���c�����޸ģ��oՓ���������DZ��ڙ�ĵڶ�����������x��ģ�\
��һ����l�еİ汾��\
\r\n\
����ʽ�S���ʹ��Ŀ�Ķ�����ɢ����Ȼ����ؓ�κΓ���؟�Σ���o���m���Ի��ض�Ŀ��\
�m���������Ĭʾ�ԓ�����Ԕ��Ո����GNUͨ�ù����ڙࡣ\
\r\n\
�������յ����S춱���ʽ��GNUͨ�ù����ڙ�ĸ�������o��Ո����������ܛ�w�������\
59 Temple Place �C Suite 330, Boston, Ma 02111-1307, USA��");

}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	DDX_Control(pDX, IDC_PROVIDER, m_provider);
	DDX_Text(pDX, IDC_COPYLEFT, m_strCopyLeft);
	//}}AFX_DATA_MAP
}

BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	for(int i=0; i<m_nParser; i++)
	{
		m_provider.AddString(m_pParserDesc[i]->psSiteName);
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

const UINT g_uMsg=RegisterWindowMessage("News Message");// Custom message for C/S communication

/////////////////////////////////////////////////////////////////////////////
// CNewsEverywhereMFCDlg dialog

CNewsEverywhereMFCDlg::CNewsEverywhereMFCDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CNewsEverywhereMFCDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNewsEverywhereMFCDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	// Member variables initialization
	m_hookProc=NULL;
	m_hSUIInput=NULL;
	m_hHook=NULL;
	m_dwStatus=0;
	
	m_nBGMIndex=-1;
	m_nParserSel=-1;
	m_nCategorySel=-1;
	m_nTitleSel=-1;
	m_nPrevPlayItem=-1;		// Index of source
	m_nPrevPlayContent=-1;	// Index of source

	// Title Displaying
	m_pTitle=NULL;
	m_nTitle=-1;;
	m_nTitleCurPlay=-1;
	m_nContentCurPlay=-1;

	// Parser Variables
	m_nParser=-1;
	m_pParserDesc=NULL;
	m_dwLanguage=0;
	m_pParserModule=NULL;
	
	m_hRoot=NULL;

	m_psPrevContent=NULL;

	m_hWnd=NULL;
	//m_rcPrev;
	m_hDC=NULL;
}

void CNewsEverywhereMFCDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNewsEverywhereMFCDlg)
	DDX_Control(pDX, IDC_SWITCH_HOTKEY, m_switchHotkey);
	DDX_Control(pDX, IDC_SPEED, m_speed);
	DDX_Control(pDX, IDC_CATEGORY, m_category);
	DDX_Control(pDX, IDC_SITE, m_site);
	//}}AFX_DATA_MAP
}



BEGIN_MESSAGE_MAP(CNewsEverywhereMFCDlg, CDialog)
	//{{AFX_MSG_MAP(CNewsEverywhereMFCDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_CBN_CLOSEUP(IDC_SITE, OnCloseupSite)
	ON_CBN_CLOSEUP(IDC_CATEGORY, OnCloseupCategory)
	ON_WM_TIMER()
	ON_WM_KEYDOWN()
	ON_BN_CLICKED(ID_MENU, OnMenu)
	ON_COMMAND(ID_EXIT, OnExit)
	ON_NOTIFY(NM_RELEASEDCAPTURE, IDC_SPEED, OnReleasedcaptureSpeed)
	ON_REGISTERED_MESSAGE(g_uMsg,OnKeyCaptured)
	ON_BN_CLICKED(IDC_SWITCH_HOTKEY, OnSwitchHotkey)
	//}}AFX_MSG_MAP
	ON_COMMAND_RANGE(TITLE_0,TITLE_MAX,OnTitleSelected)
	ON_COMMAND(ID_GOTO_CURTITLE,OnGotoTitle)
	ON_COMMAND(ID_GOTO_CURCONTENT,OnGotoContent)
	ON_MESSAGE(ID_SWITCH_TITLE, OnSwitchTitle)
	ON_MESSAGE(ID_SWITCH_CONTENT, OnSwitchContent)
	ON_MESSAGE(ID_PLAY_CURTITLE, OnPlayContent)
	ON_MESSAGE(ID_TITLE_UP, OnTitleUp)
	ON_MESSAGE(ID_TITLE_DOWN, OnTitleDown)
	ON_MESSAGE(MSG_SYSBAR,OnSysbarNotification)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNewsEverywhereMFCDlg message handlers

BOOL CNewsEverywhereMFCDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	// Set up parsers pool
	EnumerateParser();

	// Initialize ComboBox
	for(int i=0;i<m_nParser;i++)
	{
		TCHAR psSite[100];
		_tcscpy(psSite,m_pParserDesc[i]->psSiteName);
		_tcscat(psSite,"  [");
		_tcscat(psSite,m_pParserDesc[i]->psSiteUrl);
		_tcscat(psSite,"]");
		m_site.AddString(psSite);
	}

	// Initialize Speed Slider for title scrolling
	m_speed.SetRange(1, 10);
	m_speed.SetPos(5);

	if(InternetAttemptConnect(0) == ERROR_SUCCESS)
	{
		m_hRoot=InternetOpen("News Everywhere",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,
			NULL);
		if(m_hRoot == NULL)
		{
			MessageBox("����ʧ�ܣ����������������á�");
			return FALSE;
		}
	}

	// Set up SDI
	BOOL br;
	SDIVECTOR pos={0,0,0};

 	br=InitializeSDI(NULL, NULL, AfxGetInstanceHandle(), 0);
	_ASSERTE(br);

	// Speech object
	m_hTitle=CreateSpeech(SDI_LANGUAGE_MANDARIN_CHINESE, 
									SDI_VOICE_ADULTFEMALE1, 0);
	pos.x=-1.0f;
	SetPosition(m_hTitle, &pos);

	m_hContent=CreateSpeech(SDI_LANGUAGE_MANDARIN_CHINESE, 
								SDI_VOICE_ADULTMALE1, 0);
	pos.x=1.0f;
	SetPosition(m_hContent, &pos);

	// Earcon object
	m_hEarcon=CreateEarcon(666666L, 1024, MAKE_TIMESIGNATURE(4,2,0x18,0x08),0);

	// Create News bar
	HBRUSH brush=(HBRUSH)GetStockObject(BLACK_BRUSH);
	LPCTSTR psWndClass=AfxRegisterWndClass(CS_DBLCLKS,0,brush,0);
	
	OSVERSIONINFO osVersion;
	osVersion.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
	GetVersionEx(&osVersion);
	if(osVersion.dwMajorVersion>=5)
	{
		m_newsBar.CreateEx(WS_EX_LAYERED|WS_EX_TOPMOST,psWndClass,"",WS_POPUP,
		200,0,WIDTH_NEWSBAR,HEIGHT_NEWSBAR,GetSafeHwnd(),NULL,NULL);

		HMODULE hModule=LoadLibrary("user32.dll");
		if(hModule==NULL)
			return 0;
		typedef BOOL (__stdcall *PFNSetLayeredWindowAttributes)(HWND hwnd,COLORREF crKey,BYTE bAlpha,
			DWORD dwFlags);
		PFNSetLayeredWindowAttributes pfnSetLayeredWindowAttributes=(PFNSetLayeredWindowAttributes)GetProcAddress(hModule,
			"SetLayeredWindowAttributes");
		if(pfnSetLayeredWindowAttributes==NULL)
			return 0;
		(*pfnSetLayeredWindowAttributes)(m_newsBar.m_hWnd,NULL,150,LWA_ALPHA);
		FreeLibrary(hModule);	
	}
	else	
	{
		m_newsBar.CreateEx(WS_EX_TOPMOST,psWndClass,"",WS_POPUP,
			200,0,WIDTH_NEWSBAR,HEIGHT_NEWSBAR,GetSafeHwnd(),NULL,NULL);
	}
	m_newsBar.ShowWindow(SW_SHOW);
	m_newsBar.UpdateWindow();
	m_newsBar.m_hTitle=m_hTitle;
	m_newsBar.m_hContent=m_hContent;
	m_newsBar.m_hEarcon=m_hEarcon;
	m_newsBar.m_pdwStatus=&m_dwStatus;

	// Set up timer
	if(!SetTimer(TIMER_PLAY_TITLE,5*ELAPSE_TIMER_PLAY_TITLE,NULL))
		return 0;
	
	// Set up hook
	m_dwStatus |= STATUS_HOTKEY_DISABLED;
	m_dwStatus |= STATUS_HOTKEY_BG;
	m_newsBar.SetBGMode(TRUE);

	// Critical Section
	InitializeCriticalSection(&m_cs);
	
	m_newsBar.SetTitleMode(FALSE);
	m_newsBar.SetContentMode(FALSE);
	m_newsBar.SetTitleText("��ѡ������");
	m_dwStatus |= STATUS_CONTENT_DISABLE;
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CNewsEverywhereMFCDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.m_pParserDesc=m_pParserDesc;
		dlgAbout.m_nParser=m_nParser;
		dlgAbout.DoModal();
	}
	else
	{
		switch(nID)
		{
		case SC_MINIMIZE:
			Minimize();
			return;
			break;
		default:
			break;
		}
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CNewsEverywhereMFCDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CNewsEverywhereMFCDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CNewsEverywhereMFCDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	CDialog::OnLButtonDown(nFlags, point);
}

void CNewsEverywhereMFCDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	CDialog::OnLButtonUp(nFlags, point);
}

void CNewsEverywhereMFCDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
	CDialog::OnMouseMove(nFlags, point);
}


BOOL CNewsEverywhereMFCDlg::DestroyWindow() 
{	
	

	EnterCriticalSection(&m_cs);
	// HINTERNET
	InternetCloseHandle(m_hRoot);
	// GDI objects
	
	// Timer
	KillTimer(TIMER_PLAY_TITLE);

	
	// Parser
	for(int i=0;i<m_nParser;i++)
	{
		FreeLibrary(m_pParserModule[i]);
	}
	
	if(m_pParserDesc)
		delete[] m_pParserDesc;
	if(m_pParserModule)
		delete[] m_pParserModule;
	if(m_pTitle)
		delete[] m_pTitle;
	
	// Hook
	if(!(m_dwStatus & STATUS_HOTKEY_DISABLED))
	{
		UnhookWindowsHookEx(m_hHook);
		FreeLibrary(m_hSUIInput);
	}

	// SUI
	Stop(m_hTitle);
	Stop(m_hContent);
	Sleep(1000);
	ReleaseSDI();

	LeaveCriticalSection(&m_cs);

	DeleteCriticalSection(&m_cs);

	return CDialog::DestroyWindow();
}

int CNewsEverywhereMFCDlg::EnumerateParser()
{
	WIN32_FIND_DATA pData;
	int nParser=0;
	HANDLE hFind=FindFirstFile("Parser\\*.dll",&pData);
	if(hFind==INVALID_HANDLE_VALUE)
		return 0;
	do
	{
		nParser++;
	}while(FindNextFile(hFind,&pData));
	FindClose(hFind);
	m_pParserDesc=new PARSERDESC*[nParser];
	m_pParserModule=new HMODULE[nParser];
	m_nParser=nParser;
	nParser=0;
	hFind=FindFirstFile("Parser\\*.dll",&pData);
	do
	{
		TCHAR fileName[MAX_PATH];
		_tcscpy(fileName,"Parser\\");
		_tcscat(fileName,pData.cFileName);
		_RPT2(_CRT_WARN,"nParser=%u, File Name: %s\n",nParser,fileName);
		m_pParserModule[nParser]=LoadLibrary(fileName);
		if(m_pParserModule[nParser]==NULL)
			continue;
		GETPARSERDESCRIPTOR pfnGetParserDesc=(GETPARSERDESCRIPTOR)GetProcAddress(m_pParserModule[nParser],"GetParserDescriptor");
		m_pParserDesc[nParser] = (*pfnGetParserDesc)();
		nParser++;
	}while(FindNextFile(hFind,&pData));
	FindClose(hFind);
	return nParser;
}


void CNewsEverywhereMFCDlg::OnCloseupSite() 
{
	if(m_site.GetCurSel()==CB_ERR)
		return;
	EnterCriticalSection(&m_cs);

	m_nParserSel=m_site.GetCurSel();
	m_dwLanguage=m_pParserDesc[m_nParserSel]->dwLanguage;
	for(int i=0;i<m_pParserDesc[m_nParserSel]->nCategory;i++)
	{
		CString str=m_pParserDesc[m_nParserSel]->pCategory[i].psCategoryName;
		str+="  [";
		str+=m_pParserDesc[m_nParserSel]->pCategory[i].psCategoryUrl;
		str+="]";
		m_category.AddString(str);
	}

	LeaveCriticalSection(&m_cs);
}

void CNewsEverywhereMFCDlg::OnCloseupCategory()
{
	if(m_category.GetCurSel()==CB_ERR)
		return;

	EnterCriticalSection(&m_cs);

	m_nCategorySel=m_category.GetCurSel();
	ParseCategory();
	
	Stop(m_hTitle);
	Stop(m_hContent);
	
	m_nTitleSel=0;
	m_nTitleCurPlay=-1;
	m_nPrevPlayContent=-1;
	m_nPrevPlayItem=-1;
	m_dwStatus |= STATUS_PLAY_TITLE;		// Start rolling the headlines
	
	m_newsBar.m_pTitle=m_pTitle;
	m_newsBar.SetTitleMode(TRUE);
	
	LeaveCriticalSection(&m_cs);
}

void CNewsEverywhereMFCDlg::ParseCategory()
{
	TCHAR psText[MAX_TEXT_SIZE];
	int dwSize=GetUrlText(psText,MAX_TEXT_SIZE,
		m_pParserDesc[m_nParserSel]->pCategory[m_nCategorySel].psCategoryUrl
		//TEST_CATEGORY_URL_ECONOMIC
		);
	if(dwSize == -1)
	{
		MessageBox("�������ѻ����ԡ�");
		dwSize=GetTestText(TEST_TYPE_CATEGORY, psText);
	}
	

	EnterCriticalSection(&m_cs);
	
	// Fill TITLE structures
	PARSETITLEPROC pfnParseTitle=m_pParserDesc[m_nParserSel]->pfnParseTitle;
	m_nTitle=(*pfnParseTitle)(psText, m_nCategorySel, NULL);
	if(m_pTitle)
		delete m_pTitle;
	m_pTitle=new TITLE[m_nTitle];
	(*pfnParseTitle)(psText, m_nCategorySel, m_pTitle);

	m_nTitleCurPlay=0;
	m_newsBar.m_nTitle=m_nTitle;
	m_newsBar.m_pTitle=m_pTitle;

	LeaveCriticalSection(&m_cs);
}


int CNewsEverywhereMFCDlg::GetUrlText(PTSTR psBuffer, DWORD dwSize, PCTSTR psUrl)
{
	if(InternetAttemptConnect(0) != ERROR_SUCCESS)
	{
		MessageBox("��δ���ӵ����磬�����Ӻ����ԡ�");
		return -1;
	}
	m_hRoot=InternetOpen("News Everywhere",INTERNET_OPEN_TYPE_DIRECT,NULL,NULL,NULL);
	if(m_hRoot == NULL)
	{
		MessageBox("����ʧ�ܣ����������������á�");
		return -1;
	}
	HINTERNET hFile=InternetOpenUrl(m_hRoot,psUrl,NULL,0,0,NULL);
	if(hFile==INVALID_HANDLE_VALUE)
	{
		MessageBox("��ַ��������Ҫ���µ�ǰ��վ�Ľ������������Գ���һ�������������");
		return -1;
	}
	DWORD cbRead;
	if(FALSE==InternetReadFile(hFile,psBuffer,dwSize,&cbRead))
		return -1;
	InternetCloseHandle(hFile);
	return cbRead;
}


void CNewsEverywhereMFCDlg::OnTimer(UINT nIDEvent) 
{
	switch(nIDEvent)
	{
	case TIMER_PLAY_TITLE:
		{
			if(m_nTitle>-1 && (m_dwStatus & STATUS_PLAY_TITLE && m_pTitle))
			{
				EnterCriticalSection(&m_cs);
				m_nTitleCurPlay++;
				PlayTitle();
				m_newsBar.SetTitleText(m_pTitle[m_nTitleCurPlay].psTitle);
				if(m_nTitleCurPlay==m_nTitle)
				{
					m_nTitleCurPlay=0;
					ParseCategory();
				}
				LeaveCriticalSection(&m_cs);
			}
		}
		break;
	case TIMER_NEWSBAR:
		break;
	default:
		break;
	}
	CDialog::OnTimer(nIDEvent);
}

void CNewsEverywhereMFCDlg::PlayTitle()
{
	EnterCriticalSection(&m_cs);
	PlayNotation(m_hEarcon, "@I08 C42");
	
	PlayText(m_hTitle, m_pTitle[m_nTitleCurPlay].psTitle);
	LeaveCriticalSection(&m_cs);
}

void CNewsEverywhereMFCDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}

LRESULT CNewsEverywhereMFCDlg::OnKeyCaptured(WPARAM wParam, LPARAM lParam)
{
	EnterCriticalSection(&m_cs);

	if(m_dwStatus & STATUS_HOTKEY_BG)
	{
		if(wParam == KEY_SWITCH_MODE)
		{
			m_dwStatus &= ~STATUS_HOTKEY_BG;
			PlayNotation(m_hEarcon, "@I0C E44");
			m_newsBar.SetBGMode(FALSE);
			LeaveCriticalSection(&m_cs);
			return -1;
		}
	}
	if(m_dwStatus & STATUS_HOTKEY_BG)		// Reject key input if SUI is closed.
	{
		LeaveCriticalSection(&m_cs);
		return 0;
	}
	BOOL bHandled=FALSE;
	switch(wParam)
	{
	case KEY_TITLE_UP:
		OnTitleUp(ID_TITLE_UP,0,0,bHandled);
		break;
	case KEY_TITLE_DOWN:
		OnTitleDown(ID_TITLE_DOWN,0,0,bHandled);
		break;
	case KEY_OK:
		OnPlayContent(0,0,0,bHandled);
		break;
	case KEY_SWITCH_TITLE:
		OnSwitchTitle(0,0,0,bHandled);
		break;
	case KEY_SWITCH_CONTENT:
		OnSwitchContent(0,0,0,bHandled);
		break;
	case KEY_SWITCH_MODE:
		{
			m_dwStatus |= STATUS_HOTKEY_BG;
			m_newsBar.SetBGMode(TRUE);
			PlayNotation(m_hEarcon, "@I0C C44");
		}
		break;
	case KEY_GOTO_PAGE:
		GotoPage(m_nTitleCurPlay);
		break;
	}
	LeaveCriticalSection(&m_cs);
	return -1;
}

void CNewsEverywhereMFCDlg::PlayContent(int nIndex)
{
	if(nIndex<0)
		return;
	TCHAR psText[2*MAX_TEXT_SIZE],psContent[MAX_TEXT_SIZE];
	int nSize=GetUrlText(psText,2*MAX_TEXT_SIZE,
		m_pTitle[nIndex].psContentUrl
		//TEST_CONTENT_URL_ECONOMIC
		);
	if(nSize == -1)
	{
		MessageBox("�������ѻ����ԡ�");
		nSize=GetTestText(TEST_TYPE_CONTENT, psText);
	}

	EnterCriticalSection(&m_cs);

	PARSECONTENTPROC pfnParseContent=m_pParserDesc[m_nParserSel]->pfnParseContent;
	(*pfnParseContent)(psText,
		m_nCategorySel,
		psContent);

	m_dwStatus &= ~STATUS_CONTENT_DISABLE;
	m_newsBar.SetContentMode(TRUE);
	m_nContentCurPlay=nIndex;
	
	PlayText(m_hContent,psContent);

	LeaveCriticalSection(&m_cs);
}


void CNewsEverywhereMFCDlg::OnTitleSelected(UINT nID)
{
	EnterCriticalSection(&m_cs);
	
	m_nContentCurPlay=nID-TITLE_0;
	PlayNotation(m_hEarcon, "@I04 C34");
	PlayContent(m_nContentCurPlay);
	m_newsBar.SetContentMode(TRUE);
	
	LeaveCriticalSection(&m_cs);
}

void CNewsEverywhereMFCDlg::GotoPage(int nIndex)
{
	if(nIndex<0)
		return;
	TCHAR psCommandLine[MAX_PATH];
	GetSystemDirectory(psCommandLine,MAX_PATH);
	psCommandLine[3]='\0';	// Distill the x:\ part
	_tcscat(psCommandLine,"Program files\\Internet Explorer\\iexplore.exe ");
	_tcscat(psCommandLine,m_pTitle[nIndex].psContentUrl);
	STARTUPINFO info;
	ZeroMemory(&info,sizeof(STARTUPINFO));
	info.cb=sizeof(STARTUPINFO);

	PROCESS_INFORMATION process_info;
	CreateProcess(NULL,
		psCommandLine,NULL,NULL,FALSE,NULL,NULL,NULL,&info,&process_info);
	CloseHandle(process_info.hThread);
	CloseHandle(process_info.hProcess);
}

void CNewsEverywhereMFCDlg::Minimize()
{
	ShowWindow(SW_HIDE);
	NOTIFYICONDATA nd;
	nd.cbSize=NOTIFYICONDATA_V1_SIZE;
	nd.hWnd=GetSafeHwnd();
	nd.uID=SHELL_ICON_ID;
	nd.uFlags=NIF_ICON|NIF_TIP|NIF_MESSAGE;
	HINSTANCE hInst=AfxGetInstanceHandle();
	nd.hIcon=LoadIcon(hInst,MAKEINTRESOURCE(IDI_SYSBAR));
	_tcscpy(nd.szTip,IDS_SYSTIP);
	nd.uCallbackMessage=MSG_SYSBAR;

	Shell_NotifyIcon(NIM_ADD,&nd);

	PlayNotation(m_hEarcon, "@I09 E44");
}

LRESULT	CNewsEverywhereMFCDlg::OnSysbarNotification(WPARAM wParam, LPARAM lParam)
{
	switch(lParam)
	{
	case WM_LBUTTONDBLCLK:
		ShowWindow(SW_SHOW);
		SetForegroundWindow();
		NOTIFYICONDATA nd;
		nd.cbSize=NOTIFYICONDATA_V1_SIZE;
		nd.hWnd=GetSafeHwnd();
		nd.uID=SHELL_ICON_ID;

		Shell_NotifyIcon(NIM_DELETE,&nd);

		break;
	}
	return 0;
}

void CNewsEverywhereMFCDlg::OnMenu() 
{
	CMenu pops;
	CMenu* main;
	pops.LoadMenu(IDR_POPUP);
	main=pops.GetSubMenu(0);
	POINT point={330,25};
	ClientToScreen(&point);
	main->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,point.x,point.y,this);
}

void CNewsEverywhereMFCDlg::OnExit()
{
	m_newsBar.SetTitleText("�����˳������Ժ�...");
	OnClose();
}

void CNewsEverywhereMFCDlg::OnReleasedcaptureSpeed(NMHDR* pNMHDR, LRESULT* pResult) 
{
	SetTimer(TIMER_PLAY_TITLE, m_speed.GetPos()*ELAPSE_TIMER_PLAY_TITLE, NULL);
	*pResult = 0;
}


BOOL CNewsEverywhereMFCDlg::OnCommand(WPARAM wParam, LPARAM lParam) 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CDialog::OnCommand(wParam, lParam);
}

LRESULT CNewsEverywhereMFCDlg::OnPlayContent(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	PlayContent(m_nTitleCurPlay);
	return 0;
}

LRESULT CNewsEverywhereMFCDlg::OnSwitchTitle(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	PlayNotation(m_hEarcon, "@I0a E44");
	EnterCriticalSection(&m_cs);
	if(m_dwStatus & STATUS_PLAY_TITLE)
	{
		m_dwStatus &= ~STATUS_PLAY_TITLE;
	}
	else
	{
		m_dwStatus |= STATUS_PLAY_TITLE;
	}
	m_newsBar.SetTitleMode(m_dwStatus & STATUS_PLAY_TITLE);
	LeaveCriticalSection(&m_cs);
	return 0;
}

void CNewsEverywhereMFCDlg::OnSwitchHotkey() 
{
	EnterCriticalSection(&m_cs);
	if(m_dwStatus & STATUS_HOTKEY_DISABLED)
	{
		m_hSUIInput=LoadLibrary("Input.dll");
		if(m_hSUIInput==NULL)
			return;
		m_hookProc=(HOOKPROC)GetProcAddress(m_hSUIInput,"CaptureKeyForSUI");
		if(m_hookProc==NULL)
			return;
		m_hHook=SetWindowsHookEx(WH_KEYBOARD,m_hookProc,m_hSUIInput,0);
		if(m_hHook==NULL)
			return;
		m_dwStatus &= ~STATUS_HOTKEY_DISABLED;
		m_dwStatus |= STATUS_HOTKEY_BG;
		m_switchHotkey.SetWindowText("ֹͣ�ȼ�����");
	}
	else
	{
		UnhookWindowsHookEx(m_hHook);
		FreeLibrary(m_hSUIInput);
		m_dwStatus |= STATUS_HOTKEY_DISABLED;
		m_dwStatus |= STATUS_HOTKEY_BG;
		m_newsBar.SetBGMode(TRUE);
		m_switchHotkey.SetWindowText("�����ȼ�����");
	}
	LeaveCriticalSection(&m_cs);
}

int CNewsEverywhereMFCDlg::GetTestText(int nType, PTSTR psText)
{
	HANDLE hFile;
	if(nType == TEST_TYPE_CATEGORY)
		hFile=CreateFile("sports.htm",GENERIC_READ,FILE_SHARE_READ,NULL,
			OPEN_EXISTING,NULL,NULL);
	else if(nType == TEST_TYPE_CONTENT)
		hFile=CreateFile("content.htm",GENERIC_READ,FILE_SHARE_READ,NULL,
			OPEN_EXISTING,NULL,NULL);
	if(hFile==INVALID_HANDLE_VALUE)
		return -1;
	DWORD cbRead;
	BOOL br=ReadFile(hFile,psText, 2*MAX_TEXT_SIZE, &cbRead, NULL);
	if(!br)
		return -1;
	return cbRead;
}

void    CNewsEverywhereMFCDlg::OnGotoTitle()
{
	GotoPage(m_nTitleCurPlay);
}

void    CNewsEverywhereMFCDlg::OnGotoContent()
{
	GotoPage(m_nContentCurPlay);
}

LRESULT CNewsEverywhereMFCDlg::OnTitleUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	EnterCriticalSection(&m_cs);

	if(m_nTitle>-1)
	{
		if(m_nTitleCurPlay==m_nTitle-1)
			m_nTitleCurPlay=m_nTitle-1;
		else
			m_nTitleCurPlay++;
		PlayTitle();
		m_newsBar.m_psText=m_pTitle[m_nTitleCurPlay].psTitle;
		m_newsBar.SetTitleText(m_newsBar.m_psText);
	}
	
	LeaveCriticalSection(&m_cs);
	return 0;
}

LRESULT CNewsEverywhereMFCDlg::OnTitleDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	EnterCriticalSection(&m_cs);

	if(m_nTitle>-1)
	{
		if(m_nTitleCurPlay==0)
			m_nTitleCurPlay=0;
		else
			m_nTitleCurPlay--;
		PlayTitle();
		m_newsBar.m_psText=m_pTitle[m_nTitleCurPlay].psTitle;
		m_newsBar.SetTitleText(m_newsBar.m_psText);
	}
	
	LeaveCriticalSection(&m_cs);
	return 0;
}

LRESULT CNewsEverywhereMFCDlg::OnSwitchContent(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	EnterCriticalSection(&m_cs);
	if(m_nTitle>-1)
	{
		if(m_dwStatus & STATUS_CONTENT_DISABLE)
		{
			m_dwStatus &= ~STATUS_CONTENT_DISABLE;
			PlayNotation(m_hEarcon, "@I01 E44 C44");
			PlayContent(m_nContentCurPlay);
			m_newsBar.SetContentMode(TRUE);
		}
		else
		{
			m_dwStatus |= STATUS_CONTENT_DISABLE;
			PlayNotation(m_hEarcon, "@I01 E44 C44");
			Stop(m_hContent);
			m_newsBar.SetContentMode(FALSE);
		}
	}
	LeaveCriticalSection(&m_cs);
	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Dong Lin
Engineer
China China
A student at Zhejiang University, Zhejiang, China.
Major in Automation.
Now I want to study machine vision and robotics, but I'm really consumed with choices between hardware and software, and between research and engineering.
I'll be glad if you can give some suggestions.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150129.1 | Last Updated 3 May 2004
Article Copyright 2004 by Dong Lin
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid