Re: Resize 3rd Party Application
Code:
Public Class Form1
Const LWA_COLORKEY As Int32 = 1
Const LWA_ALPHA As Int32 = 2
Const GWL_EXSTYLE As Int32 = (-20)
Const WS_EX_LAYERED As Int32 = 524288
Private Declare Function apiGetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Int32, ByVal nIndex As Int32) As Int32
Private Declare Function apiSetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Int32, ByVal nIndex As Int32, ByVal dwNewLong As Int32) As Int32
Private Declare Function apiSetLayeredWindowAttributes Lib "user32" Alias "SetLayeredWindowAttributes" (ByVal hWnd As Int32, ByVal crKey As Int32, ByVal bAlpha As Byte, ByVal dwFlags As Int32) As Int32
Dim nhwnd As Int32
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim p As New System.Diagnostics.Process
p = Process.Start("notepad")
p.WaitForInputIdle()
nhwnd = p.MainWindowHandle.ToInt32
TrackBar1.Maximum = 255
TrackBar1.Value = 100
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Transparency(nhwnd, 100) 'Set transparency to 100, or anywhere between 0-255. Use a trackbar if you want.
End Sub
Private Sub Transparency(ByVal hwnd As Int32, ByVal sOpacity As Int32)
Dim Ret As Int32 = apiGetWindowLong(hwnd, GWL_EXSTYLE) 'Set the window style to 'Layered'
Ret = Ret Or WS_EX_LAYERED
apiSetWindowLong(hwnd, GWL_EXSTYLE, Ret)
apiSetLayeredWindowAttributes(hwnd, 0, sOpacity, LWA_ALPHA) 'Set the opacity of the layered window
End Sub
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
Transparency(nhwnd, TrackBar1.Value)
End Sub
End Class
first of all im sorry for bringing up an old topic
im new at vb and rly dont know how to do this with an already started application
could somebody rewrite it to make it work with and already started application?
Re: Resize 3rd Party Application
Code:
Public Class Form1
Const LWA_COLORKEY As Int32 = 1
Const LWA_ALPHA As Int32 = 2
Const GWL_EXSTYLE As Int32 = (-20)
Const WS_EX_LAYERED As Int32 = 524288
Private Declare Function apiGetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Int32, ByVal nIndex As Int32) As Int32
Private Declare Function apiSetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Int32, ByVal nIndex As Int32, ByVal dwNewLong As Int32) As Int32
Private Declare Function apiSetLayeredWindowAttributes Lib "user32" Alias "SetLayeredWindowAttributes" (ByVal hWnd As Int32, ByVal crKey As Int32, ByVal bAlpha As Byte, ByVal dwFlags As Int32) As Int32
Private Declare Function apiFindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32
Dim nhwnd As Int32 = 0 'Handle of window
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TrackBar1.Maximum = 255
TrackBar1.Value = 100
nhwnd = Me.Handle.ToInt32 'Set handle to this application
'Or uncomment, and insert any application title below
'nhwnd = apiFindWindow(Nothing, "Application Title Here")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Transparency(nhwnd, 100) 'Set transparency to 100, or anywhere between 0-255. Use a trackbar if you want.
End Sub
Private Sub Transparency(ByVal hwnd As Int32, ByVal sOpacity As Int32)
Dim Ret As Int32 = apiGetWindowLong(hwnd, GWL_EXSTYLE) 'Set the window style to 'Layered'
Ret = Ret Or WS_EX_LAYERED
apiSetWindowLong(hwnd, GWL_EXSTYLE, Ret)
apiSetLayeredWindowAttributes(hwnd, 0, sOpacity, LWA_ALPHA) 'Set the opacity of the layered window
End Sub
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
Transparency(nhwnd, TrackBar1.Value)
End Sub
End Class
Re: Resize 3rd Party Application
Thanks!
1 more question
can i pick the window by process name instead of form name?
Re: Resize 3rd Party Application
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
nhwnd = HandleFromProcessName("Running process name here")
TrackBar1.Maximum = 255
TrackBar1.Value = 100
End Sub
Private Function HandleFromProcessName(ByVal pName As String) As Int32
For Each p As Process In Process.GetProcesses
If p.ProcessName = pName Then HandleFromProcessName = p.MainWindowHandle.ToInt32
Next
End Function
Re: Resize 3rd Party Application
hehe tyvm again
and is there any other way to make it trasparent but without using apis?
Re: Resize 3rd Party Application
I don't think so.
If there is a way in .NET, then it's not very well known.
Re: Resize 3rd Party Application
There is no way IMHO, that there is a non - API solution to making a third party window transparant.
Re: Resize 3rd Party Application
as i tought, anyway thanks for helping me out
P.S. doesnt work with every application
Re: Resize 3rd Party Application
Quote:
P.S. doesnt work with every application
I'm sure it doesn't.
However, there are several possible reasons.
A. The application is doing a custom paint operation, or it's non regular window form.
Not much you can do about that without going way overboard.
B. The process loop is not obtaining the correct main window handle(or common zero .net bug).
In which case you have to use a bunch more API for getting the process information.
It would be more reliable, but still not failsafe.
However, you would get almost all windows covered.
I use API for this usually.
C. You've simply used it wrong, and the handle is zero.
D. Your reply may have meant, that not all applications(processes) with the same name become transparent.
If so, you can extend that so that all processes with the same name get the transparency applied.
E. Other
_
Re: Resize 3rd Party Application
Quote:
Originally Posted by
TT(n)
A. The application is doing a custom paint operation
this is the reason why it doesnt work with the application which i want to make trasparent
also noticed that it doesnt work well with the applications which have a 3D render field like 3DS max or 3D games
Re: Resize 3rd Party Application
DirectX draws directly into memory on the GPU, not the screen buffer area. It gets to the screen buffer automagically. You can't intercept that