
HACCEL hAccelTable;
hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WIN32));
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msghwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
还要建立加速键表资源和相应项,指向菜单,或自定义的ID,
在wm_command或wm_syscommand中处理,和菜单类似
你可以建立默认的win32工程试试,或者是helloworld的win32工程,vs的几个版本应该差的不太多,里面应该含有例子
就在OnPaint函数中画就行了,它的客户区是整个对话框(除标题栏、菜单栏与边界栏),它的CDC使用GetDC()就行了。
例如:
void CTstDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dcGetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rectWidth() - cxIcon + 1) / 2;
int y = (rectHeight() - cyIcon + 1) / 2;
// Draw the icon
dcDrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
// 这里是画图或输出
CDC pDC=GetDC();
pDC->TextOut(10,150,"Hello");
ReleaseDC(pDC);
}
}
使用 WM_GETTEXT 消息是可以做到的:
TCHAR buf[1024];
SendMessage(hwndEdit, WM_GETTEXT, sizeof(buf)/sizeof(TCHAR), (LPARAM)(void)buf);
hwndEdit 是你要获取的 edit 的句柄。buf 包含了你所需要的字符串。
GetCursorPos不管鼠标在哪里都可以获取位置的
问题是
只有OnMouseMove的时候才获取鼠标位置
但是OnMouseMove又是你对话框的成员函数
所以说
只有鼠标在对话框内移动才会显示坐标的
但是并不是没办法实现的
首先
你可以在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;
strAboutMenuLoadString(IDS_ABOUTBOX);
if
(!strAboutMenuIsEmpty())
{
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
SetTimer(1,100,NULL);//时间设置短一点
显示的也快点
return
TRUE;
//
return
TRUE
unless
you
set
the
focus
to
a
control
然后为对话框添加WM_TIME消息
void
CAdcDlg::OnTimer(UINT
nIDEvent)
{
//
TODO:
Add
your
message
handler
code
here
and/or
call
default
POINT
pos;
GetCursorPos(&pos);
//取鼠标的坐标
CString
str;
strFormat("%d,%d",posx,posy);
m_dd=str;
UpdateData(FALSE);
CDialog::OnTimer(nIDEvent);
}
m_dd为绑定在一个静态label空间上的CString
试试吧
这样就可以获得鼠标在任何时候的坐标了
以上就是关于C++获取光标所在位置的句柄,并向光标处发送数据,用PostMessage(),要详细代码。全部的内容,包括:C++获取光标所在位置的句柄,并向光标处发送数据,用PostMessage(),要详细代码。、cwindows应用程序的唯一入口点是、一个简单的win32窗口程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)