Is there a way to remove the border/frame (the Aero bit) of another application's window (say notepad) from a VB.NET program?
相关问题
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
- Should I use static function in c# where many call
You can do that using P-Invoke. Below is some code which uses SetWindowLong (in User32.dll) to change the border of the main window of notepad. (This code assumes that you have an instance of notepad running.) You can experiment with different window styles to achieve the result you want.
GWL_STYLE is for basic window styles. You can read about them here.
GWL_EXSTYLE is for extended window styles. You can read about them here.
Explanation of the code
I'm not sure how much experience you have in developing GUI applications, so I'll give a little background on how a window works. A window has a uniquely identifying number called a handle. Also associated with the window is a window procedure, which handles messages (integer numbers that identify events and commands) for that window. When a window is created, you specify what styles you want the window to have, etc. There's a lot more complexity to windows applications, but to avoid getting bogged down in the details we'll move on.
Thankfully, .NET Winforms isolates us from having to interact with the Windows API and handle messages directly (for the most part) and makes it very easy to create functional GUI applications. There is a lot more power under the hood in the Windows API that most .NET developers don't usually need to worry about.
Now with that background, the code should be a little easier to understand.
First off we need to get the first process named "notepad".
Then we define two integers
GWL_STYLE
andGWL_EXSTYLE
. These two integers will have a specific meaning in context of theSetWindowLong
function. Their value (and the value of many other constants) can be found in Winuser.h and the rest of the header files in the Windows SDK.Next we get the handle of the notepad's main window.
After that we encounter the GetWindowLong function. From MSDN:
GetWindowLong
takes the window handle and a value indicating what information to retrieve and returns the specified information.These were included so you could see what styles were applied to the window, so you could determine which styles to leave out.
Next we define what we styles we want to apply to the window. You can read about the various styles and their meanings here.
Then we apply those styles to the window using SetWindowLong. From MSDN:
SetWindowLong
takes the window handle, a value indicating what attribute to change, and the new value of the attribute, and changes the attribute.That's basically what the code does. To avoid repetition, I will not go over
GWL_EXSTYLE
since it is used exactly the same way asGWL_STYLE
. The rest of the code is just logistics to allow us to useSetWindowLong
andGetWindowLong
.