本帖最后由 yangke1994 于 2009-07-28 22:45:32 编辑

解决方案 »

  1.   

    将工程的启动改为:Sub Main过程,在里面添加:运行时先判断是否已经运行该文件,如果没有运行,那么运行。如果运行,那么置顶。
      

  2.   

    按照你程序的标题+窗口类名,使用 FindWindow 函数来查找你的窗口,再用 ShowWindow 函数显示你的窗口!
      

  3.   

    FindWindow 的方法不可靠,不推荐。专业的做法是使用 RegisterWindowMessage 和 CreateMutex。VC示例代码如下:
    启动时:
    ////////////////
        CHAR szMutexName[] = "aabbcc~~tt";
        g_GlobeRestoreMsg = RegisterWindowMessage(szMutexName);
        
        //
        //Register ATOM
        //
        HANDLE hMutex = CreateMutex(NULL,FALSE,szMutexName);
        
        if (hMutex == NULL)
        {
            return FALSE;
        }
        else if(ERROR_ALREADY_EXISTS == ::GetLastError())
        {
            //
            // Restore the exist instance...
            //
            ::SendMessage(HWND_BROADCAST,
    g_GlobeRestoreMsg,
    -1,       //Restore
    0);
            CloseHandle(hMutex);
            return FALSE;
        }然后在主窗口的窗口过程中,处理自定义消息:
    LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
    {
        if (message == g_GlobeRestoreMsg)
        {
            CString strDebug;
            
            strDebug.Format("[MMXShell] HWND_BROADCAST, wParam = %d\n", wParam);
            OutputDebugString(strDebug);
            
            if (wParam == -1) // 是本进程发送的广播消息
            {
                ::SetForegroundWindow(this->m_hWnd);
            }
            else // 由MMXDetect发送的
            {
            }
            
            return 1;
        }
      

  4.   

    http://topic.csdn.net/t/20030311/16/1517558.html
      

  5.   

    启动窗口中加
    Private Sub Form_Load() 
    If App.PrevInstance Then 
    MsgBox "你已经运行这个应用程序了" 
    End ' 退出新运行的程序 
    End If 
    End Sub