|
The thing is that BlockInput only blocks the input queue of the thread it's executed in - at least that's what the documentation[^] says, so your separate process implementation can't work, as it can only block its own input.
Also - a keyboard hook doesn't need a DLL if it's just for your current thread. The following code adds a hook to the calling thread that blocks input if the 'A' key is pressed. To activate it, you just need to call the StartBlockingFilter function.
HHOOK myHook = 0;
LRESULT CALLBACK KeyboardFilter(int code, WPARAM wParam, LPARAM lParam)
{
if (wParam == 'a' || wParam == 'A')
BlockInput(TRUE);
return CallNextHookEx(myHook, code, wParam, lParam);
}
void StartBlockingFilter()
{
myHook = ::SetWindowsHookEx(WH_KEYBOARD, &KeyboardFilter, 0, GetCurrentThreadId());
}
void FinishBlockingFilter()
{
BlockInput(FALSE);
::UnhookWindowsHookEx(myHook);
}
You could put this code in a .cpp file, #include it and call StartBlockingFilter from where it was included.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Uh, so I attempted to add that code into a .ccp file, but it failed to compile properly afterwards. I don't know whether there were things I needed to change or add to it because I've never gone over keyboard hooks before. Terribly sorry for all the issues..
|
|
|
|
|
You'd need to #include <Windows.h> before that code.
gamefreak2291 wrote: Uh, so I attempted to add that code into a .ccp file, but it failed to compile properly afterwards
What errors did you get?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
<pre>#include <windows.h>
#include <iostream>
#include <Winable.h>
using namespace std;
int main(void)
{
HHOOK myHook = 0;
LRESULT CALLBACK KeyboardFilter(int code, WPARAM wParam, LPARAM lParam)
{
if (wParam == 'a' || wParam == 'A')
BlockInput(TRUE);
return CallNextHookEx(myHook, code, wParam, lParam);
}
void StartBlockingFilter()
{
myHook = ::SetWindowsHookEx(WH_KEYBOARD, &KeyboardFilter, 0, GetCurrentThreadId());
}
void FinishBlockingFilter()
{
BlockInput(FALSE);
::UnhookWindowsHookEx(myHook);
}
}
return 0;
}
</pre>
There's the code I used, and the errors I got are as follows:
<pre> H:\Programs\Worthwhile Programs\hidden\hooker.cpp In function `int main()':
12 H:\Programs\Worthwhile Programs\hidden\hooker.cpp a function-definition is not allowed here before '{' token
18 H:\Programs\Worthwhile Programs\hidden\hooker.cpp expected primary-expression before "void"
18 H:\Programs\Worthwhile Programs\hidden\hooker.cpp expected `;' before "void"
23 H:\Programs\Worthwhile Programs\hidden\hooker.cpp expected primary-expression before "void"
23 H:\Programs\Worthwhile Programs\hidden\hooker.cpp expected `;' before "void"
23 H:\Programs\Worthwhile Programs\hidden\hooker.cpp At global scope:
30 H:\Programs\Worthwhile Programs\hidden\hooker.cpp expected unqualified-id before "return"
30 H:\Programs\Worthwhile Programs\hidden\hooker.cpp expected `,' or `;' before "return"
31 H:\Programs\Worthwhile Programs\hidden\hooker.cpp expected declaration before '}' token </pre>
|
|
|
|
|
OK....you needed to put the code in your main.cpp, NOT in the main function - you aren't allowed to define nested functions in C++.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Sigh, alright I added the code into my main file and I got it to compile without errors after one simple tweak. I then added in LONG StartBlockingFilter into a spot of my main() function and it is still compiling properly, however its not blocking input when I press a or A. I'm thinking its going to be a major issue.. I'm thinking that the keyboard hook is not going to work with MessageBoxes, which my entire code revolves around. I don't know if the Message Boxes are the issue are not, i hope not.
|
|
|
|
|
gamefreak2291 wrote: I'm thinking that the keyboard hook is not going to work with MessageBoxes
The keyboard hook works OK - the BlockInput, however, doesn't. You can, however, simulate BlockInput by using keyboard and mouse hooks to stop messages getting through - this code stops mouse and keyboard messages being sent to the message box:
HHOOK myKeyboardHook = 0;
HHOOK myMouseHook = 0;
bool blocking = false;
LRESULT CALLBACK KeyboardFilter(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0) return CallNextHookEx(myKeyboardHook, nCode, wParam, lParam);
if (wParam == 'a' || wParam == 'A')
blocking = true;
else if (wParam == 'b' || wParam == 'B')
blocking = false;
if (blocking) return 1;
return CallNextHookEx(myKeyboardHook, nCode, wParam, lParam);
}
LRESULT CALLBACK MouseFilter(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0 || !blocking) return CallNextHookEx(myMouseHook, nCode, wParam, lParam);
return 1;
}
void StartBlockingFilter()
{
myKeyboardHook = ::SetWindowsHookEx(WH_KEYBOARD, &KeyboardFilter, 0, GetCurrentThreadId());
myMouseHook = ::SetWindowsHookEx(WH_MOUSE, &MouseFilter, 0, GetCurrentThreadId());
}
void FinishBlockingFilter()
{
::UnhookWindowsHookEx(myKeyboardHook);
::UnhookWindowsHookEx(myMouseHook);
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Alright, I threw in the new bit of code and it also compiled correctly. However I still can't get it to block input when I press a or A. I'm not sure if I'm calling it correctly, I'm trying to call it as follows:
{ LONG StartBlockingFilter;
MessageBox(NULL, "Welcome to my program", "Welcome", MB_OK);
MessageBox(NULL, "Just run through all the messages\n" "and you'll be done", "Instructions", MB_OK);
MessageBox(NULL, "Oh, and a word of warning.. I wouldn't\n" "suggest using Ctrl+Alt+Del, Alt+Tab\n"
"the Windows keys, the Escape keys\n" "or your mouse..", "Warning", MB_OK);}
Is that the correct way to call it into use?
|
|
|
|
|
Noooo - you need to call StartBlockingFilter, not declare a variable of that name:
{ StartBlockingFilter();
MessageBox(NULL, "Welcome to my program", "Welcome", MB_OK);
MessageBox(NULL, "Just run through all the messages\n" "and you'll be done", "Instructions", MB_OK);
MessageBox(NULL, "Oh, and a word of warning.. I wouldn't\n" "suggest using Ctrl+Alt+Del, Alt+Tab\n"
"the Windows keys, the Escape keys\n" "or your mouse..", "Warning", MB_OK);}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Alright I switched it to StartBlockingFilter(); but it still did not work
but it still is not blocking the input when I press a or A. I also sent
you and e-mail explaining more. Respond if you want
|
|
|
|
|
i have started turning this program for a class into a container template class program and i'm having trouble with one part.
Stack *Z = new Stack;
the line above is where i'm having trouble. this line is in my main program and i need to set it up for template but i don't know how to do it for this line i can do templates for everywhere else but because of the * i'm not sure how to handle this one. please any help would be great! thank you!
below is the rest of the code:
#include <iostream><br />
<br />
using namespace std;<br />
<br />
struct Box {<br />
int data;<br />
struct Box * next;<br />
};<br />
template < typename T ><br />
class Stack {<br />
<br />
public:<br />
Stack();<br />
~Stack();<br />
bool Pop(int &);<br />
void Push(int);<br />
bool Empty();<br />
private:<br />
struct Box * Start;<br />
};<br />
template <typename t=""><br />
Stack <t>::Stack() { Start=NULL; }<br />
template <typename t=""><br />
Stack <t>::~Stack() {<br />
<br />
struct Box *p1=Start, *p2;<br />
<br />
while (p1!=NULL) {<br />
p2=p1->next;<br />
delete p1;<br />
p1=p2;<br />
}<br />
}<br />
template <typename t=""><br />
bool Stack <t>::Pop(int &x) {<br />
<br />
struct Box *p1;<br />
if (Start==NULL) return false;<br />
<br />
x=Start->data;<br />
p1=Start->next;<br />
delete Start;<br />
Start=p1;<br />
return true;<br />
}<br />
template <typename t=""><br />
void Stack <t>::Push(int x) {<br />
<br />
struct Box *p1 = new struct Box;<br />
p1->data = x;<br />
p1->next = Start;<br />
Start=p1;<br />
return;<br />
}<br />
template <typename t=""><br />
bool Stack <t>::Empty() { if (Start==NULL) return true; else return false; }<br />
<br />
<br />
int main() {<br />
template <typename t=""><br />
Stack X;<br />
int x;<br />
<br />
for (int i=0; i<10; ++i) X.Push(i);<br />
<br />
while(X.Pop(x)) cout << x << endl;<br />
<br />
cout << "-------------------------------" << endl;<br />
<br />
Stack *Z = new Stack;<br />
<br />
for (int i=0; i<10; ++i) (*Z).Push(i);<br />
<br />
while(Z->Pop(x)) cout << x << endl;<br />
<br />
Stack Y[10];<br />
<br />
for (int j=0; j<10; j++) {<br />
<br />
for (int i=0; i<10; ++i) Y[j].Push(i);<br />
<br />
while(Y[j].Pop(x)) cout << x << endl;<br />
<br />
}<br />
<br />
return 0;<br />
<br />
}</typename></t></typename></t></typename></t></typename></t></typename></t></typename></iostream>
|
|
|
|
|
first of all I dont know why you'd write your own, since the STL provides one ..
but assuming I cant dissuade you, I think :-
Brandon Ramirez wrote: Stack *Z = new Stack;
should be
Stack<int> *Z = new Stack<int> ;
for a stack of int's ... I am in two minds as to wether :-
Stack<int> *Z = new Stack<int>();
is more correct - suck it and see ?
'g'
|
|
|
|
|
Garth J Lancaster wrote: I am in two minds as to wether :-
Stack<int> *Z = new Stack<int>();
is more correct - suck it and see ?
No difference - they both just call the default constructor, so it's just a matter of style.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
thanks for the clarification
'g'
|
|
|
|
|
thanks Garth, that was helpful! i know there is on in the STL but it was an assignment to make our own.
|
|
|
|
|
Hello, folks:
in trial version software, we all see the dialog box with a date frame, during which a user is allowed to test the application until the last day expired.I wonder if there is any component out there up for grab? Or any code?
thanks,
jon
|
|
|
|
|
Try Trail Creator at http://softwarekey-trial-creator.concept-software-inc.qarchive.org/
Why the hell is the link stuff not working
|
|
|
|
|
Hi,
I need to add Vertical and Horizontal scrollbars to a CListBox. I have checked Horizontal scroll and Vertical scroll in the properties of Listbox control , but it doesn't work. I also tried with m_AvailableList.ShowScrollBar(SB_BOTH); But this doesn't work..
Can I know how to add vertical and horizontal scrollbars to ListBox control.
Thanks in advance.
Venkat
|
|
|
|
|
You need to items for see scrollbars.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
: Use Dev-C++ 4.9.9.2
Your task is to implement a Catalog of Books.
1. For this first you have to implement Book class The Book class is a simple class to store information about a particular book and it has the following data members:
o Title of the book (string)
o Author of the book (string)
o ISBN of the book (string)
o Status of the book (bool)
Write default and parameterized constructors and setters getters for the Book class.
2. Catalog class is a linked list of Book objects and that can perform the following functionality.
o Add method to add a book in the Catalog
o printAllBooks method to print all the books in the Catalog.
o searchByAuthor method will take author name as an argument and will find a book written by that author.
o Available method to print all those books that are currently available. If the status of a book is false than it means that book is not available, if the status is true then it means book is available.
3. Include a main function as follows:
o Main will create 5 different books and add them in Catalog
o Print all books present in Catalog linked list.
o Search a Book by its Author name.
o Print all the books which are available.
Hint:
Make Nodes of Book type and then link them to make Catalog linked list. It means there will be another class between Book and Catalog and that is BookNode class
|
|
|
|
|
Well, good luck with your homework.
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]
|
|
|
|
|
must be a new course starting somewhere - saw two like this last week
'g'
|
|
|
|
|
This isn't even subtle.
This signature was proudly tested on animals.
|
|
|
|
|
#include <iostream>
#include <string>
using namespace std;
int wmain(int , wchar_t* )
{
for ( ; ; )
{
cout << "Enter Title: ";
string s;
cin >> s;
cout << "Title: \"" << s << "\" is invalid." << endl << endl;
}
return 0;
}
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Amazing how a complex problem can be easily solved with such a few lines of code, isn't it?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|