VC中让软件发出Beep声,用Beep函数,另需添加头文件, #include <windows.h>,例如,Beep(1000,500);


Syntax


C++





BOOL WINAPI Beep( _In_  DWORD dwFreq, _In_  DWORD dwDuration );


Parameters


dwFreq [in]


The frequency of the sound, in hertz. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF).

dwDuration [in]


The duration of the sound, in milliseconds.



延迟函数如下,

int sTime, eTime;
sTime = ::GetTickCount();
eTime = ::GetTickCount();
while (eTime - sTime < 500)
{
MSG msg;
GetMessage(&msg, NULL, 0, 0);
TranslateMessage(&msg);
DispatchMessage(&msg);
eTime = ::GetTickCount();
}


 使用Sleep函数,或者使用循环来导致延迟,会出现窗口死的情况,用以上函数则没有,或者使用Timer和线程也可以。



HWND mHwnd = ::FindWindow(NULL,"dlgok");//通过windowname得到该窗体的句柄
DlgOk* mDlgok= (DlgOk*)CWnd::FromHandle(mHwnd ); //有该句柄得到对话框类的指针
int ntemp= mDlgok->m_temp; //访问其中的变量