|
There must be something special about the WM_CLOSE message. Are you using a DLL? Are you calling SetWindowLong() in that DLL? Are you injecting the DLL into the process of the "specific window?"
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Because this is a global hook which will monitor all message before they really reach to target window. So I think It doesn't need inject the dll to the target window. But I will try.
I took a round from google and know that many people have the same problem with me when they try to catch the WM_CLOSE. But I still cannot find the solution.
[N][Q][H]
|
|
|
|
|
[N][Q][H] wrote: DLLEXPORT LRESULT CALLBACK KeyboardProc(int nCode,WPARAM wParam, LPARAM lParam)
You hook handler seems to be incorrect. For instance if you are using the WH_CALLWNDPROC, the handler should be like
LRESULT CALLBACK CallWndProc(int nCode,WPARAM wParam, LPARAM lParam)
{
PCWPSTRUCT msg = (PCWPSTRUCT)lParam;
if(msg->message == WM_CLOSE )
{
}
return CallNextHookEx(_hHook,nCode,wParam, lParam);
}
|
|
|
|
|
ok, KeyboardProc must be renamed to fnHookProc. But this is not the cause. This just a mistake when I copy from my code.
LRESULT CALLBACK LRESULT CALLBACK fnHookProc(int nCode,WPARAM wParam, LPARAM lParam)
{
PCWPSTRUCT msg = (PCWPSTRUCT)lParam;
if(msg->message == WM_CLOSE )
{
}
return CallNextHookEx(_hHook,nCode,wParam, lParam);
}
[N][Q][H]
|
|
|
|
|
It's an old Win32 FAQ (see onWin32 grp[^]) (same method than on Win 9x)
|
|
|
|
|
Dear all,
I am using MFC dialog application to get an text input from the user and make processing on it and then reply with response but I need to declare some variables to be working throughout the whole system cycle(I think its called global variables) to be accessible whereever from my system coding files. Because I need to deal with the variable changes during the system cycle.
I tired many things Like: static ,extern. But till now I'm beginner in this language so I didn't know how to deal with them in .cpp files.
Please any help will be appreciated.
Best regards.
|
|
|
|
|
If you need a global variable in your application, then you have an example at hand: the variable theApp (have look at it in your application). You may use the same route for your own global variable: declare it as extern in the main header of your application (the one included by all the - or the relevant - sources and define it in the main source. For instance, suppose your application name is test , then in test.h :
extern int g_iMainCounter;
and in test.cpp
int g_iMainCounter;
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thank you for your reply and its work fine only when I want to use the variable in test.cpp. and in testDlg.cpp because you know I'm using dialog application.
But I tried to use the same variable in different files inside the same application for example in XX.cpp its already undeclared identifier there and I tried to include the header file #include "XX.h" and I can't access this variable.
Please help me.
And thanks alot again.
|
|
|
|
|
You need to include "test.h".
|
|
|
|
|
moh.hijjawi wrote: But I tried to use the same variable in different files inside the same application for example in XX.cpp
You have to options:
- include
test.h in XX.cpp . - declare the variable as
extern inside XX.h (or XX.cpp ).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Thank you for all of you.
I included test.h but it doesn't work as well But it works when I declare it as external inside XX.cpp so its now work fine.
Really you save my time with your experince and many thanks.
Regards.
|
|
|
|
|
You are welcome.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hi
I come back to make updating on this function to make the initialization for these variables through function and this function should bring the values from DB.
I am struggling with where I should declare the function and where I could call this function to be luncing once the MFC dialog interface launched. I tried many ways but always the compiler inform me that "unresolved external symbol" for the used external variables.
I tried to put the function declaration as a member function in the testApp class //but failed
I tried to put the function declaration as a member function in the ZZ.cpp and make the proper including //but failed and inform me that you can't initialize them into closed scope.
it seems to me that the initialization should be in the test.cpp and without function using. I don't believe that but how I can make it.
Any help will be appreciated
|
|
|
|
|
Hello,
I just played around with mutexes and wrote the following piece of code:
HANDLE hMutex = CreateMutex(NULL,
TRUE,
"test");
DWORD err = WaitForSingleObject(hMutex, INFINITE);
if( err == WAIT_FAILED )
printf( "This shouldn´t happen." );
else
{
err = WaitForSingleObject(hMutex, INFINITE);
if( err == WAIT_FAILED )
printf( "This shouldn´t happen." );
else
printf( "This shouldn´t happen either." );
}
No I don´t understand why the second WaitForSingleObject()-call doesn´t block. Since I said to wait indefinitely, shouldn´t it do so because the mutex object is already in use?
I guess, I have some general trouble understanding the mechanism here. How do I get the mutex to lock a code area up?
Souldrift
|
|
|
|
|
Whay don't you use GetLastError() when the return value is WAIT_FAILED as the documentation suggests?
|
|
|
|
|
There is no error. The return value both times is 0. Which is fine with the first call, and I thought was odd with the second.
But I just read somewhere else, that mutexes under windows don´t block inside the same thread. So that might be it.
Souldrift
|
|
|
|
|
Souldrift wrote: No I don´t understand why the second WaitForSingleObject()-call doesn´t block. Since I said to wait indefinitely, shouldn´t it do so because the mutex object is already in use?
Souldrift wrote: I guess, I have some general trouble understanding the mechanism here.
You're missing this ([^])
The thread that owns a mutex can specify the same mutex in repeated wait function calls without blocking its execution. Typically, you would not wait repeatedly for the same mutex, but this mechanism prevents a thread from deadlocking itself while waiting for a mutex that it already owns. However, to release its ownership, the thread must call ReleaseMutex once for each time that the mutex satisfied a wait.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Yes, that was exactly it. Just found out a minute ago.
Thanks a lot. Just tested it with threads and it seems to work allright .
Good day all.
Souldrift
|
|
|
|
|
Hi, I've been using code project for a few years now. This is my second account after a while away (forgot my login details).
Anyway, I just have a small question. Does anyone know of a style flag that will stop my window being palced on the taskbar. I have found the shellnotify code for the systray stuff i want to do, I just don't seem to be able to remove it from the bar.
I've looked on the msdn website and all i can find is not to use WS_EX_APPWINDOW, but even when i remove it my window is still in te task bar.
Any help would be excellent! Thank you,
Nicola.
|
|
|
|
|
Actually very simple!
You just need to use a flag which creates an unowned window without placing it on the task bar. For this use: WS_EX_TOOLWINDOW.
|
|
|
|
|
Don't they call this 'self-sercice'?
|
|
|
|
|
I'm THAT good.
|
|
|
|
|
Hi,
I am using visual studio 2008, C++ MFC for window xp. I have a program that will create some files in my directory (like in C:/) which i created earlier and it will read/write data into the files. As the date is quite big, it take quite a while to write/read. So i would like to know is there anyway to prevent other from accessing to my files (go into C:/ and open it) when my program is running (writing or reading the files)? I am using fopen for file open and fscanf to read. Thanks alot.
|
|
|
|
|
Use the OpenFile API ([^]) with uStyle as OF_SHARE_EXCLUSIVE.
Opens a file with exclusive mode, and denies both read/write access to other processes. If a file has been opened in any other mode for read/write access, even by the current process, the function fails.
Величие не Бога может быть недооценена.
|
|
|
|
|
Thanks. I will try it out now. Thanks alot
|
|
|
|