-2

I was working on a project using WPF, I want to modify the MainWindow to have some extended window styles. I have referred some docs and found out that I can set the window styles using SetWindowLong(), but in my case it will not work because I am trying to use WS_EX_NOREDIRECTIONBITMAP as the extended window style. when I use SetWindowLong() it does nothing. I have read somewhere that WS_EX_NOREDIRECTIONBITMAP can only be set while creating the window. So is there any way that i could modify the CreateWindowEx() of the WPF MainWindow.

I have found another alternate method to achieve this but it is by using the Undocumented API function.(SetWindowCompositionAttribute()). I need my project to be stable so is there any other method to achieve this?

If SetWindowCompositionAttribute() can set WS_EX_NOREDIRECTIONBITMAP at runtime, there must be a workaround to do this.

Here is the screenshot of what i want to achieve :

Sample Image

It is possible to do it in C++ but in C# WPF i haven't found a way to do this.

trickymind
  • 557
  • 5
  • 21
  • You can't use an existing "managed" desktop 15-years old UI frameworks such as Winforms or WPF and do your own low-level stuff with it. Either you use them because they're relatively easy to program (and suffer their true lack of modernity with regards with today's Windows technologies, ie: Direct Composition or Windows.UI.Composition, DirectX, etc) or go and write your own Win32 desktop stuff where you have access to everything. In theory, WinUI3 (https://learn.microsoft.com/en-us/windows/apps/winui/winui3/) will fill the gap, but it's not there yet and details are uncertain. – Simon Mourier Jan 24 '21 at 08:39
  • What specifically would you want the window to do/look like after changing it? – o_w Jan 24 '21 at 09:11
  • @o_w There's only one reason why you would want to use the `WS_EX_NOREDIRECTIONBITMAP` window style: It prevents the system from allocating a redirection bitmap for cases where you don't need it. [This Q&A](https://stackoverflow.com/q/49380566/1889329) provides more information. – IInspectable Jan 24 '21 at 10:34
  • Using WS_EX_NOREDIRECTIONBITMAP will create a window without loosing it's shadow. since the WPF uses DirectX to render controls the redirection surface is not required. i have tried it. the WPF was able to draw to a window with WS_EX_NOREDIRECTIONBITMAP (i used undocumented api). the DWMExtendFrameIntoClient Area will produce a black border if i set all the margins below 11 so if i use WS_EX_NOREDIRECTIONBITMAP this problem is solved and that's why i need it – trickymind Jan 25 '21 at 07:17
  • and i don't know why everyone is down voting, i have explained as much as i can. I was not able to add any codes because i don't know what I will add there. all i just want to do is a blank wpf window with WS_EX_NOREDIRECTIONBITMAP. – trickymind Jan 25 '21 at 07:21

1 Answers1

1

If you want to set WS_EX_NOREDIRECTIONBITMAP during creating MainWindow then you can create MainWindow manually. Just remove StartupUri from App.xaml and create new event handler for Startup event.

<Application x:Class="WpfApp1.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         Startup="App_Startup">

App.xaml.cs

void App_Startup(object sender, StartupEventArgs e)
{
    // replace with your code
    MainWindow window = new MainWindow();
    window.Show();
}

But it would be useful if you can shore more code.

user2250152
  • 14,658
  • 4
  • 33
  • 57