一个关于“一次只能启动一个实例”程序的问题
rengo 2002-08-04 10:24:54 我找到一个一次只能启动一个程序实例的源代码,下面是它里面的一个函数,用来判断自己的程序是否已经启动了,我弄不明白FindWindow(_T("#32770"),"Instance")里面的_T("#32770")是哪里来的,按道理_T("#32770")是表示window class name,可是该程序的作者是怎么知道自己窗口的class name呢?(这个程序只有一个Dialog窗口),我把_T("#32770")随便改成其他数字,发现不行,希望大家帮帮忙,谢谢了?还有,要怎么知道自己窗口的class name呢?
BOOL CInstanceApp::FirstInstance()
{
CWnd *pWndPrev , *pWndChild;
// Determine if another window with our class name and Window title exists...
// The title "Instance " is set up latter, in the InitDialog function.
if (pWndPrev = CWnd::FindWindow(_T("#32770"),"Instance"))//
{
pWndChild = pWndPrev->GetLastActivePopup(); // if so, does it have any popups?
if (pWndPrev->IsIconic())
pWndPrev->ShowWindow(SW_RESTORE); // If iconic, restore the main window
pWndChild->SetForegroundWindow(); // Bring the main window or it's popup to
// the foreground
// and we are done activating the previous one.
return FALSE;
}
else
return TRUE; // First instance. Proceed as normal.
}
还有其他“一次只能启动一个实例”的方法吗