|
Because I use a timer in the form,I write some code to set a button's enable property at interval.When the form is on desktop, my hook application can hook the message,but when the form minmum my hook application can't.
|
|
|
|
|
The key here is WH_GETMESSAGE. Are you sure the minimized application should be getting messages? I could be wrong. I thought the minimized application would be in the idle loop. I used Spy++ to monitor all standard window messages of a minimized application and I don't see any. Do you expect custom control messages? If not, I think what you are seeing is the correct behavior. I don't think Spy++ will miss out any.
I used WH_CALLWNDPROC and WH_CBT and they behave differently from WH_GETMESSAGE. I have the similar code to hook and subclass, I don't think that part of your code is wrong.
|
|
|
|
|
At first,Thanks your reply!As you said,When the application is minimized the Spy++ could not hook the messages!But the application is runing.Of course,the application must produce some messages to notify it's child-component such as button,listbox,prograss bar and so on.If the application is in the idle loop,how does it's child-component get the notify_message?Please help me!Thanks!
|
|
|
|
|
I don't think you understand what I was saying. You can use Spy++ to log ALL messages of the window and ALL its child windows before you minimize the application, then only you minimize it.
I'm outta ideas to suggest to you (that you actually try). Good luck!
|
|
|
|
|
Sorry I didn't see your post about the timer. Why don't you use Spy++ to monitor it and see if it gets any timer messages? If it doesn't, then your code behaves correctly. If it does, I suggest you to add a bunch of debug messages where the timer starts, ends, etc and analyze them in DebugView.
|
|
|
|
|
When an application's form is minmum to the taskbar or hide,how to hook the messages of the form?I have developed an application that can hook a form's messages when the form on the desktop.But when the form is minmum to the taskbar or the form is hidden,the hook message application could not hook nothing of the form.In fact ,the messages of the form happen,such as a message that a disable button is changed to an enable button.Please help me!
Thanks alot!
|
|
|
|
|
please help me.I have searched on google and msdn,but all ways can only hook the application with forms.But when the form is hidden,how to hook the messages when the states of the components on the form is changing?Please help me!
|
|
|
|
|
Hello, I am new to programming C++. Can anyone help me with this problem:
C2248: cannot access protected struct declared in class.
It occurs when I want to fill a struct in another class, which is declared private (and should stay private).
Do I have to develop a public function in this class which acceses my struct ?
I do not know how to proceed...
Thanks for your help
|
|
|
|
|
externalize the declaration of the struct type outside the class, or set it to public/protected within the class.
don't confuse, i talk about the struct type declaration, not the members of that type.
|
|
|
|
|
Thanks for your reply,
I already set it protected.
I do not want to access it from a derrived class, but from a really different class.
|
|
|
|
|
if you access it from a class that is not in the inheritance, you have to declare the struct public, or global.
|
|
|
|
|
ok thank you, i declared it public
|
|
|
|
|
Checker2003 wrote: i declared it public
what's wrong ? it's just a type... no one will access your datas from outside the class !!! no ?!
|
|
|
|
|
Instead of declaring it public, you could also add a constructor to structure to initialize its values, or add a method to the outer class to initialize it:
class OuterClass
{
public:
OuterClass() {}
~OuterClass() {}
private:
struct InnerClass
{
InnerClass() { _data = 0; }
int _data;
};
InnerClass _MyData;
};
class OuterClass
{
public:
OuterClass() {}
~OuterClass() {}
void Initialize() { _MyData._data = 0; }
private:
struct InnerClass
{
int _data;
};
InnerClass _MyData;
};
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi,
Probably your problem looks like this:
typedef struct TESTSTRUCT {
double a;
}
class testA
{
public:
TESTSTRUCT st;
...
};
class testB: private testA
{
public:
void MyFunc(double val) {
st.a = val;
};
...
};
int main (...) {
testB c;
c.st.a = 1.1;
Myfunc(1.1);
}
So, everything you have to do is to create publicly available function to access private member of your classes.
Hope that helps a bit.
Best regards
|
|
|
|
|
Thanks for your reply,
I already thought about this, but I do not want to access it from a derrived class, but from a really different class.
My problem is, that then I have to give my function the struct as parameter, and this does not work, because the compiler doesn't understand the struct as identifier...
Thanks a lot
|
|
|
|
|
You can always post a bit of your code , which would be very helpful.
Regards
|
|
|
|
|
LRESULT CALLBACK CBTProc(
int code, // hook code
WPARAM wParam, // removal flag
LPARAM lParam // address of structure with message
)
{
if (code < 0) return CallNextHookEx(CBTSysHook, code, wParam, lParam);
if(code == HCBT_ACTIVATE)
{
HWND hWnd = (HWND) wParam;
TCHAR cWind[512], cClass[512];
GetWindowText( hWnd, cWind, 512);
GetClassName( hWnd, cClass, 512);
/*if ( (GetParent(GetParent(hWnd))==NULL) && ( IsWindow(GetParent(hWnd))==TRUE ) )
{
CStringW strWind, strClass;
AfxDaoInit(); // preparing for DAO
CDaoDatabase database;
CDaoRecordset recordset(& database);
// Open database and recordset
database.Open(_T("d:\\╠юш фюъєьхэЄ√\\┴рч√ фрээ√ї\\hookBase.mdb"));
recordset.Open(AFX_DAO_USE_DEFAULT_TYPE,
_T("SELECT * FROM hookspy"), 0);
// getting know Window Title and Class Name of hwnd
strWind.AppendFormat(_T("%s"), cWind);
strClass.AppendFormat(_T("%s"), cClass);
// adding new record
recordset.AddNew();
recordset.SetFieldValue(_T("lpszName"), strWind.GetString());
recordset.SetFieldValue(_T("lpszClass"), strClass.GetString());
recordset.SetFieldValue(_T("lpszAction"), _T("CBT activated"));
recordset.Update();
recordset.Close();
database.Close();
AfxDaoTerm();
} */
//AfxBeginThread(threadActiv, NULL);
/*if(_tcscmp(buff,_T("Effects")) == 0)
{
ShowWindow(hWnd,SW_HIDE);
g_hWndEffects = hWnd;
}
if(_tcscmp(buff,_T("Display Properties")) == 0)
{
ShowWindow(hWnd,SW_HIDE);
}*/
}
|
|
|
|
|
Hi,
Most of your code seems to be commented out, so it will not be executing.
Could you point us where exactly problem occurs, and what kind of error it is, please?
Regards
|
|
|
|
|
There is no error when code is simply
LRESULT CALLBACK CBTProc(
int code, // hook code
WPARAM wParam, // removal flag
LPARAM lParam // address of structure with message
)
{
if (code < 0) return CallNextHookEx(CBTSysHook, code, wParam, lParam);
if(code == HCBT_ACTIVATE)
{
HWND hWnd = (HWND) wParam;
TCHAR cWind[512], cClass[512];
GetWindowText( hWnd, cWind, 512);
GetClassName( hWnd, cClass, 512);
}
return 0;
}
An error occurs when I add DAO support, exactly when program is run
and I open Light Alloy, press 'play' and further press X - to close,
it happens error sound, my program goes on to work
, and nothing else is different with normal closing
|
|
|
|
|
There is no error when code is simply
LRESULT CALLBACK CBTProc(
int code, // hook code
WPARAM wParam, // removal flag
LPARAM lParam // address of structure with message
)
{
if (code < 0) return CallNextHookEx(CBTSysHook, code, wParam, lParam);
if(code == HCBT_ACTIVATE)
{
HWND hWnd = (HWND) wParam;
TCHAR cWind[512], cClass[512];
GetWindowText( hWnd, cWind, 512);
GetClassName( hWnd, cClass, 512);
}
return 0;
}
An error occurs when I add DAO support, exactly when program is run
and I open Light Alloy, press 'play' and further press X - to close,
it happens error sound, my program goes on to work
, and nothing else is different with normal closing
|
|
|
|
|
There is no error when code is simply
LRESULT CALLBACK CBTProc(
int code, // hook code
WPARAM wParam, // removal flag
LPARAM lParam // address of structure with message
)
{
if (code < 0) return CallNextHookEx(CBTSysHook, code, wParam, lParam);
if(code == HCBT_ACTIVATE)
{
HWND hWnd = (HWND) wParam;
TCHAR cWind[512], cClass[512];
GetWindowText( hWnd, cWind, 512);
GetClassName( hWnd, cClass, 512);
}
return 0;
}
An error occurs when I add DAO support, exactly when program is run
and I open Light Alloy, press 'play' and further press X - to close,
it happens error sound, my program goes on to work
, and nothing else is different with normal closing
|
|
|
|
|
There is no error when code is simply
LRESULT CALLBACK CBTProc(
int code, // hook code
WPARAM wParam, // removal flag
LPARAM lParam // address of structure with message
)
{
if (code < 0) return CallNextHookEx(CBTSysHook, code, wParam, lParam);
if(code == HCBT_ACTIVATE)
{
HWND hWnd = (HWND) wParam;
TCHAR cWind[512], cClass[512];
GetWindowText( hWnd, cWind, 512);
GetClassName( hWnd, cClass, 512);
}
return 0;
}
An error occurs when I add DAO support, exactly when program is run
and I open Light Alloy, press 'play' and further press X - to close,
it happens error sound, my program goes on to work
, and nothing else is different with normal closing
|
|
|
|
|
You dont need to repeat your answer
|
|
|
|
|
I use CList instead of DAO, I mean I use back-write, here is it.
But except for my Program, which call CBT.dll, nothing is written.
I open the testHook table, and there is it
#1: myMonitor #32770
#2: myMonitor #32770
#3: myMonitor #32770
#4: myMonitor #32770
#5: myMonitor #32770
Why is it so? Is there any secret?
LRESULT CALLBACK CBTProc(
int code, // hook code
WPARAM wParam, // removal flag
LPARAM lParam // address of structure with message
)
{
if (code < 0) return CallNextHookEx(CBTSysHook, code, wParam, lParam);
if(code == HCBT_ACTIVATE)
{
HWND hwnd = (HWND) wParam;
if ( IsWindow( hwnd )== TRUE)
{
myStr str;
GetWindowText( hwnd, str.cWind, 250);
GetClassName( hwnd, str.cClass, 250);
AfxMessageBox( cStr );
myWindList.AddTail(str);
}
}
return 0;
}
...
void RunStopHook(BOOL State)
{
if (State == TRUE)
{
//SysHook = SetWindowsHookEx(WH_SHELL, &ShellProc, hInst, 0);
CBTSysHook = SetWindowsHookEx(WH_CBT, &CBTProc, hInst, 0);
//WNDSysHook = SetWindowsHookEx(WH_CALLWNDPROCRET, &CallWndRetProc, hInst, 0);
}
else
{
//UnhookWindowsHookEx(SysHook);
UnhookWindowsHookEx(CBTSysHook);
//UnhookWindowsHookEx(WNDSysHook);
AfxDaoInit(); // preparing for DAO
CDaoDatabase database;
CDaoRecordset recordset(& database);
// Open database and recordset
database.Open("d:\\╠юш фюъєьхэЄ√\\┴рч√ фрээ√ї\\hookBase.mdb");
recordset.Open(AFX_DAO_USE_DEFAULT_TYPE,
"SELECT * FROM testHook", 0);
myStr str;
POSITION pos = myWindList.GetHeadPosition();
for (int i=0;i < myWindList.GetCount();i++)
{
str = myWindList.GetNext(pos);
if ((strlen( str.cWind ) < 255) &&
(strlen( str.cClass ) < 255))
{
recordset.AddNew();
recordset.SetFieldValue("lpszName", (LPCSTR) str.cWind);
recordset.SetFieldValue("lpszClass", (LPCSTR) str.cClass);
recordset.Update();
}
else
{
CString strC, strD;
strC.AppendFormat("%i", strlen( str.cWind ));
strD.AppendFormat("%i", strlen( str.cClass));
recordset.AddNew();
recordset.SetFieldValue("lpszName", (LPCSTR) strC.GetString());
recordset.SetFieldValue("lpszClass", (LPCSTR) strD.GetString());
recordset.Update();
}
}
myWindList.RemoveAll();
recordset.Close();
database.Close();
AfxDaoTerm();
}
}
|
|
|
|
|