Microsoft Visual Studio Projects DISCUSSION

How can I make a delay in Visual Studio 2010

Started by syedzainnasir How can I make a delay in Visual Studio 2010
1 replies 248 views 2 participants
Latest activity · 20 Feb 2017

How can I make a delay in Visual Studio 2010

syedzainnasir Microsoft Visual Studio Projects Forum
#1
Hi all,



I need to know how can I make a delay of ~1msec in that platform.

beside the Order sleep() that gives me delay in seconds.



Thanks,

Community replies 1

Re: How can I make a delay in Visual Studio 2010

#2
[quote=Anita post_id=69 time=1487584009 user_id=70] Hi all,



I need to know how can I make a delay of ~1msec in that platform.

beside the Order sleep() that gives me delay in seconds.



Thanks, [/quote]
If you are building a console application then include windows header file and use sleep() function. Here is an example,
[code]// header files here #include <windows.h> int _tmain(int argc, _TCHAR* argv[]) { // code Sleep(1); return 0; }[/code]

If you are using Windows Application then follow this:

1. Define a timer ID on top of your cpp file
[code]#define MY_TIMER_ID (WM_USER + 200)[/code]

2. Declare a timer variable inside your class definition in header file
[code]class MainDlg : public CDialogEx { // defs UINT_PTR m_MyTimer; }[/code]

3. Implement your timer function,
[code]void MainDlg::OnTimer(UINT_PTR nIDEvent) { // use nIDEvent to detect if you have multiple timers // your code CDialogEx::OnTimer(nIDEvent); }[/code] 4. Start your timer for example in OnInitDialog() [code]BOOL MainDlg::OnInitDialog() { CDialogEx::OnInitDialog(); // Code m_MyTimer = SetTimer(MY_TIMER_ID, 1, NULL); }[/code] 5. Kill your timer when you are done. Example follows, [code]void MainDlg::OnClose( ) { // Code if (!KillTimer (m_MyTimer)) MessageBox(_T("Could not kill timer!")); CDialogEx::OnClose(); }[/code] Read More: [url=http://www.theengineeringprojects.com/2013/10/how-to-add-delay-in-microsoft-visual.html]HOW TO ADD A DELAY IN VISUAL STUDIO 2010[/url]
TEP COMMUNITY