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
-Chris
"Tony Hudson" <TonyH...@discussions.microsoft.com> wrote in message
news:6A7F8EF4-7AF9-4534...@microsoft.com...
--
Tony Hudson
Cheers
Daniel
--
http://www.danielmoth.com/Blog/
"Tony Hudson" <TonyH...@discussions.microsoft.com> wrote in message
news:0678E4C6-C0C2-4D52...@microsoft.com...
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
You managed to look into or duplicate this?
--
Tony Hudson
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" <TonyH...@discussions.microsoft.com> wrote in message
news:64E63E63-B5D3-4053...@microsoft.com...
- 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" <dmo...@hotmail.com> wrote in message
news:e3TpDmiu...@TK2MSFTNGP10.phx.gbl...