How to make invisible form when screen capture is running - c#

is there any one can help me?
i am creating a windows application in c#. and i want to make it invisible when i do screen recording. i mean, it will not record but i can use it.
i try displayaffinity
but this makes form black when record. but i want full invisible.
namespace WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll")]
public static extern uint SetWindowDisplayAffinity(IntPtr hwnd, uint dwAffinity);
private void Form1_Load(object sender, EventArgs e)
{
const uint WDA_NONE = 0;
const uint WDA_MONITOR = 1;
SetWindowDisplayAffinity(this.Handle, WDA_MONITOR);
}
}
}

Related

C# . How to take effect for regitstry edited Caret Width immediately?

I found a path for Caret Width in my registry: HKEY_USERS\S-1-5-21-1217365396-2387141574-3682890637-1001\Control Panel\Desktop. Value "CaretWidth" = 1. I want to change it for 5, for example.
But how take effect for this change immediately? I think need to use some method from pinvoke.net, but I don't know how do it. Can you help me?
You can use SystemParametersInfo and pass SPI_SETCARETWIDTH
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices; // Add
namespace Caret_Changer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
const int SPIF_UPDATEINIFILE = 0x01;
const int SPIF_SENDCHANGE = 0x02;
public const uint SPI_SETCARETWIDTH = 0x2007;
[DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, uint pvParam, uint fWinIni);
private void ChangeCaret(uint caret)
{
SystemParametersInfo(SPI_SETCARETWIDTH, 0, caret, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
}
// Start button
private void Button1_Click(object sender, EventArgs e)
{
ChangeCaret(0x0000005); // New caret width
}
// Stop Button
private void Button2_Click(object sender, EventArgs e)
{
ChangeCaret(0x0000001); // Return default width
}
}
}

Change Caret (Cursor) in Textbox in C#

I want to change the Caret in a Textbox in C# that it appears wider like in does in old DOS applications.
What i have:
Example what i want:
I tried:
using System.Runtime.InteropServices;
...
[DllImport("user32.dll")]
static extern bool CreateCaret(IntPtr hWnd, IntPtr hBitmap, int nWidth, int nHeight);
[DllImport("user32.dll")]
static extern bool ShowCaret(IntPtr hWnd);
...
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern bool CreateCaret(IntPtr hWnd, IntPtr hBitmap, int nWidth, int nHeight);
[DllImport("user32.dll")]
static extern bool ShowCaret(IntPtr hWnd);
public Form1()
{
InitializeComponent();
}
private void Form1_Shown(object sender, EventArgs e)
{
CreateCaret(textBox1.Handle, IntPtr.Zero, 20, textBox1.Height);
ShowCaret(textBox1.Handle);
}
}
But it still looks the same. Any help would be nice. Thanks in advance!
Edit:
This was just an example. My real code looks like:
TextBox textbox = new TextBox();
textbox.MaxLength = fieldLength;
textbox.Width = fieldLength*24;
textbox.MaxLength = maxChars;
this.Controls.Add(textbox);
CreateCaret(textbox.Handle, IntPtr.Zero, 20, textbox.Height);
ShowCaret(textbox.Handle);
The code gets called but doesnt change anything.
Edit2:
I tried the example and it works fine but my problem still exisits:
I cant change the Caret when creating the textbox. Its only possible for a textbox created with the form.
You didn't link the event correctly, you should change to :
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern bool CreateCaret(IntPtr hWnd, IntPtr hBitmap, int nWidth, int nHeight);
[DllImport("user32.dll")]
static extern bool ShowCaret(IntPtr hWnd);
public Form1()
{
InitializeComponent();
this.Shown += Form1_Shown;
}
private void Form1_Shown(object sender, EventArgs e)
{
CreateCaret(textBox1.Handle, IntPtr.Zero, 20, textBox1.Height);
ShowCaret(textBox1.Handle);
}
}
What is going on it seems is that the shown event will only initially work. When you leave the textbox by tabbing away and back to the control the caret will be reset by underlying code.
Take a look the answer in this thread.
I took their DrawDaret Method and changed it a bit. Calling DrawCaret on the textbox1.Enter event doesn't work. possibly the textbox implementation will notify the Enter event and then change the caret. This would undo a change done in the Enter event handler regarding to the caret.
EDIT
But the control also has a GotFocus event which you can use.
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern bool CreateCaret(IntPtr hWnd, IntPtr hBitmap, int nWidth, int nHeight);
[DllImport("user32.dll")]
static extern bool ShowCaret(IntPtr hWnd);
public Form1()
{
InitializeComponent();
textBox1.GotFocus += new EventHandler(textBox1_GotFocus);
}
void textBox1_GotFocus(object sender, EventArgs e)
{
DrawCaret(textBox1);
}
public void DrawCaret(Control ctrl)
{
var nHeight = 0;
var nWidth = 10;
nHeight = Font.Height;
CreateCaret(ctrl.Handle, IntPtr.Zero, nWidth, nHeight);
ShowCaret(ctrl.Handle);
}
}

Is it possible to disable the "close" button while still being able to close from elsewhere?

I have a winforms application where I want the close button in the top-right corner of the program to instead minimize the program.
I have been able to achieve this by using the form's FormClosing event like this:
this.Hide();
e.Cancel = true;
But this unfortunately also stops any other close buttons I place on the form.
Is there a way to only stop the default button in the top-right but still be able to close the form elsewhere?
This is a simple boolean example:
bool ExitApplication = false;
private void Form1_FormClosing(Object sender, FormClosingEventArgs e)
{
switch(ExitApplication)
{
case false:
this.Hide();
e.Cancel = true;
break;
case true:
break;
}
}
So when you want to close your application just set ExitApplication to true.
Use this to disable close button from your form at top right corner.
public partial class Form1 : Form
{
const int MfByposition = 0x400;
[DllImport("User32")]
private static extern int RemoveMenu(IntPtr hMenu, int nPosition, int wFlags);
[DllImport("User32")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[DllImport("User32")]
private static extern int GetMenuItemCount(IntPtr hWnd);
public Form1()
{
InitializeComponent();
var hMenu = GetSystemMenu(Handle, false);
var menuItemCount = GetMenuItemCount(hMenu);
RemoveMenu(hMenu, menuItemCount - 1, MfByposition);
...
}
}
Another way to disable the "X" in the top right:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
protected override CreateParams CreateParams
{
get
{
const int CS_NOCLOSE = 0x200;
CreateParams cp = base.CreateParams;
cp.ClassStyle |= CS_NOCLOSE;
return cp;
}
}
}
The form can still be closed programmatically with this.Close();.

Automate MapInfo with C#

Hi I'm developing an application that parsing data then after that I want to visualize some data on map using MapInfo, I made a MapInfo instance correctly but till now I do not know how to display data on the instance or how to use it also the instance I've created is not visible even after I make visible.
below is my code
namespace JA3_Trace_Viewer
{
public partial class JA3Main : Form
{
public JA3Main()
{
InitializeComponent();
}
private void JA3Main_Load(object sender, EventArgs e)
{
MapInfo.MapInfoApplication mapinfoinstance = new MapInfo.MapInfoApplication();
mapinfoinstance.Visible = true;
DDockWindow winM = new DDockWindow();
winM.Activate();
}
}
The data that I want to visualize on map is longitude and latitude and another columns lets call them data, so please if you help me.
Thanks in advance.
The new code:
public partial class Form1 : Form
{
// Sets the parent of a window.
[DllImport("User32", CharSet = CharSet.Auto, ExactSpelling = true)]
internal static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndParent);
//Sets window attributes
[DllImport("USER32.DLL")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
//Gets window attributes
[DllImport("USER32.DLL")]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
//assorted constants needed
public static int GWL_STYLE = -16;
public static int WS_CHILD = 0x40000000; //child window
public static int WS_BORDER = 0x00800000; //window with border
public static int WS_DLGFRAME = 0x00400000; //window with double border but no title
public static int WS_CAPTION= WS_BORDER | WS_DLGFRAME; //window with a title bar
public static int WS_MAXIMIZE = 0x1000000;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// Create a new instance of MapInfo.
MapInfoApplication mapinfo = new MapInfoApplication();
// Get the handle to the whole MapInfo application.
// 9 = SYS_INFO_MAPINFOWND.
string handle = mapinfo.Eval("SystemInfo(9)");
// Convert the handle to an IntPtr type.
IntPtr oldhandle = new IntPtr(Convert.ToInt32(handle));
//Make mapinfo visible otherwise it won't show up in our control.
mapinfo.Visible = true;
//Set the parent of MapInfo to a picture box on the form.
SetParent(oldhandle, this.pictureBox1.Handle);
//Get current window style of MapInfo window
int style = GetWindowLong(oldhandle, GWL_STYLE);
//Take current window style and remove WS_CAPTION(title bar) from it
SetWindowLong(oldhandle, GWL_STYLE, (style & ~WS_CAPTION));
//Maximize MapInfo so that it fits into our control.
mapinfo.Do("Set Window 1011 Max");
}
}
Class MapInfoApplication has a method called Do() and Eval(), there you can pass a command string, e.g. mapinfoinstance.Do('Open Table foo_bar.TAB as foo')
Have look at MapBasic samples in folder Samples\DOTNET\... in your MapBasic folder.

Webbrowser disable all audio output - from online radio to youtube

My webbrowser:
XAML:
//...
xmlns:my="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
//...
<my:WindowsFormsHost Name="windowsFormsHost"/>
Code behind C#:
System.Windows.Forms.WebBrowser Browser = new System.Windows.Forms.WebBrowser();
windowsFormsHost.Child = Browser;
My question is how to disable all audio output.
I found this:
C#:
private const int Feature = 21; //FEATURE_DISABLE_NAVIGATION_SOUNDS
private const int SetFeatureOnProcess = 0x00000002;
[DllImport("urlmon.dll")]
[PreserveSig]
[return: MarshalAs(UnmanagedType.Error)]
static extern int CoInternetSetFeatureEnabled(int featureEntry,
[MarshalAs(UnmanagedType.U4)] int dwFlags,
bool fEnable);
Its fine, but this code disable only "click" sound, so its kind of useless in this case.
I just want from my application 100% mute, no sounds at all.
I've read that in this webbrowser it need to be done through Windows Sounds, but I cant really bielieve that I cant do this in code.
Here is how you can do it with ease. Not specific to WebBrowser though, but does what you requested: I just want from my application 100% mute, no sounds at all.
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WinformsWB
{
public partial class Form1 : Form
{
[DllImport("winmm.dll")]
public static extern int waveOutGetVolume(IntPtr h, out uint dwVolume);
[DllImport("winmm.dll")]
public static extern int waveOutSetVolume(IntPtr h, uint dwVolume);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// save the current volume
uint _savedVolume;
waveOutGetVolume(IntPtr.Zero, out _savedVolume);
this.FormClosing += delegate
{
// restore the volume upon exit
waveOutSetVolume(IntPtr.Zero, _savedVolume);
};
// mute
waveOutSetVolume(IntPtr.Zero, 0);
this.webBrowser1.Navigate("http://youtube.com");
}
}
}
You can try as well to use DISPID_AMBIENT_DLCONTROL
DLCTL_DLIMAGES, DLCTL_VIDEOS, and DLCTL_BGSOUNDS: Images, videos, and background sounds will be downloaded from the server and displayed or played if these flags are set. They will not be downloaded and displayed if the flags are not set.

Categories

Resources