⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chatdlg.cpp

📁 著名的任天堂FC游戏机模拟器VirtuaNes 085版的源码!
💻 CPP
字号:
//
// 僠儍僢僩僟僀傾儘僌僋儔僗
//
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include <stdlib.h>
#include <mbstring.h>
#include <shlwapi.h>

#include <string>
using namespace std;

#include "typedef.h"
#include "macro.h"

#include "VirtuaNESres.h"
#include "DebugOut.h"
#include "App.h"
#include "Pathlib.h"
#include "Config.h"

#include "NetPlay.h"

#include "Wnd.h"
#include "ChatDlg.h"

// 儊僢僙乕僕
DLG_MESSAGE_BEGIN(CChatDlg)
DLG_ON_MESSAGE( WM_INITDIALOG,	OnInitDialog )
DLG_ON_MESSAGE( WM_DESTROY,	OnDestroy )
DLG_ON_MESSAGE( WM_CLOSE,	OnClose )
DLG_ON_MESSAGE( WM_ACTIVATE,	OnActivate )
DLG_ON_MESSAGE( WM_SETCURSOR,	OnSetCursor )
DLG_ON_MESSAGE( WM_SIZE,	OnSize )
DLG_ON_MESSAGE( WM_CTLCOLORSTATIC, OnControlColorStatic )
DLG_ON_MESSAGE( WM_COPYDATA,	OnCopyData )

// 僐儅儞僪
DLG_COMMAND_BEGIN()
DLG_ON_COMMAND_NOTIFY( IDC_NCT_MESSAGE, EN_SETFOCUS, OnMessageFocus )
DLG_ON_COMMAND( IDOK, OnOK )
DLG_ON_COMMAND( IDCANCEL, OnCancel )
DLG_ON_COMMAND( IDC_NCT_SEND, OnSend )
DLG_COMMAND_END()
// Notify 儊僢僙乕僕
DLG_NOTIFY_BEGIN()
DLG_NOTIFY_END()
DLG_MESSAGE_END()

BOOL	CChatDlg::Create( HWND hWndParent )
{
	// 恊偼僨僗僋僩僢僾偵偡傞
	m_hWnd = ::CreateDialogParam( CApp::GetPlugin(), MAKEINTRESOURCE(IDD_NETPLAY_CHAT),
				NULL, g_DlgProc, (LPARAM)this );
	if( !m_hWnd )
		return	FALSE;

	// 儌乕僪儗僗僟僀傾儘僌儕僗僩偵壛偊傞
	CWndList::Add( this );

	return	TRUE;
}

void	CChatDlg::Destroy()
{
	if( m_hWnd ) {
		// 儌乕僪儗僗僟僀傾儘僌儕僗僩偐傜嶍彍
		CWndList::Del( this );

		::GetWindowRect( m_hWnd, &Config.netplay.rcChatPos );

		::DestroyWindow( m_hWnd );
		m_hWnd = NULL;
	}
}

void	CChatDlg::SetEditText()
{
	CHAR	szText[256+1];

	::GetWindowText( ::GetDlgItem(m_hWnd, IDC_NCT_EDIT), szText, sizeof(szText)-1 );
	::SetWindowText( ::GetDlgItem(m_hWnd, IDC_NCT_EDIT), "" );

	if( ::strlen(szText) ) {
		// clear message window
		if( ::StrCmpI( szText, "/clear" ) == 0 ) {
			::SendDlgItemMessage( m_hWnd, IDC_NCT_MESSAGE, EM_SETSEL, 0, -1 );
			::SendDlgItemMessage( m_hWnd, IDC_NCT_MESSAGE, EM_REPLACESEL, FALSE, (WPARAM)"" );
			return;
		}

		string	str;

		if( NetPlay.IsConnect() ) {
			str = "(";
			str = str + Config.netplay.szNick;
			str = str + ") ";
		}

		str = str + szText;
		str = str + "\r\n";

		// 憡庤偵憲怣
		if( NetPlay.IsConnect() ) {
			NetPlay.ChatSend( (LPSTR)str.c_str() );
		}

		// 帺暘帺恎偺儊僢僙乕僕傪昞帵
		INT n = GetWindowTextLength( GetDlgItem( m_hWnd, IDC_NCT_MESSAGE ) );
		::SendDlgItemMessage( m_hWnd, IDC_NCT_MESSAGE, EM_SETSEL, (WPARAM)n, (LPARAM)n );
		::SendDlgItemMessage( m_hWnd, IDC_NCT_MESSAGE, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)str.c_str() );
	}
}

DLGMSG	CChatDlg::OnCopyData( DLGMSGPARAM )
{
	COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)lParam;
	CHAR*	lpStr = (CHAR*)pcds->lpData;

	INT n = GetWindowTextLength( GetDlgItem( hWnd, IDC_NCT_MESSAGE ) );
	::SendDlgItemMessage( hWnd, IDC_NCT_MESSAGE, EM_SETSEL, (WPARAM)n, (LPARAM)n );
	::SendDlgItemMessage( hWnd, IDC_NCT_MESSAGE, EM_REPLACESEL, (WPARAM)TRUE, (LPARAM)lpStr );

	if( ::GetFocus() != m_hWnd && ::strlen( lpStr ) > 0 ) {
		::MessageBeep( MB_OK );
//		::PlaySound( "MailBeep", NULL, SND_ALIAS|SND_ASYNC );
	}

	// 儊僢僙乕僕偑棃偨傜億僢僾傾僢僾偝偣傞偨傔
	::SendMessage( CApp::GetHWnd(), WM_VNS_CHATPOPUP, 0, 0 );

	return	TRUE;
}

DLGMSG	CChatDlg::OnInitDialog( DLGMSGPARAM )
{
//	DEBUGOUT( "CChatDlg::OnInitDialog\n" );

	NetPlay.SetChatWnd( m_hWnd );

	// 埵抲忣曬傪曐懚
	::GetClientRect( m_hWnd, &m_rcClient );
	::GetWindowRect( ::GetDlgItem(m_hWnd, IDC_NCT_MESSAGE), &m_rcMessage );
	::GetWindowRect( ::GetDlgItem(m_hWnd, IDC_NCT_EDIT), &m_rcEdit );
	::GetWindowRect( ::GetDlgItem(m_hWnd, IDC_NCT_SEND), &m_rcButton );

	// 僋儔僀傾儞僩嵗昗傊偺曄姺
	::ScreenToClient( m_hWnd, (POINT*)&m_rcMessage.left );
	::ScreenToClient( m_hWnd, (POINT*)&m_rcMessage.right );
	::ScreenToClient( m_hWnd, (POINT*)&m_rcEdit.left );
	::ScreenToClient( m_hWnd, (POINT*)&m_rcEdit.right );
	::ScreenToClient( m_hWnd, (POINT*)&m_rcButton.left );
	::ScreenToClient( m_hWnd, (POINT*)&m_rcButton.right );

	// 僂僀儞僪僂埵抲/僒僀僘偺愝掕
//	RECT	rc = Config.launcher.rcWindowPos;
//	if( (rc.right-rc.left) && (rc.bottom-rc.top) ) {
//		::SetWindowPos( m_hWnd, NULL, rc.left, rc.top, RCWIDTH(rc), RCHEIGHT(rc), SWP_NOZORDER );
//	}

	// 僂僀儞僪僂埵抲/僒僀僘偺愝掕
	RECT	rc = Config.netplay.rcChatPos;
	if( (rc.right-rc.left) && (rc.bottom-rc.top) ) {
		::SetWindowPos( m_hWnd, NULL, rc.left, rc.top, RCWIDTH(rc), RCHEIGHT(rc), SWP_NOZORDER );
	}

	// 昞帵
	::ShowWindow( m_hWnd, SW_SHOW );

	return	TRUE;
}

DLGMSG	CChatDlg::OnDestroy( DLGMSGPARAM )
{
	return	TRUE;
}

DLGMSG	CChatDlg::OnClose( DLGMSGPARAM )
{
	::ShowWindow( m_hWnd, SW_HIDE ); // 旕昞帵偵偡傞偩偗
	return	TRUE;
}

DLGMSG	CChatDlg::OnActivate( DLGMSGPARAM )
{
	if( LOWORD(wParam) == WA_INACTIVE ) {
//		DEBUGOUT( "CChatDlg::OnActivate:Inactive\n" );
		::PostMessage( CApp::GetHWnd(), WM_VNS_SHORTCUTENABLE, (WPARAM)TRUE, 0 );

		Config.InputKeyboardDisable( FALSE );
	} else {
//		DEBUGOUT( "CChatDlg::OnActivate:Active\n" );
		::PostMessage( CApp::GetHWnd(), WM_VNS_SHORTCUTENABLE, (WPARAM)FALSE, 0 );

		Config.InputKeyboardDisable( TRUE );
	}
	return	TRUE;
}

DLGMSG	CChatDlg::OnSetCursor( DLGMSGPARAM )
{
//	DEBUGOUT( "CChatDlg::OnSetCursor\n" );
	return	FALSE;
}

DLGMSG	CChatDlg::OnSize( DLGMSGPARAM )
{
//	DEBUGOUT( "CChatDlg::OnSize\n" );
	HWND	hWndCtrl;
	RECT	rcC, rcT;
	::GetClientRect( m_hWnd, &rcC );

	// 儊僢僙乕僕榞
	if( (hWndCtrl = ::GetDlgItem( m_hWnd, IDC_NCT_MESSAGE )) ) {
		rcT.left   = rcC.left;
		rcT.right  = rcC.right;
		rcT.top    = rcC.top;
		rcT.bottom = rcC.bottom - (m_rcClient.bottom-m_rcMessage.bottom);
		::MoveWindow( hWndCtrl, rcT.left, rcT.top, RCWIDTH(rcT), RCHEIGHT(rcT), TRUE );
	}
	if( (hWndCtrl = ::GetDlgItem( m_hWnd, IDC_NCT_EDIT )) ) {
		rcT.left   = rcC.left;
		rcT.right  = rcC.right - (m_rcClient.right-m_rcEdit.right);
		rcT.top    = rcC.bottom - (m_rcClient.bottom-m_rcEdit.top);
		rcT.bottom = rcC.bottom - (m_rcClient.bottom-m_rcEdit.bottom);
		::MoveWindow( hWndCtrl, rcT.left, rcT.top, RCWIDTH(rcT), RCHEIGHT(rcT), TRUE );
	}
	if( (hWndCtrl = ::GetDlgItem( m_hWnd, IDC_NCT_SEND )) ) {
		rcT.left   = rcC.right - (m_rcClient.right-m_rcButton.left);
		rcT.right  = rcT.left + RCWIDTH(m_rcButton);
		rcT.top    = rcC.bottom - (m_rcClient.bottom-m_rcButton.top);
		rcT.bottom = rcT.top + RCHEIGHT(m_rcButton);
		::MoveWindow( hWndCtrl, rcT.left, rcT.top, RCWIDTH(rcT), RCHEIGHT(rcT), TRUE );
	}
	return	FALSE;
}

DLGMSG	CChatDlg::OnControlColorStatic( DLGMSGPARAM )
{
	if( (HWND)lParam == ::GetDlgItem( m_hWnd, IDC_NCT_MESSAGE ) ) {
		SetBkColor( (HDC)wParam, (COLORREF)0x00FFFFFF );
		bResult = (LRESULT)GetStockObject( WHITE_BRUSH );
		return	TRUE;
	}
	return	FALSE;
}

DLGCMD	CChatDlg::OnMessageFocus( DLGCMDPARAM )
{
	DEBUGOUT( "CChatDlg::OnMessageFocus\n" );

//	::SetFocus( ::GetDlgItem( m_hWnd, IDC_NCT_EDIT ) );
	::SetFocus( m_hWnd );
}

DLGCMD	CChatDlg::OnOK( DLGCMDPARAM )
{
//	DEBUGOUT( "CChatDlg::OnOK\n" );
	SetEditText();
}

DLGCMD	CChatDlg::OnCancel( DLGCMDPARAM )
{
//	DEBUGOUT( "CChatDlg::OnCancel\n" );
	::ShowWindow( m_hWnd, SW_HIDE ); // 旕昞帵偵偡傞偩偗
}

DLGCMD	CChatDlg::OnSend( DLGCMDPARAM )
{
//	DEBUGOUT( "CChatDlg::OnSend\n" );
	SetEditText();

	::SetFocus( ::GetDlgItem( m_hWnd, IDC_NCT_EDIT ) );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -