Equivalent of ReisizeEnd event User Control - vb.net

I have made a custom task pane using a user control.
Every time I resize it I raise a method called SuspendDrawing the reason I do this is because the buttons on my custom task pane flicker when I resize it therefore I need to suspend it. I add these buttons using the designer
This works like a treat but then I need to call a method called ResumeDrawing when the user stops resizing however I don't know what event I should use to call the ResumeDrawing method as there is no ResizeEnd event for a user control.
Any suggestions would be appreciated as I'm out of ideas.
My code is as follows
Public Property Resizing As Boolean
<DllImport("user32.dll", EntryPoint:="SendMessageA", ExactSpelling:=True, CharSet:=CharSet.Ansi, SetLastError:=True)>
Private Shared Function SendMessage(ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function
Public Shared Sub SuspendDrawing(ByVal target As Control)
SendMessage(target.Handle, WM_SETREDRAW, 0, 0)
End Sub
Public Shared Sub ResumeDrawing(ByVal target As Control)
ResumeDrawing(target, True)
End Sub
Public Shared Sub ResumeDrawing(ByVal target As Control, ByVal redraw As Boolean)
SendMessage(target.Handle, WM_SETREDRAW, 1, 0)
If redraw Then
target.Refresh()
End If
End Sub
Private Sub SideBarPowerPoint_Resize(sender As Object, e As EventArgs) Handles MyBase.Resize
SuspendDrawing(Me)
End Sub
My Custom Task Pane
Dim taskPaneView = New PowerPointCommon.SideBarPowerPoint
sideBarTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(taskPaneView, " ")
If sideBarTaskPane.Visible = True Then
sideBarTaskPane.Visible = False
End If
sideBarTaskPane.Visible = True
sideBarTaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionRight
sideBarTaskPane.Width = 100

Related

Get the highlighted text from outside of form in vb.net

I want to copy the highlighted text from outside of winform using vb.net.
For example, if the user highlights a text in a browser or in notepad it should be copied into a textbox in a winform.
Any help would be great!
Thanks in advance.
Ok!
Thanks to this link I got my answer.
My Logic is First of all the user will highlight a value, not specific to browser but anywhere.
then the user will press the Hotkey, In my case it's F8. Then Code will trigger the copy command and then retrieve the Clipboard value and will assign it to a textbox text.
Here is the Full Code along with Helping Class.
Hotkey.vb
Public Class Hotkey
#Region "Declarations - WinAPI, Hotkey constant and Modifier Enum"
''' <summary>
''' Declaration of winAPI function wrappers. The winAPI functions are used to register / unregister a hotkey
''' </summary>
Private Declare Function RegisterHotKey Lib "user32" _
(ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
Private Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As IntPtr, ByVal id As Integer) As Integer
Public Const WM_HOTKEY As Integer = &H312
Enum KeyModifier
None = 0
Alt = &H1
Control = &H2
Shift = &H4
Winkey = &H8
End Enum 'This enum is just to make it easier to call the registerHotKey function: The modifier integer codes are replaced by a friendly "Alt","Shift" etc.
#End Region
#Region "Hotkey registration, unregistration and handling"
Public Shared Sub registerHotkey(ByRef sourceForm As Form, ByVal triggerKey As String, ByVal modifier As KeyModifier)
RegisterHotKey(sourceForm.Handle, 1, modifier, &H77)
End Sub
Public Shared Sub unregisterHotkeys(ByRef sourceForm As Form)
UnregisterHotKey(sourceForm.Handle, 1) 'Remember to call unregisterHotkeys() when closing your application.
End Sub
Public Shared Sub handleHotKeyEvent(ByVal hotkeyID As IntPtr)
SendKeys.Send("^(c)") 'for Ctrl-C[/CODE]
End Sub
#End Region
End Class
This Section will Trigger the Hotkey Code and do the rest of logic
Main Form
'This Program will wait for a key to press in our case it will wait for the F8 key to be press
'Then it will copy the highlighted text (Outside and Inside of the form) and will concatinate the text with a webaddress'
Imports Name_Of_Your_Project.Hotkey
Public Class Form1
'This Chunk of code will register the F8 key as a main key for the Program'
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Hotkey.registerHotkey(Me, "f8", Hotkey.KeyModifier.None)
End Sub
'This sub will trigger the Hotkey Sub Code in the Hotkey.vb Class'
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = Hotkey.WM_HOTKEY Then
Hotkey.handleHotKeyEvent(m.WParam)
'After pressing the F8 key It will copy the highlighted data from anywhere and store it to the clipboard'
If Clipboard.ContainsText Then
Try
Textbox1.text = My.Computer.Clipboard.GetData(DataFormats.Text).ToString
Catch ex As Exception
MessageBox.Show("Error in Program" + ex.ToString())
End Try
End If
End If
MyBase.WndProc(m)
End Sub
'System wide hotkey event handling
End Class

VB Mouse click in background running process

I’m making an VB application which runs another process (windowed game). My app acts as a macro to that game.
I’m struggling to get mouse click working, although my code to send keys in the background works excellent (can provide if needed).
I mean the program to click into specific location within the process in the background, that means I could be browsing internet or playing another game when that mouse click takes action.
I'm getting an error message: Specified cast is not valid.
Error is on InputPressRightMouse Sub where:
PostMessage(Handle, WM_RBUTTONDOWN, 1, coord)
Private Const WM_RBUTTONDOWN As System.UInt32 = &H204
Private Const WM_RBUTTONUP As System.UInt32 = &H205
Dim coord = MakeDWord(-220, 85)
Private Function MakeDWord(ByVal LoWord As Integer, ByVal HiWord As Integer) As Long
MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
End Function
<System.Runtime.InteropServices.DllImport("user32.dll")>
Public Shared Function PostMessage(<System.Runtime.InteropServices.In()> ByVal hWnd As System.IntPtr, <System.Runtime.InteropServices.In()> ByVal Msg As System.UInt32, <System.Runtime.InteropServices.In()> ByVal wParam As System.IntPtr, <System.Runtime.InteropServices.In()> ByVal lParam As System.UIntPtr) As System.Boolean
End Function
Public Sub InputPressKey(ByVal Handle As System.IntPtr, ByVal Key As System.Windows.Forms.Keys)
PostMessage(Handle, WM_KEYDOWN, CType(Key, System.IntPtr), CType(WM_KEYDOWNLPARAM, System.UIntPtr))
End Sub
Public Sub InputReleaseKey(ByVal Handle As System.IntPtr, ByVal Key As System.Windows.Forms.Keys)
PostMessage(Handle, WM_KEYUP, CType(Key, System.IntPtr), CType(WM_KEYUPLPARAM, System.UIntPtr))
End Sub
Public Sub InputPressRightMouse(ByVal Handle As System.IntPtr, ByVal Mouse As System.Windows.Forms.MouseButtons)
PostMessage(Handle, WM_RBUTTONDOWN, 1, coord)
End Sub
And code to perform mouse click:
InputPressRightMouse(Process.MainWindowHandle, System.Windows.Forms.MouseButtons.Right)
Code to send key (which works)
InputPressKey(Process.MainWindowHandle, System.Windows.Forms.Keys.V)
Can somebody help with what I did wrong here?

Visual Studio Console-Like Blinking Cursor?

Is there any way to make a cursor look something like the blinking, square cursor used in console applications, say, inside of a text box instead of the regular vertical line? Example:
https://gyazo.com/db9f5661d493c32e48434eed2fa45252
You can control the caret (cursor) using the Win API Caret Functions.
A simple custom WinForm TextBox can be given a blinking caret like this:
Public Class MyTB : Inherits TextBox
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function CreateCaret(ByVal hWnd As IntPtr, ByVal hBitmap As IntPtr, ByVal nWidth As Integer, ByVal nHeight As Integer) As Boolean
End Function
<DllImport("user32.dll")>
Private Shared Function DestroyCaret() As Boolean
End Function
<DllImport("user32.dll")>
Private Shared Function SetCaretBlinkTime(ByVal uMSeconds As UInt32) As Boolean
End Function
<DllImport("user32.dll")> _
Private Shared Function ShowCaret(ByVal hWnd As IntPtr) As Boolean
End Function
Protected Overrides Sub OnGotFocus(e As EventArgs)
MyBase.OnGotFocus(e)
MyTB.CreateCaret(Me.Handle, Nothing, 5, Me.Font.Height)
MyTB.SetCaretBlinkTime(500UI)
MyTB.ShowCaret(Me.Handle)
End Sub
Protected Overrides Sub OnLostFocus(e As EventArgs)
MyBase.OnLostFocus(e)
MyTB.DestroyCaret()
End Sub
End Class

Switch focus to a vb.net application on key press

I have a vb.net application which will be minimized to task bar or notification area. Is there any way for me to maximize/focus on that application when user presses a key (even if the user is using any other application).
Tried windows hot key but doesn't focus the app when it is already open.Please help
You require global hotkeys. First, add these functions to your application.
Private Declare Function GetKeyPress Lib "user32" Alias "GetAsyncKeyState" (ByVal key As Integer) As Integer
<DllImport("user32.dll", EntryPoint:="FindWindow", SetLastError:=True)> _
Private Shared Function FindWindow(lpClassName As String, lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll")> _
Private Shared Function ShowWindow(hWnd As IntPtr, nCmdShow As Integer) As Boolean
End Function
<DllImport("user32.dll")> _
Private Shared Function SetForegroundWindow(hWnd As IntPtr) As Integer
End Function
Next, add a Timer and in its Timer.Tick Event, use this function like this:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If GetKeyPress(Keys.LControlKey) And GetKeyPress(Keys.A) Then
Dim Handle As IntPtr = Process.GetProcessById(2916).MainWindowHandle
ShowWindow(Handle, 9)
SetForegroundWindow(Handle)
End If
End Sub
Set the Timer Interval to 150 to avoid repeated keypresses and make sure to enable the timer in the Form Load event.

How to add more items to the window context menu

I'm making an app for the company I work for and I was wondering how to customise the window's context menu like PuTTY's (aka, it has "New Session..." etc.). I've looked all over Google and can't find the answer I'm looking for.
make a new module and add Imports System.Runtime.InteropServices on top
then declare this
<Flags()> _
Public Enum MenuFlags As Integer
MF_BYPOSITION = 1024
MF_REMOVE = 4096
MF_SEPARATOR = 2048
MF_STRING = 0
End Enum
<DllImport("user32.dll", CallingConvention:=CallingConvention.Cdecl)> _
Public Function GetSystemMenu(ByVal hWnd As IntPtr, Optional ByVal bRevert As Boolean = False) As IntPtr
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto)> _
Public Function AppendMenu(ByVal hMenu As IntPtr, ByVal uFlags As MenuFlags, ByVal uIDNewItem As Int32, ByVal lpNewItem As String) As Boolean
End Function
then on your form load handler add this code
Dim sysmenu As IntPtr = GetSystemMenu(Me.Handle)
AppendMenu(sysmenu, MenuFlags.MF_STRING, &H1FFF, "Hello")
then, in order to be able to capture the user click on your new menu item, you have to implement this function which will capture all messages, just add it to your form code
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_SYSCOMMAND Then
If m.WParam.ToInt32 = &H1FFF Then
' your menu item is clicked, call a function here
End If
End If
MyBase.WndProc(m)
End Sub