J
Jerod Houghtelling
Hi all,
I'm creating a Kiosk program and I'm trying to hook into the start bar
left click. I think I'm really close, but I've hit a snag when control
comes back to my program. I'm not exactly sure what is happening, but
I have narrowed down the code to possibly the cause. See notes in code
below...
using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace StartBarTest
{
public partial class Form1 : Form
{
private static StartBarLeftClickDelegate mStartBarCallback;
private delegate void StartBarLeftClickDelegate();
public Form1()
{
InitializeComponent();
}
[DllImport( "CUMenuNative.dll" )]
private static extern void HookStartButtonLeftClick(
[MarshalAs( UnmanagedType.FunctionPtr )]
StartBarLeftClickDelegate callbackPointer );
[DllImport( "CUMenuNative.dll" )]
private static extern void UnHookStartButtonLeftClick();
protected override void OnLoad( EventArgs e )
{
base.OnLoad( e );
mStartBarCallback = new
StartBarLeftClickDelegate( _HandleStartBarClick );
HookStartButtonLeftClick( mStartBarCallback );
}
protected override void
OnClosing( System.ComponentModel.CancelEventArgs e )
{
UnHookStartButtonLeftClick();
base.OnClosing( e );
}
private void _HandleBtnLaunchCalcClick( object sender, EventArgs e )
{
Process.Start( @"\Windows\calc.exe", "" );
}
private void _HandleStartBarClick()
{
if( InvokeRequired )
{
BeginInvoke( new
StartBarLeftClickDelegate( _HandleStartBarClick ) );
return;
}
// TODO: handle how we want the start bar to work.
}
}
}
#include <windows.h>
#ifdef CUMENUNATIVE_EXPORTS
#define CUMENUNATIVE_API __declspec(dllexport)
#endif
WNDPROC mOrgWndProc;
void (*mCallback)();
LRESULT CALLBACK HookWndProc( HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam )
{
if( message == WM_LBUTTONDOWN && LOWORD(lParam) < 150 )
{
// HERE'S THE PROBLEM... IF I REMOVE THE CALL TO mCallback
if( mCallback != NULL )
{
mCallback();
}
else
{
MessageBeep(0);
}
return TRUE;
}
return CallWindowProc( mOrgWndProc, hWnd, message, wParam, lParam );
}
extern "C" CUMENUNATIVE_API void
HookStartButtonLeftClick(void(_stdcall*callback)())
{
mCallback = callback;
HWND hTbWnd = FindWindow( L"HHTaskBar", NULL );
mOrgWndProc = (WNDPROC)SetWindowLong( hTbWnd, GWL_WNDPROC,
(long)HookWndProc );
}
extern "C" CUMENUNATIVE_API void UnHookStartButtonLeftClick()
{
HWND hTbWnd = FindWindow( L"HHTaskBar", NULL );
SetWindowLong( hTbWnd, GWL_WNDPROC, (long)mOrgWndProc );
}
I'm creating a Kiosk program and I'm trying to hook into the start bar
left click. I think I'm really close, but I've hit a snag when control
comes back to my program. I'm not exactly sure what is happening, but
I have narrowed down the code to possibly the cause. See notes in code
below...
using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace StartBarTest
{
public partial class Form1 : Form
{
private static StartBarLeftClickDelegate mStartBarCallback;
private delegate void StartBarLeftClickDelegate();
public Form1()
{
InitializeComponent();
}
[DllImport( "CUMenuNative.dll" )]
private static extern void HookStartButtonLeftClick(
[MarshalAs( UnmanagedType.FunctionPtr )]
StartBarLeftClickDelegate callbackPointer );
[DllImport( "CUMenuNative.dll" )]
private static extern void UnHookStartButtonLeftClick();
protected override void OnLoad( EventArgs e )
{
base.OnLoad( e );
mStartBarCallback = new
StartBarLeftClickDelegate( _HandleStartBarClick );
HookStartButtonLeftClick( mStartBarCallback );
}
protected override void
OnClosing( System.ComponentModel.CancelEventArgs e )
{
UnHookStartButtonLeftClick();
base.OnClosing( e );
}
private void _HandleBtnLaunchCalcClick( object sender, EventArgs e )
{
Process.Start( @"\Windows\calc.exe", "" );
}
private void _HandleStartBarClick()
{
if( InvokeRequired )
{
BeginInvoke( new
StartBarLeftClickDelegate( _HandleStartBarClick ) );
return;
}
// TODO: handle how we want the start bar to work.
}
}
}
#include <windows.h>
#ifdef CUMENUNATIVE_EXPORTS
#define CUMENUNATIVE_API __declspec(dllexport)
#endif
WNDPROC mOrgWndProc;
void (*mCallback)();
LRESULT CALLBACK HookWndProc( HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam )
{
if( message == WM_LBUTTONDOWN && LOWORD(lParam) < 150 )
{
// HERE'S THE PROBLEM... IF I REMOVE THE CALL TO mCallback
if( mCallback != NULL )
{
mCallback();
}
else
{
MessageBeep(0);
}
return TRUE;
}
return CallWindowProc( mOrgWndProc, hWnd, message, wParam, lParam );
}
extern "C" CUMENUNATIVE_API void
HookStartButtonLeftClick(void(_stdcall*callback)())
{
mCallback = callback;
HWND hTbWnd = FindWindow( L"HHTaskBar", NULL );
mOrgWndProc = (WNDPROC)SetWindowLong( hTbWnd, GWL_WNDPROC,
(long)HookWndProc );
}
extern "C" CUMENUNATIVE_API void UnHookStartButtonLeftClick()
{
HWND hTbWnd = FindWindow( L"HHTaskBar", NULL );
SetWindowLong( hTbWnd, GWL_WNDPROC, (long)mOrgWndProc );
}