Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Making my app Topmost in a callback

Status
Not open for further replies.

JeepJson

Programmer
Oct 15, 2000
3
US
Ok, here's the deal. I am making a dialog based app. I have a hook setup when you press F12 while using another app and it brings up a callback function that is a global. In the callback function I want to have it set my app to the Top-most window. here is what I have tried... What am I doing wrong?

HWND ghWndMain = NULL; //Is a global to CLLTrainerDlg

LRESULT CALLBACK KeyboardHook(int nCode,
WPARAM wParam,
LPARAM lParam)
{
BOOL huh = FALSE;
if (nCode == HC_ACTION)
{
if (wParam == VK_F12 && !GetAsyncKeyState(VK_F12))
{
huh = ::SetWindowPos(ghWndMain,
HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE & SWP_SHOWWINDOW);
if (!huh)
{
AfxMessageBox("Cannot set
on top!", MB_OK);
return 1;
}
}
}
return CallNextHookEx(ghHook, nCode, wParam, lParam);
}

Maybe I'm not using the Hwnd of the main dialog app right, but I can't figure out how to get it. Can someone PLEASE help!! The callback works fine, and if I just put in a Messagebox instead of all that crap everything works, it just won't make my app topmost for some reason. Thanks in advance! [sig][/sig]
 
Have you tried LRESULT CALLBACK KeyboardHook(int nCode, WPARAM wParam, LPARAM lParam) in DLL??

In DLL, Each process attatchment has its own variables. to make it shared to all process, when building DLL, try this

#prama data_seg("mydata")
HWND ghWndMain = NULL; //Is a global to CLLTrainerDlg
#prama data_seg()

In .DEF files, declare

SECTIONS
mydata READ WRITE SHARED

Before SetWindowsHook, please call a setup function in DLL to initiate ghWndMain to proper windows's handle


JimmyK
[sig][/sig]
 
I am new to C++, I don't know how to create Dll's yet :) But thanks for the reply, I did get it to work finally. Thanks anyway!

Jason [sig][/sig]
 
Hi,
Try to use timer. You can create a timer and to use message WM_TIME. All what you need is to skan keyboard 48 times in a second.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top