键盘消息

这篇博客详细探讨了Windows编程中与键盘消息相关的函数,包括如何创建、设置、显示和隐藏插入符号,以及处理窗口滚动、文本输出等操作。涉及到的关键函数有:LoadStandardCursor、AfxRegisterWndClass、CreateEx、SetBkColor、TabbedTextOutW、ExtTextOut、ScrollWindow、ValidateRect、GetTextExtent等。通过实例代码展示了这些函数的具体应用。
摘要由CSDN通过智能技术生成

键盘消息

  1. 涉及函数
  • AfxGetApp()->LoadStandardCursor(IDC_ARROW)
  • AfxRegisterWndClass //注册窗口类
  • CreateEx //创建窗口
  • pDC->SetBkColor((COLORREF)::GetSysColor(COLOR_3DFACE));//设置背景颜色
  • TabbedTextOutW//对齐输出文本
  • ExtTextOut //调用此成员函数,以使用当前选中的字体在矩形区域内写入字符串。
  • ScrollWindow//ScrollWindow函数滚动指定窗口的客户区域的内容。
  • ValidateRect //使矩形保持有效模式,来拒绝OnPaint消息重绘窗口
  • GetTextExtent //调用此成员函数来计算使用当前字体确定大小的文本行的宽度和高度。
  • SetRect//将CRect的维度设置为指定的坐标
  • InflateRect//InflateRect将CRect的边从其中心移开,从而使其膨胀。
  • CalcWindowRect//调用此成员函数,根据所需的客户端矩形大小计算窗口矩形的所需大小。
  • SetWindowPos//调用此成员函数来更改子窗口、弹出窗口和顶级窗口的大小、位置和z顺序
  • DrawEdge//调用此成员函数来绘制指定类型和样式的矩形的边缘
  • GetMessagePos//确定光标的当前位置,请使用GetCursorPos函数。The return value specifies the x- and y-coordinates of the cursor position. The x-coordinate is the low order short and the y-coordinate is the high-order short.
  • ScreenToClient//Converts screen coordinates to client coordinates.
  • PtInRect//确定指定点是否位于CRect内。
  • CreateSolidCaret//为系统插入符号创建一个实线矩形,并声明插入符号的所有权。
  • DestroyCaret//DestroyCaret函数销毁插入符号的当前形状,将插入符号从窗口释放,并从屏幕上删除插入符号。
  • GetSystemMetrics//Retrieves the specified system metric or system configuration setting.
    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-umjQUAc7-1590070621220)(https://raw.githubusercontent.com/konalo-X/pic/master/20200521221408.png)]
  • ShowCaret//ShowCaret函数使插入符号在屏幕上的当前位置可见。当插入符号变得可见时,它开始自动闪烁。
  • HideCaret//HideCaret函数从屏幕上删除插入符号。隐藏插入符号不会破坏其当前形状或使插入点无效。
  • SetCaretPos//SetCaretPos函数将插入符号移动到指定的坐标。如果拥有插入符号的窗口是用CS_OWNDC类样式创建的,那么指定的坐标取决于与该窗口关联的设备上下文的映射模式
  • GetCaretPos//GetCaretPos函数将插入符号的位置复制到指定的点结构中。
  1. 函数原型

//The pointer returned by this function can be used to access application information such as the main message-dispatch code or the topmost window. 
CWinApp* AFXAPI AfxGetApp( ); 

//Allows you to register your own window classes. 
LPCTSTR AFXAPI AfxRegisterWndClass(
   UINT nClassStyle,
   HCURSOR hCursor = 0,
   HBRUSH hbrBackground = 0,
   HICON hIcon = 0 
);

//Creates an overlapped, pop-up, or child window with the extended style specified in dwExStyle. 
virtual BOOL CreateEx(
   DWORD dwExStyle,
   LPCTSTR lpszClassName,
   LPCTSTR lpszWindowName,
   DWORD dwStyle,
   int x,
   int y,
   int nWidth,
   int nHeight,
   HWND hWndParent,
   HMENU nIDorHMenu,
   LPVOID lpParam = NULL 
);
virtual BOOL CreateEx(
   DWORD dwExStyle,
   LPCTSTR lpszClassName,
   LPCTSTR lpszWindowName,
   DWORD dwStyle,
   const RECT& rect,
   CWnd* pParentWnd,
   UINT nID,
   LPVOID lpParam = NULL
);

//Sets the current background color to the specified color. 
virtual COLORREF SetBkColor(
   COLORREF crColor 
);

//Retrieves the current color of the specified display element. Display elements are the parts of a window and the display that appear on the system display screen.
DWORD WINAPI GetSysColor(
  __in  int nIndex
);

//Call this member function to write a character string at the specified location, expanding tabs to the values specified in the array of tab-stop positions. 
virtual CSize TabbedTextOut(
   int x,
   int y,
   LPCTSTR lpszString,
   int nCount,
   int nTabPositions,
   LPINT lpnTabStopPositions,
   int nTabOrigin 
);
CSize TabbedTextOut(
   int x,
   int y,
   const CString& str,
   int nTabPositions,
   LPINT lpnTabStopPositions,
   int nTabOrigin 
);


//调用此成员函数,以使用当前选中的字体在矩形区域内写入字符串。
virtual BOOL ExtTextOut(
   int x,
   int y,
   UINT nOptions,
   LPCRECT lpRect,
   LPCTSTR lpszString,
   UINT nCount,
   LPINT lpDxWidths 
);
BOOL ExtTextOut(
   int x,
   int y,
   UINT nOptions,
   LPCRECT lpRect,
   const CString& str,
   LPINT lpDxWidths 
);

//Allows a windowless OLE object to scroll an area within its in-place active image on the screen. 
void ScrollWindow(
   int xAmount,
      int yAmount,
      LPCRECT lpRect = NULL,
      LPCRECT lpClipRect = NULL 
);

//Validates the client area within the given rectangle by removing the rectangle from the update region of the window. 
void ValidateRect(
   LPCRECT lpRect 
);

//Call this member function to compute the width and height of a line of text using the current font to determine the dimensions.
CSize GetTextExtent(
   LPCTSTR lpszString,
   int nCount 
) const;
CSize GetTextExtent(
   const CString& str 
) const

//Sets the dimensions of CRect to the specified coordinates. 
void SetRect( 
   int x1, 
   int y1, 
   int x2, 
   int y2  
) throw

//InflateRect inflates CRect by moving its sides away from its center. 
void InflateRect( 
   int x, 
   int y  
) throw( );
void InflateRect( 
   SIZE size  
) throw( );
void InflateRect( 
   LPCRECT lpRect  
) throw( );
void InflateRect( 
   int l, 
   int t, 
   int r, 
   int b  
) throw( );


//Call this member function to compute the required size of the window rectangle based on the desired client-rectangle size. 
virtual void CalcWindowRect(
   LPRECT lpClientRect,
      UINT nAdjustType = adjustBorder 
);


//Call this member function to change the size, position, and Z-order of chi
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值