// VC6DemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "VC6Demo.h"
#include "VC6DemoDlg.h"
#include "GetWordInterface.h"
#include "OnlineTranslate.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//#define MAX_OUTPUT_LEN 4096 // the max length of the point-capturing output string
//#define MAX_RECT_OUTPUT_LEN 81920 // the max length of the rectangle-capturing output string
//#define MOUSEHOOK_CAPTURE_OK_MSG _T("MOUSEHOOK_CAPTUREOK_MSG-")##LICENSEID
//#define HIGHLIGHT_CAPTURE_OK_MSG _T("HIGHLIGHT_CAPTUREOK_MSG_XUFU_V1-")##LICENSEID
//#define HOTKEY_CAPTURE 1000 // the hotkey message
#define ID_HOTKEY 1002 // Enable highlighted capture
//UINT MOUSEHOOK_CAPTURE_OK = 0;
//UINT HIGHLIGHT_CAPTURE_OK = 0;
//#define TYPE_PROCESS 0x00000000
//#define TYPE_WND 0x10000000
//#define TYPE_MOUSE 0x20000000
//#define TYPE_KEYBOARD 0x30000000
//#define TYPE_ACTIVATE 0x40000000
#define UM_TRANSLATE (WM_USER+0x10)
#define WM_POST_INIT (WM_USER+0x11)
#define WM_MOUSEMOVE_EX (WM_USER+0x12)
#define BKG_COLOR RGB(249, 249, 249)
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
CRITICAL_SECTION spinlock = {0};
CVC6DemoDlg* maindlg = 0;
/////////////////////////////////////////////////////////////////////////////
// CVC6DemoDlg dialog
CVC6DemoDlg::CVC6DemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CVC6DemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CVC6DemoDlg)
//m_bEnableMouseCap = FALSE;
m_bEnableHighlight = FALSE;
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_uCheckTimerID = 1;
textEmpty = 1;
hasTitle = 1;
minimized = 1;
// hook相关 用于判定鼠标位置
maindlg = this;
InitializeCriticalSection(&spinlock);
m_brush.CreateSolidBrush( BKG_COLOR ); // 背景色
m_brushBorder.CreateSolidBrush( RGB(100,200,200) );
font = new CFont;
font->CreateFont(16,8,0,0,0,0,0,0,DEFAULT_CHARSET,0,0,0,0,0);
}
void CVC6DemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CVC6DemoDlg)
DDX_Check(pDX, IDC_CHECK_HIGHLIGHT, m_bEnableHighlight);
DDX_Control(pDX, IDC_EDIT_HIGHLIGHT, m_editHighlight);
DDX_Control(pDX, IDC_EDIT_RECT, m_editRect);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_CHECK_CLEAR, m_chkClear);
DDX_Control(pDX, IDC_COMBO1, dstCode);
}
BEGIN_MESSAGE_MAP(CVC6DemoDlg, CDialog)
//{{AFX_MSG_MAP(CVC6DemoDlg)
ON_WM_CREATE()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
ON_WM_CLOSE()
ON_WM_SIZE()
ON_WM_CTLCOLOR()
ON_WM_HOTKEY()
ON_BN_CLICKED(IDC_CHECK_HIGHLIGHT, OnCheckHighlight)
//}}AFX_MSG_MAP
//user defined
ON_MESSAGE(UM_TRANSLATE, OnTranslate)
ON_MESSAGE(WM_MOUSEMOVE_EX, OnMouseMoveEx)
ON_EN_CHANGE(IDC_EDIT_HIGHLIGHT, &CVC6DemoDlg::OnEnChangeEditHighlight)
ON_BN_CLICKED(IDC_CHECK_CLEAR, &CVC6DemoDlg::OnBnClickedCheckClear)
ON_CBN_SELCHANGE(IDC_COMBO1, &CVC6DemoDlg::OnCbnSelchangeLangCode)
ON_CBN_EDITCHANGE(IDC_COMBO1, &CVC6DemoDlg::OnCbnEditchangeLangCode)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVC6DemoDlg message handlers
const wchar_t* langCode[] = // 目标语言代码
{L"auto",L"zh",L"jp",L"spa",L"th",L"ru",L"yue",L"zh",L"de",L"nl",L"en",L"kor",L"fra",L"ara",L"pt",L"wyw",L"it",L"el",};
HRESULT WINAPI NotifyCallBackC (long wParam, long lParam)
{
//wParam lParam 永远是1,0 没用
maindlg->CaptureTextStub(wParam, lParam);
return 0;
}
HRESULT WINAPI NotifyCallBackH (long wParam, long lParam)
{
// not capture self
if (maindlg->IsSelfSubWin((HWND)lParam) ) {return 1;}
maindlg->CaptureHighlightTextStub(wParam, lParam);
return 0;
}
BOOL CVC6DemoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetWindowText(VC6DEMO_TITLE);
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
dstCode.SetCurSel(0);
GetClientRect(&m_clRect);
// set the window to the topmost
//CRect rect;
//GetWindowRect(&rect);
//height = rect.Height();
//width = rect.Width();
m_editHighlight.SetFont(font);
m_editRect.SetFont(font);
//nRight = GetSystemMetrics(SM_CXFULLSCREEN ); //SM_CXSCREEN
//nBottom = GetSystemMetrics(SM_CYFULLSCREEN );
//nCapHeight = GetSystemMetrics(SM_CYCAPTION);
hCheckHighlight = GetDlgItem(IDC_CHECK_HIGHLIGHT)->GetSafeHwnd();
hCheckClear = GetDlgItem(IDC_CHECK_CLEAR)->GetSafeHwnd();
SetWindowPos( &wndTopMost,
nRight-width,
nBottom-height+nCapHeight,
0,0, SWP_NOSIZE|SWP_SHOWWINDOW);
SetCaptureReadyCallback( NotifyCallBackC );
SetHighlightReadyCallback( NotifyCallBackH );
::RegisterHotKey(GetSafeHwnd(),ID_HOTKEY, MOD_CONTROL, VK_F9);
m_editHighlight.SetFocus();
return 0; // return TRUE unless you set the focus to a control
}
void CVC6DemoDlg::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();
}
}
HCURSOR CVC6DemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CVC6DemoDlg::OnDestroy()
{
// remove the global mouse hook
RemoveHighlightReadyCallback( NotifyCallBackH );
RemoveCaptureReadyCallback( NotifyCallBackC );
CDialog::OnDestroy();
}
void CVC6DemoDlg::OnCheckHighlight()
{
UpdateData(TRUE);
EnableHighlightCapture( m_bEnableHighlight );
EnableCursorCapture( m_bEnableHighlight );
}
void CVC6DemoDlg::CaptureTextStub(WPARAM wParam, LPARAM lParam)
{
// get the window handle at the cursor point
POINT ptCursor;
::GetCursorPos(&ptCursor);
CRect rect;
GetWindowRect(&rect);
// Self
if ( rect.PtInRect(ptCursor) ) {return ;}
// nCursorPos is the zero-based index in the string bstr
// if the cursor is not in the string bstr, nCursorPos is -1
long nCursorPos = -1;
BOOL bOK = FALSE;
BSTR wstrOut;
bOK = GetString(ptCursor.x, ptCursor.y, &wstrOut, &nCursorPos);
if (bOK) // successfully get the words
{
CString strTotal(wstrOut);
FreeString(&wstrOut);
if (!strTotal.IsEmpty())
{
if ( textEmpty)
{
m_editHighlight.SetEmpty(0);
m_editHighlight.SetWindowText(strTotal);
BeginTranslate(strTotal);
}
}
}
}
bool CVC6DemoDlg::IsSelfSubWin(HWND hwnd)
{
return
hwnd== m_hWnd
||hwnd == m_editHighlight.m_hWnd
||hwnd == m_editRect.m_hWnd
||hwnd == hCheckClear
||hwnd == hCheckHighlight;
}
void CVC6DemoDlg::CaptureHighlightTextStub(WPARAM wParam, LPARAM lParam)
{
CString strText;
POINT ptCursor;
::GetCursorPos(&ptCursor);
BOOL bOK = FALSE;
BSTR bstr = NULL;
bOK = GetHighlightText2(ptCursor.x, ptCursor.y, &bstr);
if (bOK)
{
strText = bstr;
FreeString(&bstr);
}
if (strText.IsEmpty())
{
//textEmpty = 1;
} else {
textEmpty = 0;
m_editHighlight.SetEmpty(0);
m_editHighlight.SetWindowTextW(strText);
BeginTranslate(strText);
}
}
afx_msg LRESULT CVC6DemoDlg::OnTranslate(WPARAM wParam, LPARAM lParam)
{
TranslationInfo * info = (TranslationInfo*)lParam;
if (m_curInfo == info)
{
m_editRect.SetWindowText(info->dst);
}
delete (TranslationInfo*)lParam;
return 0;
}
int CVC6DemoDlg::BeginTranslate(const CString& strText)
{
if (strText.IsEmpty()) { m_curInfo = 0; return 0;}
int index = dstCode.GetCurSel();
if (index < 0) {index=0;} // 未选中 置为auto
TranslationInfo *info = new TranslationInfo;
info->hwnd = GetSafeHwnd();
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
src.rar (50个子文件)
src
OnlineTranslate.h 286B
VC6Demo.cpp 3KB
VC6DemoDlg.h 3KB
VC6Demo.suo 107KB
VC6Demo.rc 5KB
GetWordInterface.h 2KB
Release
VC6Demo.sbr 0B
StdAfx.obj 4.21MB
VC6Demo.res 259KB
SkinEdit.sbr 0B
OnlineTranslate.obj 473KB
VC6Demo.pch 29.19MB
VC6DemoDlg.sbr 0B
BuildLog.htm 15KB
GetWordInterface2.obj 27KB
GetWordInterface2.sbr 0B
vc90.idb 547KB
mt.dep 65B
SkinEdit.obj 48KB
MyEdit.sbr 0B
OnlineTranslate.sbr 0B
StdAfx.sbr 3.35MB
VC6Demo.obj 55KB
VC6DemoDlg.obj 111KB
MyEdit.obj 71KB
ScreenTranslate.exe.intermediate.manifest 381B
res
VC6Demo.rc2 399B
dictionary.ico 66KB
book_dictionary.bmp 179KB
VC6Demo.dsp 6KB
VC6Demo.vcproj 15KB
VC6Demo.h 1KB
SkinEdit.cpp 2KB
VC6Demo.aps 281KB
VC6Demo.vcproj.TK-BEAR.Bear.user 3KB
VC6Demo.mak 7KB
GetWordInterface2.cpp 2KB
VC6Demo.sln 1KB
VC6Demo.clw 2KB
MyEdit.cpp 2KB
StdAfx.cpp 207B
VC6Demo.dep 986B
resource.h 953B
VC6Demo.dsw 537B
VC6Demo.ncb 12.8MB
StdAfx.h 1KB
VC6DemoDlg.cpp 14KB
MyEdit.h 820B
SkinEdit.h 804B
OnlineTranslate.cpp 5KB
共 50 条
- 1
资源评论
- wangjun8252016-06-29编译不了,如何调用GetWord4.3的?
- 无情剑11112017-11-09我为啥里面没内容
- jk3d200120012017-06-13只能说作为参考用一下
- 一杯咖啡不加糖2018-01-30启动会崩溃,而且会很卡,都没办法调试。只能参考下部分代码
- 3860029722017-11-01很好,可以参考.
tiankong_bear
- 粉丝: 31
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功