I think you all know of the Vista UAC dialog prompt that pops up on a new desktop to make you confirm things so my question relates to that.

At The Code Project, a clever little cookie wrote what i'm after and it's called VDialog and its description reads "Vista-like TaskDialog control for .NET Framework 2.0, compatible with Windows XP" but i'm having trouble with his code.

What i'd like to do is not use his DialogResults and use a second form with my own buttons. I've tried so many things but i can't seem to do it.

Simply put: Could somebody use his project to make a solution that has the main form with a button on it that pops up form2 the way it does with his custom dialogs.

Wouldn't ask if i had any idea what i was doing wrong. I'm a little cut that i can't do it myself so i'm hoping somebody here has the know-how to rip his apart and use it the way i'd like to. Thanks.

SNIP

Dani AI

Generated

— the missing piece is the call order and the thread you use to host the UI. is right that the VDialog author can help with their code, but the practical pattern to adapt VDialog so your own Form2 runs on a separate desktop is straightforward:

  1. Create a new desktop.
  2. Start a fresh Thread (not a ThreadPool thread), set its apartment to STA before starting.
  3. In that thread call SetThreadDesktop(hDesktop) before doing any Windows/WinForms work, then create and Application.Run your Form2 there.
  4. From the original thread call SwitchDesktop(hDesktop) to show it; wait for the form to close (ManualResetEvent or join the thread), then switch back and clean up.

A short VB.NET-style sketch (flow only):

' create desktop
Dim hd As IntPtr = CreateDesktop("MyDesk", Nothing, IntPtr.Zero, 0, DESKTOP_ALL, IntPtr.Zero)

Dim finished As New ManualResetEvent(False)
Dim result As Object = Nothing

Dim th As New Thread(Sub()
    SetThreadDesktop(hd)
    Dim f As New Form2()
    AddHandler f.FormClosed, Sub(s,e)
                                result = f.Tag ' or a public property you set
                                finished.Set()
                            End Sub
    Application.Run(f)
End Sub)

th.SetApartmentState(ApartmentState.STA)
th.Start()

SwitchDesktop(hd)
finished.WaitOne()
SwitchDesktop(originalDesktop)
CloseDesktop(hd)

Key troubleshooting notes:

  • Call SetThreadDesktop before the thread creates any windows or uses WinForms/COM—CLR or WinForms calls can create hidden windows, so use a brand new Thread and set STA first. See the API docs for CreateDesktop, SetThreadDesktop, and SwitchDesktop for exact rules and required access rights.
  • If SetThreadDesktop or SwitchDesktop fails, check window-station permissions and that you are on the interactive window station.
  • If you only need isolation (not elevation), this pattern is fine. Do not try to mimic the system UAC secure desktop for elevation prompts; use proper elevation APIs instead.

Useful references: CreateDesktop, SetThreadDesktop, SwitchDesktop, and .NET Thread.SetApartmentState.

Bump ;(

Please contact the author of the VDialog.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.