none
How to size a wpf window hosted in a winforms application... RRS feed

  • Question

  • Hi to all,
    I've a question.
    I've the need to size a wpf window, hosted in a winform application with a size greater than screen size limit.
    I've tried the code below proposed but it doesn't go.

    System.Windows.SystemParameters.PrimaryScreenWidth System.Windows.SystemParameters.PrimaryScreenHeight
    
    Dim screenW As Double = System.Windows.SystemParameters.PrimaryScreenWidth 
    Dim screenH As Double = System.Windows.SystemParameters.PrimaryScreenHeight 
    
    'Resize 
    wpfwindow.Width = screenW + 220D 
    wpfwindow.Height = screenH + 500

    So, i 've tried too this code that in winforms application is a good solution for this issue.

    Public Declare Function MoveWindow Lib "User32.dll" (ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal w As Integer, ByVal h As Integer, ByVal Repaint As Boolean) As Boolean
    
    Dim WPFWH As New WindowInteropHelper(wpfwindow)
    Dim Result As Boolean = MoveWindow(WPFWH.Handle, -300, wpfwindow.Top, 1800, 2500, True)
    
    
    But for wpf windows doesn't go...

    Thank in advance for the help.
    Genko


    Wednesday, September 10, 2014 12:08 PM

Answers

  • Oups ... sorry

    On a WPF window:

    Imports System.Runtime.InteropServices Imports System.Windows.Interop Class MainWindow Private Sub Button_Click(sender As Object, e As RoutedEventArgs) SetLargeWindowSize(Me, New Size(3000, 300)) End Sub Private Sub SetLargeWindowSize(F As Window, Sz As Size) SetWindowPos(New WindowInteropHelper(F).Handle, 0, 0, 0, Sz.Width, Sz.Height, 2 Or 4) End Sub Protected Overrides Sub OnSourceInitialized(e As EventArgs) MyBase.OnSourceInitialized(e) Dim source As HwndSource = PresentationSource.FromVisual(Me) source.AddHook(AddressOf WndProc) End Sub Private Function WndProc(hwnd As IntPtr, msg As Integer, wParam As IntPtr, lParam As IntPtr, ByRef handled As Boolean) As IntPtr If msg = &H24 Then Dim MinMax As MINMAXINFO = CType(Marshal.PtrToStructure(lParam, GetType(MINMAXINFO)), MINMAXINFO) If (MinMax.ptMaxSize.X > 0) Then MinMax.ptMaxSize.X = 60000 MinMax.ptMaxSize.Y = 60000 MinMax.ptMaxTrackSize.X = 60000 MinMax.ptMaxTrackSize.Y = 60000 Marshal.StructureToPtr(MinMax, lParam, True) End If End If Return IntPtr.Zero End Function

    Private Declare Function SetWindowPos Lib "User32" (hWnd As IntPtr, After As IntPtr, X As Integer, Y As Integer, cx As Integer, cy As Integer, Flag As UInteger) As Boolean <StructLayout(LayoutKind.Sequential)> Structure tag_POINT Dim X As Integer Dim Y As Integer End Structure

    <StructLayout(LayoutKind.Sequential)> Structure MINMAXINFO Dim ptReserverd As tag_POINT Dim ptMaxSize As tag_POINT Dim ptMaxPosition As tag_POINT Dim ptMinTrackSize As tag_POINT Dim ptMaxTrackSize As tag_POINT End Structure End Class




    • Proposed as answer by Reed KimbleMVP, Moderator Wednesday, September 10, 2014 9:11 PM
    • Edited by Crazypennie Thursday, September 11, 2014 9:13 AM 321564
    • Marked as answer by _Genko_ Thursday, September 11, 2014 3:38 PM
    Wednesday, September 10, 2014 5:25 PM

All replies

  • One more thing, i've just discovered....

    after the show request...the size of the wpf window (if greater than screen size) is resized to screen size....

    This is the reason because my wpf window is never greater than screen size...but what is the reason of this resize action?

    Wednesday, September 10, 2014 12:54 PM
  • Windows do limits the size of any windows to 16 pixels wider, or higher than the screen size.

    The only way to get a window larger is to trick the OS like this

    Imports System.Runtime.InteropServices
    
    Public Class Form1
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            SetLargeWindowSize(Me, New Size(3000, 300))
        End Sub
    
        Private Sub SetLargeWindowSize(F As Form, Sz As Size)
            SetWindowPos(F.Handle, 0, 0, 0, Sz.Width, Sz.Height, 2 Or 4)
        End Sub
    
    
    
    
        Protected Overrides Sub WndProc(ByRef m As Message)
            If m.ToString().Contains("WM_GETMINMAXINFO") Then
                Dim MinMax As MINMAXINFO = CType(Marshal.PtrToStructure(m.LParam, GetType(MINMAXINFO)), MINMAXINFO)
                If (MinMax.ptMaxSize.X > 0) Then
                    MinMax.ptMaxSize.X = 60000
                    MinMax.ptMaxSize.Y = 60000
                    MinMax.ptMaxTrackSize.X = 60000
                    MinMax.ptMaxTrackSize.Y = 60000
                    Marshal.StructureToPtr(MinMax, m.LParam, True)
                End If
            End If
            MyBase.WndProc(m)
        End Sub
    
        Private Declare Function SetWindowPos Lib "User32" (hWnd As IntPtr, After As IntPtr, X As Integer, Y As Integer, cx As Integer, cy As Integer, Flag As UInteger) As Boolean
    
        <StructLayout(LayoutKind.Sequential)>
        Structure tag_POINT
            Dim X As Integer
            Dim Y As Integer
        End Structure
    
        <StructLayout(LayoutKind.Sequential)>
        Structure MINMAXINFO
            Dim ptReserverd As tag_POINT
            Dim ptMaxSize As tag_POINT
            Dim ptMaxPosition As tag_POINT
            Dim ptMinTrackSize As tag_POINT
            Dim ptMaxTrackSize As tag_POINT
        End Structure
    
    End Class

    Wednesday, September 10, 2014 4:25 PM
  • Oups ... sorry

    On a WPF window:

    Imports System.Runtime.InteropServices Imports System.Windows.Interop Class MainWindow Private Sub Button_Click(sender As Object, e As RoutedEventArgs) SetLargeWindowSize(Me, New Size(3000, 300)) End Sub Private Sub SetLargeWindowSize(F As Window, Sz As Size) SetWindowPos(New WindowInteropHelper(F).Handle, 0, 0, 0, Sz.Width, Sz.Height, 2 Or 4) End Sub Protected Overrides Sub OnSourceInitialized(e As EventArgs) MyBase.OnSourceInitialized(e) Dim source As HwndSource = PresentationSource.FromVisual(Me) source.AddHook(AddressOf WndProc) End Sub Private Function WndProc(hwnd As IntPtr, msg As Integer, wParam As IntPtr, lParam As IntPtr, ByRef handled As Boolean) As IntPtr If msg = &H24 Then Dim MinMax As MINMAXINFO = CType(Marshal.PtrToStructure(lParam, GetType(MINMAXINFO)), MINMAXINFO) If (MinMax.ptMaxSize.X > 0) Then MinMax.ptMaxSize.X = 60000 MinMax.ptMaxSize.Y = 60000 MinMax.ptMaxTrackSize.X = 60000 MinMax.ptMaxTrackSize.Y = 60000 Marshal.StructureToPtr(MinMax, lParam, True) End If End If Return IntPtr.Zero End Function

    Private Declare Function SetWindowPos Lib "User32" (hWnd As IntPtr, After As IntPtr, X As Integer, Y As Integer, cx As Integer, cy As Integer, Flag As UInteger) As Boolean <StructLayout(LayoutKind.Sequential)> Structure tag_POINT Dim X As Integer Dim Y As Integer End Structure

    <StructLayout(LayoutKind.Sequential)> Structure MINMAXINFO Dim ptReserverd As tag_POINT Dim ptMaxSize As tag_POINT Dim ptMaxPosition As tag_POINT Dim ptMinTrackSize As tag_POINT Dim ptMaxTrackSize As tag_POINT End Structure End Class




    • Proposed as answer by Reed KimbleMVP, Moderator Wednesday, September 10, 2014 9:11 PM
    • Edited by Crazypennie Thursday, September 11, 2014 9:13 AM 321564
    • Marked as answer by _Genko_ Thursday, September 11, 2014 3:38 PM
    Wednesday, September 10, 2014 5:25 PM
  • Thank Crazypennie,

    I've seen your code and in the call SetLargeWindowSize the argument F is a form, instead i want set a size greater than the screen size of a wpf windows.

    Wednesday, September 10, 2014 5:30 PM
  • Look just before your post, I posted a code revised code for WPF


    • Edited by Crazypennie Wednesday, September 10, 2014 5:50 PM 213654
    Wednesday, September 10, 2014 5:49 PM
  • I 've tried the code andit goes :)

    One last question...

    This code can be used in every platform (windows)?

    Many thanks.

    Genko

    Thursday, September 11, 2014 3:41 PM
  • I 've tried the code andit goes :)

    One last question...

    This code can be used in every platform (windows)?

    Many thanks.

    Genko

    It will work on any platform, ... however, I wouldn't suggest to make a Windows Store App window larger than the screen.
    Thursday, September 11, 2014 4:09 PM
  •  Thank for the suggestion, but it's not into the my intentions :)
    Friday, September 12, 2014 3:21 PM