Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8313833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:37:33+00:00 2026-06-08T20:37:33+00:00

In VS2008, I add a Resource Dictionary template in my solution, I named this

  • 0

In VS2008, I add a Resource Dictionary template in my solution, I named this template as “MyWinStyle.xaml”.
Below is the style used in my window:

……

<!--Window Template-->
<ControlTemplate x:Key="MyWindowTemplate" TargetType="{x:Type Window}">
.....
</ControlTemplate>

<!--Window Style-->
<Style x:Key="MacWindowStyle" TargetType="Window">
    ....
    <Setter Property="Template" Value="{StaticResource MyWindowTemplate}" />
</Style>

</ResourceDictionary>

this is my XMAL code, when I want to add the function to make the ownerdraw window resizable, I encounter a problem, that is, I can’t get the Window Object in its constructor.(based on this article, I want to make my window resizable: http://blog.kirupa.com/?p=256)
below is my code:

public partial class MyStyledWindow : ResourceDictionary
{
    private const int WM_SYSCOMMAND = 0x112;
    private HwndSource hwndSource;
    IntPtr retInt = IntPtr.Zero;

    public MacStyledWindow()
    {
        InitializeComponent();
        /**
         **Would anyone suggest on this? I can't get window object
         **/
Window.SourceInitialized += new EventHandler(MainWindow_SourceInitialized);
    }

    private void MainWindow_SourceInitialized(object sender, EventArgs e)
    {
        hwndSource = PresentationSource.FromVisual((Visual)sender) as HwndSource;
        hwndSource.AddHook(new HwndSourceHook(WndProc));
    }

    private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        Debug.WriteLine("WndProc messages: " + msg.ToString());
        //
        // Check incoming window system messages
        //
        if (msg == WM_SYSCOMMAND)
        {
            Debug.WriteLine("WndProc messages: " + msg.ToString());
        }

        return IntPtr.Zero;
    }

    public enum ResizeDirection
    {
        Left = 1,
        Right = 2,
        Top = 3,
        TopLeft = 4,
        TopRight = 5,
        Bottom = 6,
        BottomLeft = 7,
        BottomRight = 8,
    }

    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

    private void ResizeWindow(ResizeDirection direction)
    {
        SendMessage(hwndSource.Handle, WM_SYSCOMMAND, (IntPtr)(61440 + direction), IntPtr.Zero);
    }

    private void ResetCursor(object sender, MouseEventArgs e)
    {
        var window = (Window)((FrameworkElement)sender).TemplatedParent;
        if (Mouse.LeftButton != MouseButtonState.Pressed)
        {
            window.Cursor = Cursors.Arrow;
        }
    }

    private void Resize(object sender, MouseButtonEventArgs e)
    {
        Rectangle clickedRectangle = sender as Rectangle;
        var window = (Window)((FrameworkElement)sender).TemplatedParent;
        switch (clickedRectangle.Name)
        {
            case "top":
                window.Cursor = Cursors.SizeNS;
                ResizeWindow(ResizeDirection.Top);
                break;
            case "bottom":
                window.Cursor = Cursors.SizeNS;
                ResizeWindow(ResizeDirection.Bottom);
                break;
            case "left":
                window.Cursor = Cursors.SizeWE;
                ResizeWindow(ResizeDirection.Left);
                break;
            case "right":
                window.Cursor = Cursors.SizeWE;
                ResizeWindow(ResizeDirection.Right);
                break;
            case "topLeft":
                window.Cursor = Cursors.SizeNWSE;
                ResizeWindow(ResizeDirection.TopLeft);
                break;
            case "topRight":
                window.Cursor = Cursors.SizeNESW;
                ResizeWindow(ResizeDirection.TopRight);
                break;
            case "bottomLeft":
                window.Cursor = Cursors.SizeNESW;
                ResizeWindow(ResizeDirection.BottomLeft);
                break;
            case "bottomRight":
                window.Cursor = Cursors.SizeNWSE;
                ResizeWindow(ResizeDirection.BottomRight);
                break;
            default:
                break;
        }
    }

    private void DisplayResizeCursor(object sender, MouseEventArgs e)
    {
        Rectangle clickedRectangle = sender as Rectangle;
        var window = (Window)((FrameworkElement)sender).TemplatedParent;
        switch (clickedRectangle.Name)
        {
            case "top":
                window.Cursor = Cursors.SizeNS;
                break;
            case "bottom":
                window.Cursor = Cursors.SizeNS;
                break;
            case "left":
                window.Cursor = Cursors.SizeWE;
                break;
            case "right":
                window.Cursor = Cursors.SizeWE;
                break;
            case "topLeft":
                window.Cursor = Cursors.SizeNWSE;
                break;
            case "topRight":
                window.Cursor = Cursors.SizeNESW;
                break;
            case "bottomLeft":
                window.Cursor = Cursors.SizeNESW;
                break;
            case "bottomRight":
                window.Cursor = Cursors.SizeNWSE;
                break;
            default:
                break;
        }
    }

    private void Drag(object sender, MouseButtonEventArgs e)
    {
        var window = (Window)((FrameworkElement)sender).TemplatedParent;
        window.DragMove();
    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:37:34+00:00Added an answer on June 8, 2026 at 8:37 pm

    Why are you using ResourceDictionary as a base class for your window? Change your base class to Window and you’ll be able to subscribe to SourceInitialized event. That is:

        public partial class MyStyledWindow : Window
        {
        //other code
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Aloha I have a VS2008 solution to which I want to add a webservice
I am using VS2008 with QT 4.7.1 and add-ins. I am new to this
When you add (for example) WPF window to your project VS creates .xaml and
I converted a solution from VS2008/.NET 3.5 to VS 2010/.NET 4. I'm getting this:
How do I add Prolog DLLs to VS2008 in order to embed Prolog within
Is there any add-in for VS2008 Pro that provides me the ability to expand
How do I add: pl\bin to my VS2008 PATH? I read in a forum
i am trying to create word 2007 add-in using VS2008, and i need to
I've added as wsdl file using the add servece reference dialog in vs2008. MyService
In VS2008 just before a method if you add /// it automatically adds the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.