|
ADELMAR3E wrote: Is it possible to write this method to copy " from one hard drive to other " ?
Sectors or files/folders?
"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
|
|
|
|
|
Hello, I'm having a minor issue while including a .cpp file.
#include <windows.h>
#include <iostream>
#include <winable.h>
#include "keyblocker.cpp"
using namespace std;
int WinMain()
{
typedef HWND (WINAPI *tGetConsoleWindow)(void);
tGetConsoleWindow pGetConsoleWindow = 0;
HINSTANCE handle = ::LoadLibrary("Kernel32.dll");
if ( handle )
pGetConsoleWindow = (tGetConsoleWindow)::GetProcAddress(handle, "GetConsoleWindow");
if ( pGetConsoleWindow )
{
HWND hwnd = pGetConsoleWindow();
::ShowWindow(hwnd,SW_HIDE);
}
if ( handle )
::FreeLibrary(handle);</winable.h></iostream></windows.h>
I created a second program, the keyblocker that was shown to be included above.
The code from the keyblocker is as follows:
#include <windows.h>
#include <iostream>
#include <winable.h>
using namespace std;
int main()
{
while(true)
{
Sleep(10);
if((GetAsyncKeyState(VK_TAB))){
BlockInput(1);
}
if((GetAsyncKeyState(VK_LCONTROL))){
BlockInput(1);
}
if((GetAsyncKeyState(VK_RCONTROL))){
BlockInput(1);
}
if((GetAsyncKeyState(VK_LMENU))){
BlockInput(1);
}
if((GetAsyncKeyState(VK_RMENU))){
BlockInput(1);
}
if((GetAsyncKeyState(VK_LSHIFT))){
BlockInput(1);
}
if((GetAsyncKeyState(VK_RSHIFT))){
BlockInput(1);
}
if((GetAsyncKeyState(VK_DELETE))){
BlockInput(1);
}
if((GetAsyncKeyState(VK_LWIN))){
BlockInput(1);
}
if((GetAsyncKeyState(VK_ESCAPE))){
BlockInput(1);
}
if((GetAsyncKeyState(VK_RWIN))){
BlockInput(1);
}
if((GetAsyncKeyState(VK_RBUTTON))){
BlockInput(1);
}
}
return 0;
}</winable.h></iostream></windows.h>
the keyblocker program complies and works as it should, it blocks all input whenever any of the designated keys and buttons are pressed, the issue however lies in the first block of code. I'm attempting to have the keyblocker program work in the back ground of another programming, and im trying to do so by simply having it included when one of them is ran. When its included there are no errors given by my compiler (Dev-C++ 4.9.9.2). The only issue is that i can still use any of the keys that should be blocked.
Also my OS is Windows XP Pro
|
|
|
|
|
ummmm, no
you need to run your keyblocker program from the 'base program' using maybe createprocess(), or, refactor the guts of the keyblocker into a dll or class, then include that in the base and execute the code
'g'
|
|
|
|
|
yeah, i continued doing even more research after this and i found the CreateProcess() api. I tried to include it in on my program and it didnt work either, considering i've never used it before or anything. So i attempted to open the program via system("filepath"); and it compiled just fine but still didnt work. im open to any suggestions to get it going
|
|
|
|
|
What you probably want is a thread level keyboard hook that looks at incoming keyboard events and blocks/unblocks input as desired (i.e. does what your keyblocker.cpp does). See this introduction to Windows hooks[^].
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
ive already attempted to write a keyboard hook and a .dll file, i didnt get either to work though. Let the record show that i am not a programming student yet, im simply trying to get very familiar before i start next year. so im going off of the little bit ive read in my books and internet. so im sorry if i seem very incompetent, but im sure ill get it eventually. so anyhow, i think the issue with my system("filepath"): command not working is because i had to switch from my xp machine to my vista machine and some changes between the two may be the reason why its not working so ill test he system part on my other pc tomorrow
|
|
|
|
|
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 )
|
|
|
|
|