Hi people,

I have a suite of applications developed for a mobile device using VS2005
Beta 2 and the .NET compact framework. The applications need to be capable of
bringing each other to the front of the Z order. Problem is I cant use
P/invoke routines to do a FindWindow() and then SetForegroundWindow() due to
the application forms being derived from a base class form and visual
inheritance with P/Invoke will not work.

Is there an alternative way of doing this in managed code?

Thanks.

--
Tony Hudson

Re: Findwindow - how in managed code? by ctacke/>

ctacke/>
Tue Sep 13 06:34:20 CDT 2005

So why can't you use P/Invoke? Visual inheritance has nothing to do with
it.

-Chris


"Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in message
news:6A7F8EF4-7AF9-4534-95A8-447A12B2AC81@microsoft.com...
> Hi people,
>
> I have a suite of applications developed for a mobile device using VS2005
> Beta 2 and the .NET compact framework. The applications need to be capable
> of
> bringing each other to the front of the Z order. Problem is I cant use
> P/invoke routines to do a FindWindow() and then SetForegroundWindow() due
> to
> the application forms being derived from a base class form and visual
> inheritance with P/Invoke will not work.
>
> Is there an alternative way of doing this in managed code?
>
> Thanks.
>
> --
> Tony Hudson



Re: Findwindow - how in managed code? by TonyHudson

TonyHudson
Tue Sep 13 11:47:22 CDT 2005

Its a bug in VS2005 beta 2 that is not going to be fixed in the first
official release and it is causing me big problems. I have taken the
P/invoke references out of the base class form and exposed the functionality
through a DLL class library that is called by the base class form and it
still does not allow it. I need to find a workaround.

--
Tony Hudson


"<ctacke/>" wrote:

> So why can't you use P/Invoke? Visual inheritance has nothing to do with
> it.
>
> -Chris
>
>
> "Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in message
> news:6A7F8EF4-7AF9-4534-95A8-447A12B2AC81@microsoft.com...
> > Hi people,
> >
> > I have a suite of applications developed for a mobile device using VS2005
> > Beta 2 and the .NET compact framework. The applications need to be capable
> > of
> > bringing each other to the front of the Z order. Problem is I cant use
> > P/invoke routines to do a FindWindow() and then SetForegroundWindow() due
> > to
> > the application forms being derived from a base class form and visual
> > inheritance with P/Invoke will not work.
> >
> > Is there an alternative way of doing this in managed code?
> >
> > Thanks.
> >
> > --
> > Tony Hudson
>
>
>

Re: Findwindow - how in managed code? by Daniel

Daniel
Tue Sep 13 16:28:49 CDT 2005

Can you post a repro?

Cheers
Daniel
--
http://www.danielmoth.com/Blog/

"Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in message
news:0678E4C6-C0C2-4D52-8EA9-8D52211F8689@microsoft.com...
> Its a bug in VS2005 beta 2 that is not going to be fixed in the first
> official release and it is causing me big problems. I have taken the
> P/invoke references out of the base class form and exposed the
> functionality
> through a DLL class library that is called by the base class form and it
> still does not allow it. I need to find a workaround.
>
> --
> Tony Hudson
>
>
> "<ctacke/>" wrote:
>
>> So why can't you use P/Invoke? Visual inheritance has nothing to do with
>> it.
>>
>> -Chris
>>
>>
>> "Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in message
>> news:6A7F8EF4-7AF9-4534-95A8-447A12B2AC81@microsoft.com...
>> > Hi people,
>> >
>> > I have a suite of applications developed for a mobile device using
>> > VS2005
>> > Beta 2 and the .NET compact framework. The applications need to be
>> > capable
>> > of
>> > bringing each other to the front of the Z order. Problem is I cant use
>> > P/invoke routines to do a FindWindow() and then SetForegroundWindow()
>> > due
>> > to
>> > the application forms being derived from a base class form and visual
>> > inheritance with P/Invoke will not work.
>> >
>> > Is there an alternative way of doing this in managed code?
>> >
>> > Thanks.
>> >
>> > --
>> > Tony Hudson
>>
>>
>>



Re: Findwindow - how in managed code? by TonyHudson

TonyHudson
Wed Sep 14 08:19:04 CDT 2005

To reproduce the bug perform the following.

1) Create a PocketPC 2003 Class library and call it API_Library.
2) paste the following code into the ".vb" file of this project

Imports System.Runtime.InteropServices
Public Class AppSwapper

<DllImport("coredll.dll")> _
Private Shared Function FindWindow(ByVal className As String, ByVal
wndName As String) As IntPtr
End Function

<DllImport("coredll.dll")> _
Private Shared Function SetForegroundWindow(ByVal ipHandle As
IntPtr) As Int32
End Function

Public Function BringAppToFront(ByVal strWindowTitle As String) As Integer
Dim intErrCode As Integer = 1

Dim ipHandle As IntPtr = FindWindow(vbNullString, strWindowTitle)
If SetForegroundWindow(ipHandle) <> 0 Then
intErrCode = 0
End If

Return intErrCode
End Function

End Class

3) Build this project creating API_Library.dll

4) Create a PocketPC 2003 Class library and call it VIbaseclasses.
5) Add a form to the project
6) rename the form frmBase
7) drop two buttons on the form leaving the default names.
8) paste the following code into the form frmBase

Public Class frmBase
Protected Overridable Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("frmbase - button1 clicked")
'Dim objSwapper As New API_Library.AppSwapper
'objSwapper.BringAppToFront("Test")

End Sub
Protected Overridable Sub Button2_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button2.Click
MsgBox("frmbase - button2 clicked")
End Sub
End Class

9) Add a referenece to API_Library.dll created earlier.
10) Build this project creating VIbaseclasses.dll

11) Create a PocketPC 2003 device application and call it VItest.
12) Add a form to the project leaving it at the default name
13) Add a referenece to VIbaseclasses.dll created earlier.
14) Build the project

15) Exit the project and locate the folder containg the VITest project.
16) using a text editor, edit the file Form1.Designer.vb and change the line
Inherits System.Windows.Forms.Form to Inherits VIbaseclasses.frmBase.
17) save the file and re-open the VITest project. The form should appear as
expected showing the inherited buttons.

18) re-open the VIbaseclasses project and un-comment the lines in the
Button1_Click subroutine refering to the variable objSwapper.
19) save the file and re-build VIbaseclasses project.

20) re-open the VItest project and open the Form1 designer. You will get
the "Visual inheritance is currently disabled message..." with no buttons
from the inherited form.

--
Tony Hudson


"Daniel Moth" wrote:

> Can you post a repro?
>
> Cheers
> Daniel
> --
> http://www.danielmoth.com/Blog/
>
> "Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in message
> news:0678E4C6-C0C2-4D52-8EA9-8D52211F8689@microsoft.com...
> > Its a bug in VS2005 beta 2 that is not going to be fixed in the first
> > official release and it is causing me big problems. I have taken the
> > P/invoke references out of the base class form and exposed the
> > functionality
> > through a DLL class library that is called by the base class form and it
> > still does not allow it. I need to find a workaround.
> >
> > --
> > Tony Hudson
> >
> >
> > "<ctacke/>" wrote:
> >
> >> So why can't you use P/Invoke? Visual inheritance has nothing to do with
> >> it.
> >>
> >> -Chris
> >>
> >>
> >> "Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in message
> >> news:6A7F8EF4-7AF9-4534-95A8-447A12B2AC81@microsoft.com...
> >> > Hi people,
> >> >
> >> > I have a suite of applications developed for a mobile device using
> >> > VS2005
> >> > Beta 2 and the .NET compact framework. The applications need to be
> >> > capable
> >> > of
> >> > bringing each other to the front of the Z order. Problem is I cant use
> >> > P/invoke routines to do a FindWindow() and then SetForegroundWindow()
> >> > due
> >> > to
> >> > the application forms being derived from a base class form and visual
> >> > inheritance with P/Invoke will not work.
> >> >
> >> > Is there an alternative way of doing this in managed code?
> >> >
> >> > Thanks.
> >> >
> >> > --
> >> > Tony Hudson
> >>
> >>
> >>
>
>
>

Re: Findwindow - how in managed code? by TonyHudson

TonyHudson
Thu Sep 15 10:34:05 CDT 2005

Daniel,

You managed to look into or duplicate this?

--
Tony Hudson


"Tony Hudson" wrote:

> To reproduce the bug perform the following.
>
> 1) Create a PocketPC 2003 Class library and call it API_Library.
> 2) paste the following code into the ".vb" file of this project
>
> Imports System.Runtime.InteropServices
> Public Class AppSwapper
>
> <DllImport("coredll.dll")> _
> Private Shared Function FindWindow(ByVal className As String, ByVal
> wndName As String) As IntPtr
> End Function
>
> <DllImport("coredll.dll")> _
> Private Shared Function SetForegroundWindow(ByVal ipHandle As
> IntPtr) As Int32
> End Function
>
> Public Function BringAppToFront(ByVal strWindowTitle As String) As Integer
> Dim intErrCode As Integer = 1
>
> Dim ipHandle As IntPtr = FindWindow(vbNullString, strWindowTitle)
> If SetForegroundWindow(ipHandle) <> 0 Then
> intErrCode = 0
> End If
>
> Return intErrCode
> End Function
>
> End Class
>
> 3) Build this project creating API_Library.dll
>
> 4) Create a PocketPC 2003 Class library and call it VIbaseclasses.
> 5) Add a form to the project
> 6) rename the form frmBase
> 7) drop two buttons on the form leaving the default names.
> 8) paste the following code into the form frmBase
>
> Public Class frmBase
> Protected Overridable Sub Button1_Click(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles Button1.Click
> MsgBox("frmbase - button1 clicked")
> 'Dim objSwapper As New API_Library.AppSwapper
> 'objSwapper.BringAppToFront("Test")
>
> End Sub
> Protected Overridable Sub Button2_Click(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles Button2.Click
> MsgBox("frmbase - button2 clicked")
> End Sub
> End Class
>
> 9) Add a referenece to API_Library.dll created earlier.
> 10) Build this project creating VIbaseclasses.dll
>
> 11) Create a PocketPC 2003 device application and call it VItest.
> 12) Add a form to the project leaving it at the default name
> 13) Add a referenece to VIbaseclasses.dll created earlier.
> 14) Build the project
>
> 15) Exit the project and locate the folder containg the VITest project.
> 16) using a text editor, edit the file Form1.Designer.vb and change the line
> Inherits System.Windows.Forms.Form to Inherits VIbaseclasses.frmBase.
> 17) save the file and re-open the VITest project. The form should appear as
> expected showing the inherited buttons.
>
> 18) re-open the VIbaseclasses project and un-comment the lines in the
> Button1_Click subroutine refering to the variable objSwapper.
> 19) save the file and re-build VIbaseclasses project.
>
> 20) re-open the VItest project and open the Form1 designer. You will get
> the "Visual inheritance is currently disabled message..." with no buttons
> from the inherited form.
>
> --
> Tony Hudson
>
>
> "Daniel Moth" wrote:
>
> > Can you post a repro?
> >
> > Cheers
> > Daniel
> > --
> > http://www.danielmoth.com/Blog/
> >
> > "Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in message
> > news:0678E4C6-C0C2-4D52-8EA9-8D52211F8689@microsoft.com...
> > > Its a bug in VS2005 beta 2 that is not going to be fixed in the first
> > > official release and it is causing me big problems. I have taken the
> > > P/invoke references out of the base class form and exposed the
> > > functionality
> > > through a DLL class library that is called by the base class form and it
> > > still does not allow it. I need to find a workaround.
> > >
> > > --
> > > Tony Hudson
> > >
> > >
> > > "<ctacke/>" wrote:
> > >
> > >> So why can't you use P/Invoke? Visual inheritance has nothing to do with
> > >> it.
> > >>
> > >> -Chris
> > >>
> > >>
> > >> "Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in message
> > >> news:6A7F8EF4-7AF9-4534-95A8-447A12B2AC81@microsoft.com...
> > >> > Hi people,
> > >> >
> > >> > I have a suite of applications developed for a mobile device using
> > >> > VS2005
> > >> > Beta 2 and the .NET compact framework. The applications need to be
> > >> > capable
> > >> > of
> > >> > bringing each other to the front of the Z order. Problem is I cant use
> > >> > P/invoke routines to do a FindWindow() and then SetForegroundWindow()
> > >> > due
> > >> > to
> > >> > the application forms being derived from a base class form and visual
> > >> > inheritance with P/Invoke will not work.
> > >> >
> > >> > Is there an alternative way of doing this in managed code?
> > >> >
> > >> > Thanks.
> > >> >
> > >> > --
> > >> > Tony Hudson
> > >>
> > >>
> > >>
> >
> >
> >

Re: Findwindow - how in managed code? by Daniel

Daniel
Thu Sep 15 14:13:10 CDT 2005

Hi Tony... if nobody else picks it up, I may have time to look at it over
the weekend... just to be clear, is your issue that the designer gets lost
_or_ that the pinvokes don't work (which is what I originally understood)...

Also if this is the first time you are posting repro steps (you insinuate
that you've told someone before), I suggest you post them to
ladybug/feedbackcenter so the vsd/netcf teams have visibility of the
issue...

Cheers
Daniel
--
http://www.danielmoth.com/Blog/

"Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in message
news:64E63E63-B5D3-4053-B317-DC746EA495B7@microsoft.com...
> Daniel,
>
> You managed to look into or duplicate this?
>
> --
> Tony Hudson
>
>
> "Tony Hudson" wrote:
>
>> To reproduce the bug perform the following.
>>
>> 1) Create a PocketPC 2003 Class library and call it API_Library.
>> 2) paste the following code into the ".vb" file of this project
>>
>> Imports System.Runtime.InteropServices
>> Public Class AppSwapper
>>
>> <DllImport("coredll.dll")> _
>> Private Shared Function FindWindow(ByVal className As String,
>> ByVal
>> wndName As String) As IntPtr
>> End Function
>>
>> <DllImport("coredll.dll")> _
>> Private Shared Function SetForegroundWindow(ByVal ipHandle As
>> IntPtr) As Int32
>> End Function
>>
>> Public Function BringAppToFront(ByVal strWindowTitle As String) As
>> Integer
>> Dim intErrCode As Integer = 1
>>
>> Dim ipHandle As IntPtr = FindWindow(vbNullString, strWindowTitle)
>> If SetForegroundWindow(ipHandle) <> 0 Then
>> intErrCode = 0
>> End If
>>
>> Return intErrCode
>> End Function
>>
>> End Class
>>
>> 3) Build this project creating API_Library.dll
>>
>> 4) Create a PocketPC 2003 Class library and call it VIbaseclasses.
>> 5) Add a form to the project
>> 6) rename the form frmBase
>> 7) drop two buttons on the form leaving the default names.
>> 8) paste the following code into the form frmBase
>>
>> Public Class frmBase
>> Protected Overridable Sub Button1_Click(ByVal sender As
>> System.Object,
>> ByVal e As System.EventArgs) Handles Button1.Click
>> MsgBox("frmbase - button1 clicked")
>> 'Dim objSwapper As New API_Library.AppSwapper
>> 'objSwapper.BringAppToFront("Test")
>>
>> End Sub
>> Protected Overridable Sub Button2_Click(ByVal sender As
>> System.Object,
>> ByVal e As System.EventArgs) Handles Button2.Click
>> MsgBox("frmbase - button2 clicked")
>> End Sub
>> End Class
>>
>> 9) Add a referenece to API_Library.dll created earlier.
>> 10) Build this project creating VIbaseclasses.dll
>>
>> 11) Create a PocketPC 2003 device application and call it VItest.
>> 12) Add a form to the project leaving it at the default name
>> 13) Add a referenece to VIbaseclasses.dll created earlier.
>> 14) Build the project
>>
>> 15) Exit the project and locate the folder containg the VITest project.
>> 16) using a text editor, edit the file Form1.Designer.vb and change the
>> line
>> Inherits System.Windows.Forms.Form to Inherits VIbaseclasses.frmBase.
>> 17) save the file and re-open the VITest project. The form should appear
>> as
>> expected showing the inherited buttons.
>>
>> 18) re-open the VIbaseclasses project and un-comment the lines in the
>> Button1_Click subroutine refering to the variable objSwapper.
>> 19) save the file and re-build VIbaseclasses project.
>>
>> 20) re-open the VItest project and open the Form1 designer. You will get
>> the "Visual inheritance is currently disabled message..." with no
>> buttons
>> from the inherited form.
>>
>> --
>> Tony Hudson
>>
>>
>> "Daniel Moth" wrote:
>>
>> > Can you post a repro?
>> >
>> > Cheers
>> > Daniel
>> > --
>> > http://www.danielmoth.com/Blog/
>> >
>> > "Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in message
>> > news:0678E4C6-C0C2-4D52-8EA9-8D52211F8689@microsoft.com...
>> > > Its a bug in VS2005 beta 2 that is not going to be fixed in the first
>> > > official release and it is causing me big problems. I have taken the
>> > > P/invoke references out of the base class form and exposed the
>> > > functionality
>> > > through a DLL class library that is called by the base class form and
>> > > it
>> > > still does not allow it. I need to find a workaround.
>> > >
>> > > --
>> > > Tony Hudson
>> > >
>> > >
>> > > "<ctacke/>" wrote:
>> > >
>> > >> So why can't you use P/Invoke? Visual inheritance has nothing to do
>> > >> with
>> > >> it.
>> > >>
>> > >> -Chris
>> > >>
>> > >>
>> > >> "Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in
>> > >> message
>> > >> news:6A7F8EF4-7AF9-4534-95A8-447A12B2AC81@microsoft.com...
>> > >> > Hi people,
>> > >> >
>> > >> > I have a suite of applications developed for a mobile device using
>> > >> > VS2005
>> > >> > Beta 2 and the .NET compact framework. The applications need to be
>> > >> > capable
>> > >> > of
>> > >> > bringing each other to the front of the Z order. Problem is I
>> > >> > cant use
>> > >> > P/invoke routines to do a FindWindow() and then
>> > >> > SetForegroundWindow()
>> > >> > due
>> > >> > to
>> > >> > the application forms being derived from a base class form and
>> > >> > visual
>> > >> > inheritance with P/Invoke will not work.
>> > >> >
>> > >> > Is there an alternative way of doing this in managed code?
>> > >> >
>> > >> > Thanks.
>> > >> >
>> > >> > --
>> > >> > Tony Hudson
>> > >>
>> > >>
>> > >>
>> >
>> >
>> >



Re: Findwindow - how in managed code? by Daniel

Daniel
Sun Sep 18 05:51:06 CDT 2005

I could repro what you describe and I have a fix for you.

- I run this using VS2005 TS RC
- No need for 3 separate projects, just use 1 with all the code files in it
(in fact, I generally advise against having forms in dlls)
- No need to edit the form in a text file for visual inheritance, just
follow the steps here:
http://www.danielmoth.com/Blog/2005/07/visual-form-inheritance-with-netcf.html

So, indeed the inherited form is not displayed in the designer when the form
it inherits from makes pinvoke calls.

To rectify this, follow the following steps:
1. Right click on frmBase and select "View Class Diagram"
2. Select the class shape and then go to the properties window. Select
Custom Attributes so a window come up.
3. The window has one line
Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()
4. Add one more line
DesktopCompatible(true)
and click OK
5. Rebuild your solution and the form displays fine in the designer

Let me know if it does not work for you.

Cheers
Daniel
--
http://www.danielmoth.com/Blog/

"Daniel Moth" <dmoth74@hotmail.com> wrote in message
news:e3TpDmiuFHA.3792@TK2MSFTNGP10.phx.gbl...
> Hi Tony... if nobody else picks it up, I may have time to look at it over
> the weekend... just to be clear, is your issue that the designer gets lost
> _or_ that the pinvokes don't work (which is what I originally
> understood)...
>
> Also if this is the first time you are posting repro steps (you insinuate
> that you've told someone before), I suggest you post them to
> ladybug/feedbackcenter so the vsd/netcf teams have visibility of the
> issue...
>
> Cheers
> Daniel
> --
> http://www.danielmoth.com/Blog/
>
> "Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in message
> news:64E63E63-B5D3-4053-B317-DC746EA495B7@microsoft.com...
>> Daniel,
>>
>> You managed to look into or duplicate this?
>>
>> --
>> Tony Hudson
>>
>>
>> "Tony Hudson" wrote:
>>
>>> To reproduce the bug perform the following.
>>>
>>> 1) Create a PocketPC 2003 Class library and call it API_Library.
>>> 2) paste the following code into the ".vb" file of this project
>>>
>>> Imports System.Runtime.InteropServices
>>> Public Class AppSwapper
>>>
>>> <DllImport("coredll.dll")> _
>>> Private Shared Function FindWindow(ByVal className As String,
>>> ByVal
>>> wndName As String) As IntPtr
>>> End Function
>>>
>>> <DllImport("coredll.dll")> _
>>> Private Shared Function SetForegroundWindow(ByVal ipHandle As
>>> IntPtr) As Int32
>>> End Function
>>>
>>> Public Function BringAppToFront(ByVal strWindowTitle As String) As
>>> Integer
>>> Dim intErrCode As Integer = 1
>>>
>>> Dim ipHandle As IntPtr = FindWindow(vbNullString,
>>> strWindowTitle)
>>> If SetForegroundWindow(ipHandle) <> 0 Then
>>> intErrCode = 0
>>> End If
>>>
>>> Return intErrCode
>>> End Function
>>>
>>> End Class
>>>
>>> 3) Build this project creating API_Library.dll
>>>
>>> 4) Create a PocketPC 2003 Class library and call it VIbaseclasses.
>>> 5) Add a form to the project
>>> 6) rename the form frmBase
>>> 7) drop two buttons on the form leaving the default names.
>>> 8) paste the following code into the form frmBase
>>>
>>> Public Class frmBase
>>> Protected Overridable Sub Button1_Click(ByVal sender As
>>> System.Object,
>>> ByVal e As System.EventArgs) Handles Button1.Click
>>> MsgBox("frmbase - button1 clicked")
>>> 'Dim objSwapper As New API_Library.AppSwapper
>>> 'objSwapper.BringAppToFront("Test")
>>>
>>> End Sub
>>> Protected Overridable Sub Button2_Click(ByVal sender As
>>> System.Object,
>>> ByVal e As System.EventArgs) Handles Button2.Click
>>> MsgBox("frmbase - button2 clicked")
>>> End Sub
>>> End Class
>>>
>>> 9) Add a referenece to API_Library.dll created earlier.
>>> 10) Build this project creating VIbaseclasses.dll
>>>
>>> 11) Create a PocketPC 2003 device application and call it VItest.
>>> 12) Add a form to the project leaving it at the default name
>>> 13) Add a referenece to VIbaseclasses.dll created earlier.
>>> 14) Build the project
>>>
>>> 15) Exit the project and locate the folder containg the VITest project.
>>> 16) using a text editor, edit the file Form1.Designer.vb and change the
>>> line
>>> Inherits System.Windows.Forms.Form to Inherits VIbaseclasses.frmBase.
>>> 17) save the file and re-open the VITest project. The form should
>>> appear as
>>> expected showing the inherited buttons.
>>>
>>> 18) re-open the VIbaseclasses project and un-comment the lines in the
>>> Button1_Click subroutine refering to the variable objSwapper.
>>> 19) save the file and re-build VIbaseclasses project.
>>>
>>> 20) re-open the VItest project and open the Form1 designer. You will
>>> get
>>> the "Visual inheritance is currently disabled message..." with no
>>> buttons
>>> from the inherited form.
>>>
>>> --
>>> Tony Hudson
>>>
>>>
>>> "Daniel Moth" wrote:
>>>
>>> > Can you post a repro?
>>> >
>>> > Cheers
>>> > Daniel
>>> > --
>>> > http://www.danielmoth.com/Blog/
>>> >
>>> > "Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in message
>>> > news:0678E4C6-C0C2-4D52-8EA9-8D52211F8689@microsoft.com...
>>> > > Its a bug in VS2005 beta 2 that is not going to be fixed in the
>>> > > first
>>> > > official release and it is causing me big problems. I have taken
>>> > > the
>>> > > P/invoke references out of the base class form and exposed the
>>> > > functionality
>>> > > through a DLL class library that is called by the base class form
>>> > > and it
>>> > > still does not allow it. I need to find a workaround.
>>> > >
>>> > > --
>>> > > Tony Hudson
>>> > >
>>> > >
>>> > > "<ctacke/>" wrote:
>>> > >
>>> > >> So why can't you use P/Invoke? Visual inheritance has nothing to
>>> > >> do with
>>> > >> it.
>>> > >>
>>> > >> -Chris
>>> > >>
>>> > >>
>>> > >> "Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in
>>> > >> message
>>> > >> news:6A7F8EF4-7AF9-4534-95A8-447A12B2AC81@microsoft.com...
>>> > >> > Hi people,
>>> > >> >
>>> > >> > I have a suite of applications developed for a mobile device
>>> > >> > using
>>> > >> > VS2005
>>> > >> > Beta 2 and the .NET compact framework. The applications need to
>>> > >> > be
>>> > >> > capable
>>> > >> > of
>>> > >> > bringing each other to the front of the Z order. Problem is I
>>> > >> > cant use
>>> > >> > P/invoke routines to do a FindWindow() and then
>>> > >> > SetForegroundWindow()
>>> > >> > due
>>> > >> > to
>>> > >> > the application forms being derived from a base class form and
>>> > >> > visual
>>> > >> > inheritance with P/Invoke will not work.
>>> > >> >
>>> > >> > Is there an alternative way of doing this in managed code?
>>> > >> >
>>> > >> > Thanks.
>>> > >> >
>>> > >> > --
>>> > >> > Tony Hudson
>>> > >>
>>> > >>
>>> > >>
>>> >
>>> >
>>> >
>
>



Re: Findwindow - how in managed code? by TonyHudson

TonyHudson
Mon Sep 19 05:14:04 CDT 2005

Daniel, You are a star. Works fine. Thankyou once again.
--
Tony Hudson


"Daniel Moth" wrote:

> I could repro what you describe and I have a fix for you.
>
> - I run this using VS2005 TS RC
> - No need for 3 separate projects, just use 1 with all the code files in it
> (in fact, I generally advise against having forms in dlls)
> - No need to edit the form in a text file for visual inheritance, just
> follow the steps here:
> http://www.danielmoth.com/Blog/2005/07/visual-form-inheritance-with-netcf.html
>
> So, indeed the inherited form is not displayed in the designer when the form
> it inherits from makes pinvoke calls.
>
> To rectify this, follow the following steps:
> 1. Right click on frmBase and select "View Class Diagram"
> 2. Select the class shape and then go to the properties window. Select
> Custom Attributes so a window come up.
> 3. The window has one line
> Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()
> 4. Add one more line
> DesktopCompatible(true)
> and click OK
> 5. Rebuild your solution and the form displays fine in the designer
>
> Let me know if it does not work for you.
>
> Cheers
> Daniel
> --
> http://www.danielmoth.com/Blog/
>
> "Daniel Moth" <dmoth74@hotmail.com> wrote in message
> news:e3TpDmiuFHA.3792@TK2MSFTNGP10.phx.gbl...
> > Hi Tony... if nobody else picks it up, I may have time to look at it over
> > the weekend... just to be clear, is your issue that the designer gets lost
> > _or_ that the pinvokes don't work (which is what I originally
> > understood)...
> >
> > Also if this is the first time you are posting repro steps (you insinuate
> > that you've told someone before), I suggest you post them to
> > ladybug/feedbackcenter so the vsd/netcf teams have visibility of the
> > issue...
> >
> > Cheers
> > Daniel
> > --
> > http://www.danielmoth.com/Blog/
> >
> > "Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in message
> > news:64E63E63-B5D3-4053-B317-DC746EA495B7@microsoft.com...
> >> Daniel,
> >>
> >> You managed to look into or duplicate this?
> >>
> >> --
> >> Tony Hudson
> >>
> >>
> >> "Tony Hudson" wrote:
> >>
> >>> To reproduce the bug perform the following.
> >>>
> >>> 1) Create a PocketPC 2003 Class library and call it API_Library.
> >>> 2) paste the following code into the ".vb" file of this project
> >>>
> >>> Imports System.Runtime.InteropServices
> >>> Public Class AppSwapper
> >>>
> >>> <DllImport("coredll.dll")> _
> >>> Private Shared Function FindWindow(ByVal className As String,
> >>> ByVal
> >>> wndName As String) As IntPtr
> >>> End Function
> >>>
> >>> <DllImport("coredll.dll")> _
> >>> Private Shared Function SetForegroundWindow(ByVal ipHandle As
> >>> IntPtr) As Int32
> >>> End Function
> >>>
> >>> Public Function BringAppToFront(ByVal strWindowTitle As String) As
> >>> Integer
> >>> Dim intErrCode As Integer = 1
> >>>
> >>> Dim ipHandle As IntPtr = FindWindow(vbNullString,
> >>> strWindowTitle)
> >>> If SetForegroundWindow(ipHandle) <> 0 Then
> >>> intErrCode = 0
> >>> End If
> >>>
> >>> Return intErrCode
> >>> End Function
> >>>
> >>> End Class
> >>>
> >>> 3) Build this project creating API_Library.dll
> >>>
> >>> 4) Create a PocketPC 2003 Class library and call it VIbaseclasses.
> >>> 5) Add a form to the project
> >>> 6) rename the form frmBase
> >>> 7) drop two buttons on the form leaving the default names.
> >>> 8) paste the following code into the form frmBase
> >>>
> >>> Public Class frmBase
> >>> Protected Overridable Sub Button1_Click(ByVal sender As
> >>> System.Object,
> >>> ByVal e As System.EventArgs) Handles Button1.Click
> >>> MsgBox("frmbase - button1 clicked")
> >>> 'Dim objSwapper As New API_Library.AppSwapper
> >>> 'objSwapper.BringAppToFront("Test")
> >>>
> >>> End Sub
> >>> Protected Overridable Sub Button2_Click(ByVal sender As
> >>> System.Object,
> >>> ByVal e As System.EventArgs) Handles Button2.Click
> >>> MsgBox("frmbase - button2 clicked")
> >>> End Sub
> >>> End Class
> >>>
> >>> 9) Add a referenece to API_Library.dll created earlier.
> >>> 10) Build this project creating VIbaseclasses.dll
> >>>
> >>> 11) Create a PocketPC 2003 device application and call it VItest.
> >>> 12) Add a form to the project leaving it at the default name
> >>> 13) Add a referenece to VIbaseclasses.dll created earlier.
> >>> 14) Build the project
> >>>
> >>> 15) Exit the project and locate the folder containg the VITest project.
> >>> 16) using a text editor, edit the file Form1.Designer.vb and change the
> >>> line
> >>> Inherits System.Windows.Forms.Form to Inherits VIbaseclasses.frmBase.
> >>> 17) save the file and re-open the VITest project. The form should
> >>> appear as
> >>> expected showing the inherited buttons.
> >>>
> >>> 18) re-open the VIbaseclasses project and un-comment the lines in the
> >>> Button1_Click subroutine refering to the variable objSwapper.
> >>> 19) save the file and re-build VIbaseclasses project.
> >>>
> >>> 20) re-open the VItest project and open the Form1 designer. You will
> >>> get
> >>> the "Visual inheritance is currently disabled message..." with no
> >>> buttons
> >>> from the inherited form.
> >>>
> >>> --
> >>> Tony Hudson
> >>>
> >>>
> >>> "Daniel Moth" wrote:
> >>>
> >>> > Can you post a repro?
> >>> >
> >>> > Cheers
> >>> > Daniel
> >>> > --
> >>> > http://www.danielmoth.com/Blog/
> >>> >
> >>> > "Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in message
> >>> > news:0678E4C6-C0C2-4D52-8EA9-8D52211F8689@microsoft.com...
> >>> > > Its a bug in VS2005 beta 2 that is not going to be fixed in the
> >>> > > first
> >>> > > official release and it is causing me big problems. I have taken
> >>> > > the
> >>> > > P/invoke references out of the base class form and exposed the
> >>> > > functionality
> >>> > > through a DLL class library that is called by the base class form
> >>> > > and it
> >>> > > still does not allow it. I need to find a workaround.
> >>> > >
> >>> > > --
> >>> > > Tony Hudson
> >>> > >
> >>> > >
> >>> > > "<ctacke/>" wrote:
> >>> > >
> >>> > >> So why can't you use P/Invoke? Visual inheritance has nothing to
> >>> > >> do with
> >>> > >> it.
> >>> > >>
> >>> > >> -Chris
> >>> > >>
> >>> > >>
> >>> > >> "Tony Hudson" <TonyHudson@discussions.microsoft.com> wrote in
> >>> > >> message
> >>> > >> news:6A7F8EF4-7AF9-4534-95A8-447A12B2AC81@microsoft.com...
> >>> > >> > Hi people,
> >>> > >> >
> >>> > >> > I have a suite of applications developed for a mobile device
> >>> > >> > using
> >>> > >> > VS2005
> >>> > >> > Beta 2 and the .NET compact framework. The applications need to
> >>> > >> > be
> >>> > >> > capable
> >>> > >> > of
> >>> > >> > bringing each other to the front of the Z order. Problem is I
> >>> > >> > cant use
> >>> > >> > P/invoke routines to do a FindWindow() and then
> >>> > >> > SetForegroundWindow()
> >>> > >> > due
> >>> > >> > to
> >>> > >> > the application forms being derived from a base class form and
> >>> > >> > visual
> >>> > >> > inheritance with P/Invoke will not work.
> >>> > >> >
> >>> > >> > Is there an alternative way of doing this in managed code?
> >>> > >> >
> >>> > >> > Thanks.
> >>> > >> >
> >>> > >> > --
> >>> > >> > Tony Hudson
> >>> > >>
> >>> > >>
> >>> > >>
> >>> >
> >>> >
> >>> >
> >
> >
>
>
>