http://www.vckbase.com/vckbase/columnist/ac952_z_cn/default.asp

解决方案 »

  1.   

    为什么认为服务程序一般不可以使用窗体?要知道那是2000不是unix,后台进程并不意味着一定没有窗体。窗体只是数据的观察器而已。有数据的运行体,当然最好有数据的察看与操作体。这样的服务程序才是可知。不要服务程序想象成什么端口守护进程,,,那只是比较原始的东西。像2000这种系统。光有数据运行体是不行的。不完整的。
      

  2.   

    BOOL CServiceModule::ShowMsgDlg(void)
    {
           HDESK   hdeskCurrent;
        HDESK   hdesk;
        HWINSTA hwinstaCurrent;
        HWINSTA hwinsta;    hwinstaCurrent = GetProcessWindowStation();
        if (hwinstaCurrent == NULL){
                  LogEvent(_T("get window station err"));
           return FALSE;
           }    hdeskCurrent = GetThreadDesktop(GetCurrentThreadId());
        if (hdeskCurrent == NULL){
                  LogEvent(_T("get window desktop err"));
           return FALSE;
           }//打开winsta0
        hwinsta = OpenWindowStation("winsta0", FALSE,                          
                                      WINSTA_ACCESSCLIPBOARD   |
                                      WINSTA_ACCESSGLOBALATOMS |
                                      WINSTA_CREATEDESKTOP     |
                                      WINSTA_ENUMDESKTOPS      |
                                      WINSTA_ENUMERATE         |
                                      WINSTA_EXITWINDOWS       |
                                      WINSTA_READATTRIBUTES    |
                                      WINSTA_READSCREEN        |
                                      WINSTA_WRITEATTRIBUTES);
        if (hwinsta == NULL){
                  LogEvent(_T("open window station err"));       return FALSE;
           }    if (!SetProcessWindowStation(hwinsta)){
                  LogEvent(_T("Set window station err"));       return FALSE;
           }//打开desktop
        hdesk = OpenDesktop("default", 0, FALSE,                
                                DESKTOP_CREATEMENU |
                                DESKTOP_CREATEWINDOW |
                                DESKTOP_ENUMERATE    |
                                DESKTOP_HOOKCONTROL  |
                                DESKTOP_JOURNALPLAYBACK |
                                DESKTOP_JOURNALRECORD |
                                DESKTOP_READOBJECTS |
                                DESKTOP_SWITCHDESKTOP |
                                DESKTOP_WRITEOBJECTS);
           if (hdesk == NULL){
                  LogEvent(_T("Open desktop err"));           return FALSE;
           }       SetThreadDesktop(hdesk);//到这一步,我们获取了和用户交互(如显示窗口)的权利
           CMsgDlg dlgMsg;
    //显示一个dialog
           dlgMsg.DoModal();                     if (!SetProcessWindowStation(hwinstaCurrent))
               return FALSE;       if (!SetThreadDesktop(hdeskCurrent))
          return FALSE;       if (!CloseWindowStation(hwinsta))
                  return FALSE;       if (!CloseDesktop(hdesk))
               return FALSE;              return TRUE;
    }
      

  3.   

    http://www.csdn.net/expert/topic/574/574089.xml?temp=.1257288
      

  4.   

    http://www.csdn.net/expert/topic/574/574089.xml?temp=.1257288
      

  5.   

    对不起 lauyue(rax) 
    分给的仓促,忘记你了
    请到下面处领分,谢谢
      

  6.   

    http://www.csdn.net/expert/topic/724/724329.xml?temp=.9304163
      

  7.   

    //摘自MSDN的代码:DWORD dwGuiThreadId = 0; 
     
    int 
    UserMessageBox( 
        RPC_BINDING_HANDLE h, 
        LPSTR lpszWindowStation, 
        LPSTR lpszDesktop, 
        LPSTR lpszText, 
        LPSTR lpszTitle, 
        UINT fuStyle) 

        DWORD dwThreadId; 
        HWINSTA hwinstaSave; 
        HDESK hdeskSave; 
        HWINSTA hwinstaUser; 
        HDESK hdeskUser; 
        int result; 
     
        // Ensure connection to service window station and desktop, and 
        // save their handles.     GetDesktopWindow(); 
        hwinstaSave = GetProcessWindowStation(); 
        dwThreadId = GetCurrentThreadId(); 
        hdeskSave = GetThreadDesktop(dwThreadId); 
     
        // Impersonate the client and connect to the User's 
        // window station and desktop.     RpcImpersonateClient(h); 
        hwinstaUser = OpenWindowStation(lpszWindowStation, FALSE, MAXIMUM_ALLOWED); 
        if (hwinstaUser == NULL) 
        { 
            RpcRevertToSelf(); 
            return 0; 
        } 
        SetProcessWindowStation(hwinstaUser); 
        hdeskUser = OpenDesktop(lpszDesktop, 0, FALSE, MAXIMUM_ALLOWED); 
        RpcRevertToSelf(); 
        if (hdeskUser == NULL) 
        { 
            SetProcessWindowStation(hwinstaSave); 
            CloseWindowStation(hwinstaUser); 
            return 0; 
        } 
        SetThreadDesktop(hdeskUser); 
     
        // Display message box.     dwGuiThreadId = dwThreadId; 
        result = MessageBox(NULL, lpszText, lpszTitle, fuStyle); 
        dwGuiThreadId = 0; 
     
        // Restore window station and desktop.     SetThreadDesktop(hdeskSave); 
        SetProcessWindowStation(hwinstaSave); 
        CloseDesktop(hdeskUser); 
        CloseWindowStation(hwinstaUser); 
     
        return result;