Click here to Skip to main content
15,897,371 members
Home / Discussions / C#
   

C#

 
GeneralRe: Programming Visio streams on a local computer and hosted on a remote server using c# Pin
Dave Kreskowiak24-Jun-14 1:39
mveDave Kreskowiak24-Jun-14 1:39 
SuggestionRe: Programming Visio streams on a local computer and hosted on a remote server using c# Pin
Richard Deeming24-Jun-14 0:38
mveRichard Deeming24-Jun-14 0:38 
GeneralRe: Programming Visio streams on a local computer and hosted on a remote server using c# Pin
OriginalGriff24-Jun-14 1:06
mveOriginalGriff24-Jun-14 1:06 
GeneralRe: Programming Visio streams on a local computer and hosted on a remote server using c# Pin
Mycroft Holmes25-Jun-14 0:39
professionalMycroft Holmes25-Jun-14 0:39 
QuestionHow to convert a text file in unicode format to excel file Pin
botngot8323-Jun-14 20:54
botngot8323-Jun-14 20:54 
SuggestionRe: How to convert a text file in unicode format to excel file Pin
Nathan Minier24-Jun-14 3:12
professionalNathan Minier24-Jun-14 3:12 
QuestionConnect to MySQL using MySQL Connector.NET and SharpSsh Pin
Jassim Rahma23-Jun-14 20:24
Jassim Rahma23-Jun-14 20:24 
QuestionSetting A Global Hot Key On A Second Form Pin
rfresh23-Jun-14 18:55
rfresh23-Jun-14 18:55 
I created a WinForm app in C# using VS 2013 Express.

I added code to create a Global Hot Key on the main form. This works fine. My hot key is Ctrl-T. I can press the hot key and make the main form show and hide.

Then I created a second form (ChecklistForm) and now I want to press ctrl-T and make that form show and hide. I do not need the main form to do this any more. I just used the main form to test my Global Hot Key code.

So I'm having trouble getting the second form to respond to the hot key. When I put a break on the WndProc(), there is no break.

Thanks for any help.

re lang="c#">
public partial class MainForm : Form
{
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(String sClassName, String AppName);

private IntPtr thisWindow;
private GlobalHotKeys hotkey;

public MainForm()
{
InitializeComponent();
}

private void MainForm_Load(object sender, EventArgs e)
{
ChecklistForm frm = new ChecklistForm();
frm.Show();
thisWindow = FindWindow(null, "ChecklistForm");
//thisWindow = FindWindow(null, "MainForm");
hotkey = new GlobalHotKeys(thisWindow);
hotkey.RegisterHotKeys();
}

private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
thisWindow = FindWindow(null, "ChecklistForm");
//thisWindow = FindWindow(null, "MainForm");
hotkey = new GlobalHotKeys(thisWindow);
hotkey.UnRegisterHotKeys();
}

protected override void WndProc(ref Message keyPressed)
{
if (keyPressed.Msg == 0x0312)
{
thisWindow = FindWindow(null, "ChecklistForm");
//thisWindow = FindWindow(null, "MainForm");
IntPtr i = keyPressed.WParam; // not being used
ShowChecklist ShowChkList = new ShowChecklist(thisWindow);
ShowChkList.execute();
}
base.WndProc(ref keyPressed);
}
}



class GlobalHotKeys // CLASS FILE *********************
{
public enum fsModifiers
{
Alt = 0x0001,
Control = 0x0002,
Shift = 0x0004,
Window = 0x0008
}

private IntPtr _hWnd;

public GlobalHotKeys(IntPtr hWnd)
{
this._hWnd = hWnd;
}
public void RegisterHotKeys()
{
RegisterHotKey(_hWnd, 1, (uint)fsModifiers.Control, (uint)Keys.T);
}

public void UnRegisterHotKeys()
{
UnregisterHotKey(_hWnd, 1);
}

#region WindowsAPI
[DllImport("user32.dll")]
public static extern IntPtr RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);

[DllImport("user32.dll")]
public static extern IntPtr UnregisterHotKey(IntPtr hWnd, int id);
#endregion

}




class ShowChecklist // CLASS FILE *********************
{
public enum nCmdShow
{
NORMAL = 1,
MIN = 2,
MAX = 3
}

private IntPtr _hWnd;

public ShowChecklist(IntPtr hWnd)
{
_hWnd = hWnd;
}

public void execute()
{
ShowWindowAsync(_hWnd, (int)nCmdShow.NORMAL);
}

#region WindowsAPI
[DllImport("user32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
#endregion
}



AnswerRe: Setting A Global Hot Key On A Second Form Pin
Eddy Vluggen24-Jun-14 0:34
professionalEddy Vluggen24-Jun-14 0:34 
GeneralRe: Setting A Global Hot Key On A Second Form Pin
rfresh24-Jun-14 3:21
rfresh24-Jun-14 3:21 
GeneralRe: Setting A Global Hot Key On A Second Form Pin
Eddy Vluggen24-Jun-14 5:09
professionalEddy Vluggen24-Jun-14 5:09 
QuestionPlacing UserControl within a UserControl (WPF) Pin
LAPEC23-Jun-14 8:57
LAPEC23-Jun-14 8:57 
AnswerRe: Placing UserControl within a UserControl (WPF) Pin
OriginalGriff23-Jun-14 20:01
mveOriginalGriff23-Jun-14 20:01 
QuestionMultiple application installer in single Setup file Pin
Ashfaque Hussain23-Jun-14 4:55
Ashfaque Hussain23-Jun-14 4:55 
AnswerRe: Multiple application installer in single Setup file Pin
Maciej Los23-Jun-14 9:40
mveMaciej Los23-Jun-14 9:40 
GeneralRe: Multiple application installer in single Setup file Pin
Ashfaque Hussain23-Jun-14 19:47
Ashfaque Hussain23-Jun-14 19:47 
GeneralRe: Multiple application installer in single Setup file Pin
Ashfaque Hussain23-Jun-14 23:37
Ashfaque Hussain23-Jun-14 23:37 
QuestionAbout Error - unable to find a version of the runtime to run this application." error when try to open the application. Pin
Member 1084900023-Jun-14 2:25
Member 1084900023-Jun-14 2:25 
AnswerRe: About Error - unable to find a version of the runtime to run this application." error when try to open the application. Pin
OriginalGriff23-Jun-14 2:38
mveOriginalGriff23-Jun-14 2:38 
QuestionC sharp windows application development Pin
Galacha Kevin23-Jun-14 2:09
Galacha Kevin23-Jun-14 2:09 
AnswerRe: C sharp windows application development Pin
OriginalGriff23-Jun-14 2:32
mveOriginalGriff23-Jun-14 2:32 
AnswerRe: C sharp windows application development Pin
Kornfeld Eliyahu Peter23-Jun-14 2:59
professionalKornfeld Eliyahu Peter23-Jun-14 2:59 
AnswerRe: C sharp windows application development Pin
Swinkaran23-Jun-14 15:15
professionalSwinkaran23-Jun-14 15:15 
AnswerRe: C sharp windows application development Pin
V.23-Jun-14 20:12
professionalV.23-Jun-14 20:12 
QuestionCryptanalysis Algorithm RC5 Pin
KaKoten22-Jun-14 13:29
KaKoten22-Jun-14 13:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.