- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
背景
MFC CWnd::SetTimer
调用 WinAPI 的 SetTimer
简单地。
_AFXWIN_INLINE UINT_PTR CWnd::SetTimer(UINT_PTR nIDEvent, UINT nElapse,
void (CALLBACK* lpfnTimer)(HWND, UINT, UINT_PTR, DWORD))
{ ASSERT(::IsWindow(m_hWnd)); return ::SetTimer(m_hWnd, nIDEvent, nElapse,
lpfnTimer); }
nIDEvent
范围
SetTimer
:
If the hWnd parameter is not NULL and the window specified by hWnd already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer. When SetTimer replaces a timer, the timer is reset.
CWnd::SetTimer
:
Specifies a nonzero timer identifier. If the timer identifier is unique, this same value is returned bySetTimer
. Otherwise,SetTimer
determines a new unique value and returns that. For a window timer (which has a NULL callback function), the value must be unique only for other windows timers that are associated with the current window. For a callback timer, the value must be unique for all timers in all processes. Therefore, when you create a callback timer, it is more likely that the returned value might differ from the value you specify.
SetTimer
不依赖于回调参数,总是替换现有的计时器。但是
CWnd::SetTimer
取决于回调参数,如果指定了回调,可能会生成一个新的定时器 ID,因为
对于所有进程中的所有计时器,该值必须是唯一的 .
SetTimer
:
If the function succeeds and the hWnd parameter is not NULL, then the return value is a nonzero integer. An application can pass the value of the nIDEvent parameter to the KillTimer function to destroy the timer.
CWnd::SetTimer
:
The timer identifier of the new timer if the function is successful. This value may or may not be equal to the value passed in through thenIDEvent
parameter. An application should always pass the return value to the KillTimer member function to kill the timer.
SetTimer
不生成新的定时器 id 并且不返回定时器 id,因此调用
KillTimer
与
nIDEvent
范围。但是
CWnd::SetTimer
在某些情况下会生成新的计时器 ID,因此请调用
KillTimer
与返回值。
SetTimer
带有回调,它适用于我的电脑。但是如果某些平台不替换现有的计时器,我无法接受回调计时器。
最佳答案
据我所知,MFC 文档不正确。我已经进行了广泛的测试,只要窗口相同,计时器总是会替换以前的计时器。有回调和没有回调都是如此。
通过回调,我运行了以下测试:
static void CALLBACK MyTimerProc(HWND hWnd, UINT nMsg, UINT_PTR nIDEvent, DWORD dwTime) {
KillTimer(hWnd, nIDEvent);
}
...
timerID = SetTimer(2, 1000, MyTimerProc);
timerID = SetTimer(2, 1100, MyTimerProc);
timerID = SetTimer(4, 1200, MyTimerProc);
timerID = GetParentFrame()->SetTimer(4, 1300, MyTimerProc);
timerID=2
timerID=2
timerID=4
timerID=4
nIDEvent=2, hWnd=0x00000000002d0bb8
nIDEvent=4, hWnd=0x00000000002d0bb8
nIDEvent=4, hWnd=0x0000000000140bd0
关于winapi - SetTimer 与 CWnd::SetTimer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51010727/
根据 msdn ,当我用 CWnd::FromHandle 得到 CWnd* 时, The pointer may be temporary and should not be stored for
我在一个高度多线程的应用程序上遇到了无数次崩溃。 阅读这些 MSDN page , technical note和 this article on TLS ,我已经了解 CWnd 对象被映射到 Thr
我有一个动态创建的 CWnd 窗口,标题栏区域和任务栏的图标似乎是随机选择的。 要设置图标,我调用: // Set the icon for this dialog. The framework d
我的应用程序具有基于 ATL 的 GUI(CWnd、CDialog、...),它由多个页面(CDialog)组成。其中一个页面是空的,但它有一个占位符框架 (CWnd),可随对话框调整大小。一切都构建
H, 我有一个旧的 MFC 应用程序,它有一个继承自 CWnd 的类。我正在与原作者交谈,他说 Cwnd::Create() 创建了一个新线程。但是,我在 MSDN 文档中找不到对此的任何引用 htt
我正在尝试调用 CWnd 类的函数 GetParent()。每次都会抛出异常。我正在从工作线程调用该函数。 这是导致异常的行:CWnd* parent = this->GetParent(); 我也试
我有一个显示图像的自定义控件。当图像超过可显示大小时,它会显示滚动条。出于某种原因,我想知道是否显示水平或垂直滚动条。我在 CWnd 类中找不到任何直接函数。 我找到了 GetScrollBarI
我编写了一个 MFC 应用程序,需要一个不会将输入焦点从另一个窗口移开的按钮。 不幸的是,当用户用鼠标单击按钮时,删除 WS_TABSTOP 样式没有帮助。当我阻止 WM_LBUTTONDOWN 时,
我目前大量使用这样的代码来确定控件在窗口客户区内的位置: CRect rect; GetDlgItem(IDC_CONTROL_ID)->GetWindowRect(&rect); ScreenToC
如何获取 CWnd* 的高度和宽度? CWnd 窗口是否正确?为什么不是命令: CWnd* parent = this->GetParent(); // C++ command parent->Get
背景 MFC CWnd::SetTimer调用 WinAPI 的 SetTimer简单地。 _AFXWIN_INLINE UINT_PTR CWnd::SetTimer(UINT_PTR nIDEve
我有一个 CWnd 类名 mywindow 的成员 我想给它添加一个滚动条。 我该怎么做? 我已经尝试做: mywindow.EnableScrollBarCtrl(SB_BOTH,TRUE); 它显
我有一个对话框,CFormView,其中包含一些按钮和一个面板,其中包含 Tabcontrol、单选按钮、文本输入字段等。 因此,在我的面板 CWnd 上,我创建了如下输入字段: pEdit = ne
(最后一行有一个 TL;DR) 我正在实现一个处理程序来关闭在软件应用程序中打开的选定窗口。这是一个粗略的代码: void CDlg_Dummy_Dialog::OnCloseWindows() {
我正在编写一个带有多个控件的 MFC 对话框。我目前有一个 CWnd,它位于 dialog 的右半部分。单击编辑按钮后,子 CWnd 会调整大小以占据对话框的较大部分。 但是,现在当我尝试调整窗口大小
如果我有一个带有按钮控件的 MFC 对话框,有没有办法使用按钮的 ID(例如 IDC_BUTTON_YES)为该控件构造 HWND 或 CWND? 最佳答案 是的,可以使用MFC对话框的GetDlgI
所以我有一个 MFC 应用程序,当我们执行某些操作时它会闪烁。所以我想我应该设置 SetRedraw(false) 并在函数结束时将其设置为 true。 该应用程序不再刷新,但如果我在 SetRedr
我是一个 C++ 新手,所以请多多包涵。 位于函数内的这行代码: CWnd* pWnd = CWnd::FindWindow("Shell_TrayWnd", ""); CWnd 显示为“未定义”。我
我正在处理我们的 32 位 MFC VC2010 应用程序中出现的偶发生产问题。该应用程序在 Windows Server 2008 R2 Standard SP1 64 位上运行。 此问题是由于无法
我有一个派生自 CWnd 的自定义类,我想从工作线程向其发布消息。我正在使用 PostMessage 函数来实现这一点。 PostMessage 的第一个参数是我的类的 HWND 类型句柄,接下来是我
我是一名优秀的程序员,十分优秀!