#include <afxwin.h>
#include "VisualKB.h"
CMyApp myApp;
/////////////////////////////////////////////////////////////////////////
// CMyApp member functions
BOOL CMyApp::InitInstance ()
{
m_pMainWnd = new CMainWindow;
m_pMainWnd->ShowWindow (m_nCmdShow);
m_pMainWnd->UpdateWindow ();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////
// CMainWindow message map and member functions
BEGIN_MESSAGE_MAP (CMainWindow, CWnd)
ON_WM_CREATE ()
ON_WM_PAINT ()
ON_WM_SETFOCUS ()
ON_WM_KILLFOCUS ()
ON_WM_SETCURSOR ()
ON_WM_LBUTTONDOWN ()
ON_WM_KEYDOWN ()
ON_WM_KEYUP ()
ON_WM_SYSKEYDOWN ()
ON_WM_SYSKEYUP ()
ON_WM_CHAR ()
ON_WM_SYSCHAR ()
END_MESSAGE_MAP ()
CMainWindow::CMainWindow ()
{
m_nTextPos = 0;
m_nMsgPos = 0;
//
// Load the arrow cursor and the I-beam cursor and save their handles.
//
m_hCursorArrow = AfxGetApp ()->LoadStandardCursor (IDC_ARROW);
m_hCursorIBeam = AfxGetApp ()->LoadStandardCursor (IDC_IBEAM);
//
// Register a WNDCLASS.
//
CString strWndClass = AfxRegisterWndClass (
0,
NULL,
(HBRUSH) (COLOR_3DFACE + 1),
AfxGetApp ()->LoadStandardIcon (IDI_WINLOGO)
);
//
// Create a window.
//
CreateEx (0, strWndClass, _T ("Visual Keyboard"),
WS_OVERLAPPED | WS_SYSMENU | WS_CAPTION | WS_MINIMIZEBOX,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL);
}
int CMainWindow::OnCreate (LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate (lpCreateStruct) == -1)
return -1;
//
// Initialize member variables whose values are dependent upon screen
// metrics.
//
CClientDC dc (this);
TEXTMETRIC tm;
dc.GetTextMetrics (&tm);
m_cxChar = tm.tmAveCharWidth;
m_cyChar = tm.tmHeight;
m_cyLine = tm.tmHeight + tm.tmExternalLeading;
m_rcTextBoxBorder.SetRect (16, 16, (m_cxChar * 64) + 16,
((m_cyChar * 3) / 2) + 16);
m_rcTextBox = m_rcTextBoxBorder;
m_rcTextBox.InflateRect (-2, -2);
m_rcMsgBoxBorder.SetRect (16, (m_cyChar * 4) + 16,
(m_cxChar * 64) + 16, (m_cyLine * MAX_STRINGS) +
(m_cyChar * 6) + 16);
m_rcScroll.SetRect (m_cxChar + 16, (m_cyChar * 6) + 16,
(m_cxChar * 63) + 16, (m_cyLine * MAX_STRINGS) +
(m_cyChar * 5) + 16);
m_ptTextOrigin.x = m_cxChar + 16;
m_ptTextOrigin.y = (m_cyChar / 4) + 16;
m_ptCaretPos = m_ptTextOrigin;
m_nTextLimit = (m_cxChar * 63) + 16;
m_ptHeaderOrigin.x = m_cxChar + 16;
m_ptHeaderOrigin.y = (m_cyChar * 3) + 16;
m_ptUpperMsgOrigin.x = m_cxChar + 16;
m_ptUpperMsgOrigin.y = (m_cyChar * 5) + 16;
m_ptLowerMsgOrigin.x = m_cxChar + 16;
m_ptLowerMsgOrigin.y = (m_cyChar * 5) +
(m_cyLine * (MAX_STRINGS - 1)) + 16;
m_nTabStops[0] = (m_cxChar * 24) + 16;
m_nTabStops[1] = (m_cxChar * 30) + 16;
m_nTabStops[2] = (m_cxChar * 36) + 16;
m_nTabStops[3] = (m_cxChar * 42) + 16;
m_nTabStops[4] = (m_cxChar * 46) + 16;
m_nTabStops[5] = (m_cxChar * 50) + 16;
m_nTabStops[6] = (m_cxChar * 54) + 16;
//
// Size the window.
//
CRect rect (0, 0, m_rcMsgBoxBorder.right + 16,
m_rcMsgBoxBorder.bottom + 16);
CalcWindowRect (&rect);
SetWindowPos (NULL, 0, 0, rect.Width (), rect.Height (),
SWP_NOZORDER | SWP_NOMOVE | SWP_NOREDRAW);
return 0;
}
void CMainWindow::PostNcDestroy ()
{
delete this;
}
void CMainWindow::OnPaint ()
{
CPaintDC dc (this);
//
// Draw the rectangles surrounding the text box and the message list.
//
dc.DrawEdge (m_rcTextBoxBorder, EDGE_SUNKEN, BF_RECT);
dc.DrawEdge (m_rcMsgBoxBorder, EDGE_SUNKEN, BF_RECT);
//
// Draw all the text that appears in the window.
//
DrawInputText (&dc);
DrawMessageHeader (&dc);
DrawMessages (&dc);
}
void CMainWindow::OnSetFocus (CWnd* pWnd)
{
//
// Show the caret when the VisualKB window receives the input focus.
//
CreateSolidCaret (max (2, ::GetSystemMetrics (SM_CXBORDER)),
m_cyChar);
SetCaretPos (m_ptCaretPos);
ShowCaret ();
}
void CMainWindow::OnKillFocus (CWnd* pWnd)
{
//
// Hide the caret when the VisualKB window loses the input focus.
//
HideCaret ();
m_ptCaretPos = GetCaretPos ();
::DestroyCaret ();
}
BOOL CMainWindow::OnSetCursor (CWnd* pWnd, UINT nHitTest, UINT message)
{
//
// Change the cursor to an I-beam if it's currently over the text box,
// or to an arrow if it's positioned anywhere else.
//
if (nHitTest == HTCLIENT) {
DWORD dwPos = ::GetMessagePos ();
CPoint point (LOWORD (dwPos), HIWORD (dwPos));
ScreenToClient (&point);
::SetCursor (m_rcTextBox.PtInRect (point) ?
m_hCursorIBeam : m_hCursorArrow);
return TRUE;
}
return CWnd::OnSetCursor (pWnd, nHitTest, message);
}
void CMainWindow::OnLButtonDown (UINT nFlags, CPoint point)
{
//
// Move the caret if the text box is clicked with the left mouse button.
//
if (m_rcTextBox.PtInRect (point)) {
m_nTextPos = GetNearestPos (point);
PositionCaret ();
}
}
void CMainWindow::OnKeyDown (UINT nChar, UINT nRepCnt, UINT nFlags)
{
ShowMessage (_T ("WM_KEYDOWN"), nChar, nRepCnt, nFlags);
//
// Move the caret when the left, right, Home, or End key is pressed.
//
switch (nChar) {
case VK_LEFT:
if (m_nTextPos != 0) {
m_nTextPos--;
PositionCaret ();
}
break;
case VK_RIGHT:
if (m_nTextPos != m_strInputText.GetLength ()) {
m_nTextPos++;
PositionCaret ();
}
break;
case VK_HOME:
m_nTextPos = 0;
PositionCaret ();
break;
case VK_END:
m_nTextPos = m_strInputText.GetLength ();
PositionCaret ();
break;
}
}
void CMainWindow::OnChar (UINT nChar, UINT nRepCnt, UINT nFlags)
{
ShowMessage (_T ("WM_CHAR"), nChar, nRepCnt, nFlags);
CClientDC dc (this);
//
// Determine which character was just input from the keyboard.
//
switch (nChar) {
case VK_ESCAPE:
case VK_RETURN:
m_strInputText.Empty ();
m_nTextPos = 0;
break;
case VK_BACK:
if (m_nTextPos != 0) {
m_strInputText = m_strInputText.Left (m_nTextPos - 1) +
m_strInputText.Right (m_strInputText.GetLength () -
m_nTextPos);
m_nTextPos--;
}
break;
default:
if ((nChar >= 0) && (nChar <= 31))
return;
if (m_nTextPos == m_strInputText.GetLength ()) {
m_strInputText += nChar;
m_nTextPos++;
}
else
m_strInputText.SetAt (m_nTextPos++, nChar);
CSize size = dc.GetTextExtent (m_strInputText,
m_strInputText.GetLength ());
if ((m_ptTextOrigin.x + size.cx) > m_nTextLimit) {
m_strInputText = nChar;
m_nTextPos = 1;
}
break;
}
//
// Update the contents of the text box.
//
HideCaret ();
DrawInputText (&dc);
PositionCaret (&dc);
ShowCaret ();
}
void CMainWindow::OnKeyUp (UINT nChar, UINT nRepCnt, UINT nFlags)
{
ShowMessage (_T ("WM_KEYUP"), nChar, nRepCnt, nFlags);
CWnd::OnKeyUp (nChar, nRepCnt, nFlags);
}
void CMainWindow::OnSysKeyDown (UINT nChar, UINT nRepCnt, UINT nFlags)
{
ShowMessage (_T ("WM_SYSKEYDOWN"), nChar, nRepCnt, nFlags);
CWnd::OnSysKeyDown (nChar, nRepCnt, nFlags);
}
void CMainWindow::OnSysChar (UINT nChar, UINT nRepCnt, UINT nFlags)
{
ShowMessage (_T ("WM_SYSCHAR"), nChar, nRepCnt, nFlags);
CWnd::OnSysChar (nChar, nRepCnt, nFlags);
没有合适的资源?快使用搜索试试~ 我知道了~
programming windows with MFC 2th code
共199个文件
h:56个
cpp:48个
exe:17个
需积分: 4 34 下载量 108 浏览量
2010-09-27
20:03:43
上传
评论 1
收藏 985KB RAR 举报
温馨提示
programming windows with MFC 2th code programming windows with MFC 2th code 1-8
资源推荐
资源详情
资源评论
收起资源包目录
programming windows with MFC 2th code (199个子文件)
Phones.aps 42KB
PropDemo.aps 40KB
DlgDemo2.aps 40KB
DlgDemo1.aps 40KB
Colors.aps 40KB
MyPad.aps 39KB
Shapes.aps 39KB
DlgCalc.aps 36KB
PropDemo.clw 3KB
Phones.clw 3KB
DlgDemo1.clw 2KB
DlgDemo2.clw 2KB
DlgCalc.clw 2KB
Colors.clw 2KB
MyPad.clw 2KB
Shapes.clw 1KB
VisualKB.cpp 12KB
DlgCalcDlg.cpp 9KB
Accel.cpp 7KB
TicTac.cpp 7KB
IconView.cpp 6KB
FontView.cpp 5KB
ChildView.cpp 5KB
ColorText.cpp 4KB
MainFrm.cpp 3KB
MouseCap.cpp 3KB
ChildView.cpp 3KB
ChildView.cpp 3KB
Colors.cpp 3KB
DlgDemo2.cpp 3KB
PropDemo.cpp 3KB
DlgDemo1.cpp 3KB
Phones.cpp 3KB
Shapes.cpp 3KB
MyPad.cpp 3KB
ChildView.cpp 3KB
ChildView.cpp 3KB
MainFrm.cpp 2KB
ChildView.cpp 2KB
MainFrm.cpp 2KB
MainFrm.cpp 2KB
MainFrm.cpp 2KB
MainFrm.cpp 2KB
MainFrm.cpp 2KB
ChildView.cpp 2KB
PhonesListBox.cpp 2KB
OptionsDialog.cpp 2KB
MyPropertySheet.cpp 2KB
Ruler.cpp 2KB
SizePage.cpp 1KB
EditDialog.cpp 1KB
ColorPage.cpp 1KB
OptionsDialog.cpp 1KB
DlgCalc.cpp 1005B
PhoneEdit.cpp 920B
Hello.cpp 843B
StdAfx.cpp 210B
StdAfx.cpp 210B
StdAfx.cpp 210B
StdAfx.cpp 209B
StdAfx.cpp 208B
StdAfx.cpp 208B
StdAfx.cpp 208B
StdAfx.cpp 207B
Phones.dsp 5KB
PropDemo.dsp 5KB
DlgDemo1.dsp 4KB
DlgDemo2.dsp 4KB
Colors.dsp 4KB
Shapes.dsp 4KB
MyPad.dsp 4KB
DlgCalc.dsp 4KB
ColorText.dsp 4KB
IconView.dsp 4KB
VisualKB.dsp 4KB
MouseCap.dsp 4KB
FontView.dsp 4KB
TicTac.dsp 4KB
Hello.dsp 4KB
Ruler.dsp 4KB
Accel.dsp 4KB
ColorText.dsw 541B
FontView.dsw 539B
VisualKB.dsw 539B
MouseCap.dsw 539B
IconView.dsw 539B
PropDemo.dsw 539B
DlgDemo1.dsw 539B
DlgDemo2.dsw 539B
DlgCalc.dsw 537B
TicTac.dsw 535B
Phones.dsw 535B
Colors.dsw 535B
Shapes.dsw 535B
MyPad.dsw 533B
Hello.dsw 533B
Ruler.dsw 533B
Accel.dsw 533B
Phones.exe 148KB
PropDemo.exe 128KB
共 199 条
- 1
- 2
资源评论
mymeng_feng
- 粉丝: 5
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于Python和Django的二手物品购物网站设计源码+数据库脚本.zip
- 基于pytorch实现的YOLOV5+SORT的车辆行人目标识别及追踪系统源码.zip
- 【计算机毕业设计】基于servlet+jdbc的在线选房系统设计与实现【源码+lw+部署文档+讲解】
- 投身科技创新,勇担时代先锋.pptx
- 【计算机毕业设计】基于SSM的仿微博系统的设计与实现【源码+lw+部署文档+讲解】
- 使用 Web Components 实现,遵循 Material You 设计规范的 Web 前端组件库
- 柴经理立柱右5.13.psd
- train.py
- 基于WinHex脚本技术的ExFAT校验扇区恢复研究.pdf
- 基于STM32F7系列串口数据加载方案的设计与实现.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功