#ifdef logdll_exports
#define logdll_api __declspec(dllexport)
#else
#define logdll_api __declspec(dllimport)
#endif
extern "c" logdll_api void lg( const char* sztxt );
// logdll.cpp 内容:
//
#include <windows.h>
#include "logdll.h"
#include "resource.h"
// global data:
#pragma comment( linker, "section:shared,rws" )
#pragma data_seg( "shared" )
hhook g_hhook = null;
hinstance g_hinstance = null;
hwnd g_plogdlg = null;
bool g_bshowdlg = false;
#pragma data_seg()
//------------------------------------------------------------------------
void init();
void finish();
bool createlogdlg();
bool showlogdlg();
void installhook();
void uninstallhook();
lresult callback keyboardproc( int, wparam, lparam );
int_ptr callback lgdlgproc( hwnd, uint, wparam, lparam );
//------------------------------------------------------------------------
/*
*/
bool createlogdlg()
{
if( g_plogdlg ) return true;
if( false == g_hinstance ) return false;
g_plogdlg = createdialog( g_hinstance, makeintresource(idd_dialog1), null, (dlgproc)lgdlgproc );
return true;
}
//------------------------------------------------------------------------
/*
*/
bool showlogdlg()
{
if( null == g_plogdlg )
{
if( false == createlogdlg() )
return false;
}
return showwindow( g_plogdlg, (g_bshowdlg = !g_bshowdlg) ? sw_show : sw_hide );
}
//------------------------------------------------------------------------
/*
*/
void installhook()
{
if( g_hhook == null ) {
g_hhook = setwindowshookex( wh_keyboard, (hookproc)keyboardproc, g_hinstance, 0 );
}
}
//------------------------------------------------------------------------
/*
*/
void uninstallhook()
{
if( g_hhook ) {
unhookwindowshookex(g_hhook);
g_hhook = null;
}
}
//------------------------------------------------------------------------
/*
*/
logdll_api void lg( const char* sztxt )
{
// here set the text info to your dialog's text ctrl
}
void init()
{
installhook();
}
void finish()
{
uninstallhook();
if( g_plogdlg )
{
destroywindow( g_plogdlg );
g_plogdlg = null;
}
}
//------------------------------------------------------------------------
/*
*/
bool apientry dllmain( handle hmodule, dword ul_reason_for_call, lpvoid lpreserved )
{
g_hinstance = (hinstance) hmodule;
switch( ul_reason_for_call )
{
case dll_process_attach:
init();
break;
case dll_thread_attach:
init();
break;
case dll_thread_detach:
finish();
break;
case dll_process_detach:
finish();
break;
}
return true;
}
//------------------------------------------------------------------------
/*
*/
lresult callback keyboardproc(int ncode, wparam wparam, lparam lparam)
{
lresult res = callnexthookex( g_hhook, ncode, wparam, lparam);
if( (lparam & (1 << 31)) && (wparam == vk_f3) && (ncode == hc_action) )
{
showlogdlg();
}
return res;
}
//------------------------------------------------------------------------
/*
*/
int_ptr callback lgdlgproc( hwnd hdlg, uint msg, wparam wparam, lparam lparam )
{
switch ( msg )
{
case wm_initdialog:
return true;
case wm_command: