怎么在HOOK文件中建立Form之类的控件或者表单???

bahic 2003-12-12 12:35:49
我在HOOK.DLL中加入了一个Form1的表单。我的截获的消息是当按CTRL+L键时
Form1弹出来。再按一下CTRL+L键后Form1这个界面就消失!!
但不知道怎么才能做到这一点。

我的部份程如下:

LRESULT WINAPI Hook(int nCode,WPARAM wParam,LPARAM lParam)
{
if(wParam==0xA)
{
if(!Form_Init)
{
Form_Init=true;
{
Application->Initialize();
Application->CreateForm(__classid(Tgame), &game);
Application->Run();
}
}
if(run) //如果界面已经弹出来了就将它消失
{
game->Hide();
run=false;
}
else
{
game->Show(); //如果界面已经弹出来了就将它显示
run=true;
}
}

return(CallNextHookEx(g_hHook,nCode,wParam,lParam));
}

但我运行主程序时,程序在启动时要先弹出我的DLL中的界面,然后我将它关闭后才出现主程序的界面,当我按回车键时DLL中的界面是要弹出来,但再按一下时显示了一下界面就连主程序都退出去了。

如果有高手曾经写按一个键就弹出界面,再按一下界面就消失,就指教!!!
最后将源码给我看看。

最好给我一个小小的例程。

谢谢了
...全文
76 点赞 收藏 13
写回复
13 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
myy 2003-12-17
RegisterHotKey(Handle,2000,0,VK_F12);
^----楼主,俺对你实在是佩服!




BCB的help,希望你能好好看看,俺求你了......






The RegisterHotKey function defines a hot key for the current thread.

BOOL RegisterHotKey(

HWND hWnd, // window to receive hot-key notification
int id, // identifier of hot key
UINT fsModifiers, // key-modifier flags
UINT vk // virtual-key code
);


Parameters

hWnd

Identifies the window that will receive WM_HOTKEY messages generated by the hot key. If this parameter is NULL, WM_HOTKEY messages are posted to the message queue of the calling thread and must be processed in the message loop.

id

Specifies the identifier of the hot key. No other hot key in the calling thread should have the same identifier. An application must specify a value in the range 0x0000 through 0xBFFF. A shared dynamic-link library (DLL) must specify a value in the range 0xC000 through 0xFFFF (the range returned by the GlobalAddAtom function). To avoid conflicts with hot-key identifiers defined by other shared DLLs, a DLL should use the GlobalAddAtom function to obtain the hot-key identifier.

fsModifiers

Specifies keys that must be pressed in combination with the key specified by the nVirtKey parameter in order to generate the WM_HOTKEY message. The fsModifiers
parameter can be a combination of the following values:

Value Meaning
MOD_ALT Either ALT key must be held down.
MOD_CONTROL Either CTRL key must be held down.
MOD_SHIFT Either SHIFT key must be held down.


vk

Specifies the virtual-key code of the hot key.



Return Values

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.

Remarks

When a key is pressed, the system looks for a match against all thread hot keys. Upon finding a match, the system posts the WM_HOTKEY message to the message queue of the thread that registered the hot key. This message is posted to the beginning of the queue so it is removed by the next iteration of the message loop.
This function cannot associate a hot key with a window created by another thread.
RegisterHotKey fails if the keystrokes specified for the hot key have already been registered by another hot key.

If the window identified by the hWnd parameter already registered a hot key with the same identifier as that specified by the id parameter, the new values for the fsModifiers and vk parameters replace the previously specified values for these parameters.

See Also

GlobalAddAtom, UnregisterHotKey, WM_HOTKEY
回复
bahic 2003-12-17
我的问题已经解决了,程序也写完了,谢谢大家了。呵呵!!!!
回复
ccrun.com 2003-12-17
为何偏偏选中F12了呢。F12好象是系统的一个热键,还不如用F11呢。
回复
bahic 2003-12-17
兄弟呀,我就是这么写的!如下:
RegisterHotKey(Handle,2000,0,VK_F12);
可是不能注册成功。我试了的,不行。我愚笨,再请教!
回复
bahic 2003-12-16
我看了的。我写的程序是当我键下F12这一个单键时就弹出程序。但那个程序好象必须要两个组合键才行的!

那个程序我也试过了。能行的。但就是要按组合键才。不知道只按一个键怎么设置???谢谢
回复
myy 2003-12-16
http://www.ccrun.com/doc/go.asp?id=502
回复
bahic 2003-12-16
兄弟,我不懂,教一教我。谢谢
怎么用hotkey?

如果能写一个小的hotkey程序,然后发给我就更好了。我的信箱bahic@21cn.com

回复
bahic 2003-12-15
不过我的程序要在里面修改其它程序的内存,所以要用HOOK.DLL。
回复
OperDone 2003-12-15
用hotkey、、
回复
myy 2003-12-14
程序在后台就能在我按热键时能弹出来 ---> 用HotKey就行了!
回复
bahic 2003-12-14
因为我的程序要在后台就能在我按热键时能弹出来,所以用了HOOK.DLL
现在我已经解决了程序运行时就弹出DLL中界面的问题,还不能解决按一下就弹出来,再按一下就消失的问题。
如果有高手曾经写按一个键就弹出界面,再按一下界面就消失,就指教!!!
最后将源码给我看看。
回复
COKING 2003-12-13
别人用的肯定不是HOOK而是HotKey呀!

因为Hook.dll会被衍射进该进程的.
回复
constantine 2003-12-13
回复
发动态
发帖子
Windows SDK/API
创建于2007-08-02

1202

社区成员

C++ Builder Windows SDK/API
申请成为版主
社区公告
暂无公告