How to display a dialog box in a service program

Source: Internet
Author: User
How to display a dialog box in a service program

Author: ac952_z_cn

Download source code
 
Service programs (services) generally can not interact with the user, so he is generally unable to display the window. To interact with the user (such as the display window), we must open the user WinSta0 and desktop, and the following code opens the above two and displays a dialog:
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;                          
                                  //Open 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;  //Open 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);
In this step, we get the right to interact with the user (such as the display window) Cmsgdlg dlgmsg;              

       Displays a 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;
  }
Run: Compile build Guiser.exe, run Guiser/service, and then start the service in the services in Control Panel, a dialog box will appear.

The program above Win2000 Professional + VC6.0 + Sp5.0 + Platform SDK 2001.8 compiles and runs through
if there is no compilation, please download the latest Platform SDK

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.