Window opacity not being effected in a method?
Hello, I've been trying to change the opacity of my window through code for a while now but I've had no success. I'm changing the
Window.Opacity
number in my function but I've had no success. As of now, I've tried setting the background to a SolidBrushColor
and setting the opacity from there to no success. I'm also trying INotifyPropertyChanged
still to no avail. There are no errors either. The opacity just isn't affected. Here is the code of the overlay window that needs its opacity changed:
Tell me if you would like to see any XAML code or MainWindow.cs.259 Replies
@Ero sorry for the delay but here is the code.
tell me if you want to see any more
Here is the XAML:
well if you want to do some interop there is the method
SetLayeredWindowAttributes
an other one is the undocumented SetWindowCompositionAttribute
(i cant really recommend this one)
tl;dr: windows doesnt like transparent windows unless its an uwp window?Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
What should I set to public?
I've added
DataContext=this;
to my code and it sorta worked.
The opacity is now set here
this works
but I still am not able to change the opacity during runtime
Im passing this
as the parameterYou shouldn't be setting that in code
They specifically said to insert that into the xaml
Really?
What should I be inserting into xaml?
try inserting this XAML after xmlns:local DataContext="{Binding RelativeSource={RelativeSource Self}}"
Oh I already did
lemme remove the defenition in code
(affected)
I still don't know the difference 💀
Still nothing :(
Lemme test something real quick
Something is affected by something else. You will almost never use effected.
ok thx lol
btw @Ero
I did some testing. Something is wrong with my opacity
idk what
maybe its a property I set
What does this program do exactly...?
Its a button that turns another transparent window opaque
Supposed to be really simple
no the entire program
either way i can't repro this. works fine for me
Can you send me some code please?
Im using pinvoke to create that window if that helps
Not sure if this helps at all but here
why... do you do this exactly...?
To make that window not interactable
but honestly since i suspect that this is a cheat for csgo, i'm not sure i will help much more
You're not the first lol
I'm making an app to flashbang users randomly lol
kinda worse?
Its not malicious
It can be closed
and you open it yourself
its just for fun
ws_ex_transparent makes a window transparent for clicks not visibly
Ik. Thats exactly the point
okay good
I have a feeling that that might be whats causing the problem though
<:PES_Think:639363477458255874>
i have an idea
so click-through, essentially
Yep
Also why are overlays always expected to be cheats?
make a white layered window, make it see trough with setlayerdwindowattributes and to do the flash make it opaque again
Wait so you want me to make another window?
idk
id do all of this with the win32 api and not in wpf
or whatever this is
Isnt that in C++?
you can use it in c# too
oh
I might use Win32 API as a last resort
or you do the interop manually or you use a nuget pqckage ti generate it for you
like terrafx or cswin32
someone recommended a overlay library to me
that I don't want to use but it seems like I might have to
That sounds extremely complicated for an app that is supposed to be really simple.
just a flash bang?
id say 50-100 lines of code (in the whole project) when using win32 depending on how you do it
Thats what I thought too lmao
Do you have a tutorial on using Win32 with Cs?
i always say id make one but i dont
you rigister the window class, then create a window, pump handle its messages, maybe use a timer to do the flashes on an interval
Ok...
Win32 Is usually used with C++ though right?
c/c++
in an unsafe c# context you can basically write c code (its still c# but you know what i mean)
writing the interop yourself is too much work
thats why i usually use cswin32 to generate it for me
but if you use terrafx it also has classes to create win32 windows with directx or vulkan graphics
Ok and what difference does pinvoke and cswin32 have?
nothing really, the difference is it writes the pinvoke code for you
GitHub
GitHub - microsoft/CsWin32: A source generator to add a user-define...
A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project. - GitHub - microsoft/CsWin32: A source generator to add a user-defined set of Win32 P/In...
ofc idk how well you know the win32 api
it can be quite a steep learning curve to create a simple window
how about a white top most maximized borderless window you just minimiza and maximize to do the solution no?
bruh it look bad lol
Also isn't that for winforms?
doesnt really matter which project
It mentions program.cs which is in winforms tho.
not wpf iirc.
you dont need a program.cs
just NativeMethods.json and NativeMethods.txt
Okay
Ill check this out in another project later
If thats easier
i usually put that nuget package in its own class library project thingy next to my actual project
ummmmmmmmmm
ok
@Jester So i just install CsWin32, add
NativeMethods.json
and NativeMethods.txt
, type methods that I want to use and copy and paste the method name into NativeMethods.txt
right?yup, put the config you want in the json and then the method names in the txt
Do you mind sending an example of adding the
WS_EX_TRANSPARENT
tag to the window?creating a window or an existing window?
CreateWindowExW(WS_EX_TRANSPARENT | ..., ...
Create window
I add this to NativeMethods.txt?
the method name
yes
RegisterClassW, CreateWindowExW, GetMessage, PostQuitMessage, DestroyWindow, DefWindowProc, DispatchMessage
you need at least these to create a working window
no
each on a new line
no comma
Ah ok
and any libs I should be importing?
nope
not explicit
ok
Windows.Win32.PInvoke.Create...
you will need a bunch of namespaces
Ummm
Oh
its not in here
is it meant to be>
you can find the file it generates somewhere in the solution explorer
?
under analyzers
oh okay its there
at least
good
a simple test is SetCursorPos
SetCursorPos(0, 0); should put your cursor in the left upper corner of your monitor
just checking, this is what my NativeMethods.json should look like right?
i set single file to true
and then there are a few other options
but looks good
And this is how NativeMethods.txt should look right?
yes
SetCursorPos doesn't exist in the current context
got the namespace? it might take a second for it to realise it got generated as well
Nope
Can I use more than 1 namespace at a time?
yes like any other namespace
using Windows.Win32;
using static Windows.Win32.Pinvoke;
etc
Ahhhhh
Lol I was doing it wrong
What namespace specifically should I be using?
it puts different headers across different namespaces
sonyou might have to look around
Ah ok
got it to work?
Yep!
lemme test it
nvm
This happened when building
The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?)
so did you put thr package in a class library project and this code in a console project or wpf?
WPF
you need to make a reference from this wpf project to that class library
Ok
what is the dir its installed in?
no
I cd'd into the project dir (the one the sln is in) and installed there
oh
right click and then add project reference i think
This window?
euh
can you show your project explorer
Sure
Oh is it in here?
i only see 1 project in your solution
OHHH
the class library project should be in the same solution to be simple
How do you add a class library to a sln?
right click on the solution ans then add new project
Class lib or WPF class lib?
normal class lib
I drop the NativeMethods in the class lib?
yes and install the nuget package in the class lib not in the wpf project
Ohhh
How do I remove it from the WPF project?
manage nuget uninstall
This window?
yes
its empty <:PES_Think:639363477458255874>
I didnt install VIA nuget
ohh
I installed through
dotnet add
uhhh
Whatever
Ill deal with that later
brb ill be gone for 30 min
@Jester Im back. I've imported the CsWin32 lib into the class library and added both NativeMethods. What do I do now?
add project reference from twitch to the classlib
Add the reference of twitch TO classlib?
just making sure
no the opposite
done
the namespaeces should work now
Is there anything I have to put in Class1.cs?
no you can remove that
So it should look like this yes?
yes
and by namespace, you mean
using Win32ClassLib;
?windows.win32?
Win32
The type or namespace name 'win32' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
oky
oh it works lmfao
This is still here
nearly there thoughh
in the pinvoke static class
PInvoke
Oh yea
using static Windows.Win32.PInvoke;
i forgot where it was lolah
yes
in the json there is an option to use public classes instead of internal
What is it?
or where do I find it?
in the website the json schema refers to
Okies.
Also whats the point of putting the library in a seperate class library?
well its easier to reuse the library in other projects i guess and in the earluer previews vs would become unusably laggy if you didnt do that
ok
Wtf is all of this?
It w
it kinda works
Idk what caused this tho
idk
:/
Is it okay to have the class lib inside the project?
Lemme try
i would think not but idk
IT WORKS
IM SUCH A GIGABRAIN IDIOT
Even the cursor moves!
lets goo
now this was the easy part
This is immensely epic
fuck
just a million of these docs to read
https://learn.microsoft.com/en-us/windows/win32/learnwin32/creating-a-window
Creating a Window - Win32 apps
Creating a Window
fuck me
so I can't just use
CreateWindowExW();
?
This is all in C++ :(with just this method you cant make a window
not sure why it leaves out the procedure and message pump
💀
you need at least all of these
I have them in the text file...
This is what I have to do right>
I assume you have to import
using static Windows.Win32.Foundation.HWND;
no it
using Windows.Win32.Foundation;
oky
ayy
And I create a window with these params?
yes thats the basic window
if you need some constants like WM_something you can also put those names in the txt
The name 'CreateWindowExW' does not exist in the current context
ok
It there another namespace?
there are
many
Okay...
Anything specifically that I need to insert to get
CreateWindowExW
it should be in the PInvoke class
all methods should be
hmmm
HWND hwnd = CreateWindowExW();
this is the line if it help
helpsyou need to pass the parameters
If i just put
WS_EX_TRANSPARENT
in the txt file will it be useable?yes but it might be turned into an enum thats in some namespace
the intellisense should show you that
:/
intellisense isnt showing me anything :/
Found it myself
yes it can struggle a little with the generated code
:/
Whats the second param?
look it up in the docs
they tell you all the details
class name apparently
that would just be
Window
right?
What is hInstance?
also for some reason CreateWindowExW
doesn't exist in the context but CreateWindowEx
does
are they the same?class name should be the same as the name in the windowclass you registered before doing create window
Ah
depending on your json it refers to the utf16 version(as c# strings) or ascii version
can be null
so
Window overlay;
i pass overlay
as a paramno
"overlay"
no?
WNDCLASS
its
name field
its in the docs i linked
okie dokie
well uuhhh
youre probably going to need an unsafe context and pointers
💀
thats what you get with C api's
Crap
yeah the syntax isnt exactly the same
that would be
fixed (char* className = too much for me to type i have stuff to do)
WNDCLASS wc = default;
This is for C#?
yes
because it says it cannot convert string to char
fixed statement - C# reference
Use the C# fixed statement to pin a moveable variable for the duration of the statement.
thats bcuz c# is managed
ohoh
in c# pointers are even more risky
<:PES_Cool:513334287198584834>
I havent even gotten around to learning them
close
unsafe context
hmmm
at the bottom of the docs there is a string example
here
the [] thats not a thing in c#
and the ; at the end
Okay. Even the example doesnt work
did you enable unsafe
probably not
lol
how would i do that?
properties of the project
yes
Its been on the whole time
<a:aPES_Think:493353113332219924>
then whats wrong
tell us the error?
mismatched {} it looks like to me
likely
What the fuck?
its fine
but when i add
unsafe {}
it freaks outthis thread will take a week
Honestly lol
You said a 100 lines
forgot to mention that every other word gives an error
You know what I might do
Ill try take another route at doing this
maybe make another branch
but ill keep learning Win32
cuz it seems useful
thats true
i made it sound easy
lol
im a win32 enjoyer
Are there any tutorials on this I can use so I can pester you less?
for c# probably not many
I wish but unfortunately, I have not enjoyed win32 lol
what about cpp? Is it worth learning or am I gonna end up dying myself?
well
personally i keep it C
i have no idea how to use the
std
if you're going low level, you might as well go the lowest level reasonably possible
which is c
I still dont know the difference lmao
do all the win32 stuff in a C dll and then interop that dll you made into C# you onky need a few easy calls inbetween
Literally just keep it at c lmao
i want someone to port .net to c
Isnt Win32 .Net?
win32 is from the ancient windows days long before c#
Oh
it's literal kernel stuff
So the neato stuff that WPF can do isnt on Win32
it all kinda builds upon win32
everything does, really
yea
Lol
kernel => win32 => basically anything on windows
@Jester Wait so can Win32 code be ported into WPF?
Like converted
not written in CS
idk what you mean
You know how I've kinda been writing C code in cs?
yes
you haven't
lol
Kinda
Idk how to explain it
you write c# code in c#
unsafe c# is quite c-ish
especially with interop
Is there a way to convert C code into C#?
id like to know
thst would be nice
ok :<
convert how?
you can write code that's equivalent, sure
also maybe look into clangsharp?
#allow-unsafe-blocks will know more
THATS A CHANNEL!?
Lmao okay ill look into it
thats a channel for nerds
lol