|
Thank you - I'll check it out.
// MCP, MCSD
// Software for animal shelters
// http://www.smartpethealth.com
|
|
|
|
|
hi guys, I'm trying to get a global mouse hook and listen to mouse clicks clicked on the windows desktop, however, I only succeeded in getting mouse clicks on a client window, but can't getting mouse clicks on the desktop, the following is my code(in trying to hook the desktop): any help and pointers are appreciated
#include <iostream.h>
#include<fstream.h>
#include <windows.h>
#include <stdlib.h>
#include<stdio.h>
#define WIN32_LEAN_AND_MEAN // Quicker build times;
#define WINDOWNAME "Simple Sample Application"
/*----------------------------------------------------------------*\
Global Variables - to vanish in the C++ version;
\*----------------------------------------------------------------*/
HWND hWnd; // Main window handle;
int screenHeight,screenWidth;
ofstream errstream("mouseLog.txt");
#pragma data_seg(".shared") // you must define as SHARED in .def
HHOOK mouseHook,keyboardHook;
HINSTANCE g_hinstance;
//DWORD g_dwLastTick = 0; // tick time of last input event
//LONG g_mouseLocX = -1; // x-location of mouse position
//LONG g_mouseLocY = -1; // y-location of mouse position
#pragma data_seg()
//#pragma comment(linker, "/section:.IdleTrac,rws")
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lparam){
switch(wParam){
case 27:
UnhookWindowsHookEx(mouseHook);
UnhookWindowsHookEx(keyboardHook);
errstream.close();
PostQuitMessage(0);
}
return 0;
}
LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lparam){
MessageBox(hWnd,"in mouse proc ","",MB_OK);
MOUSEHOOKSTRUCT* mousehook=(MOUSEHOOKSTRUCT*)lparam;
POINT p=mousehook->pt;
switch(wParam){
case WM_RBUTTONDOWN:
MessageBox(hWnd,"right button down","",MB_OK);
// errstream<<"mouse position is "<
|
|
|
|
|
You need to put your hook code in a DLL. That is the only way that you can get your code installed into another applications process space.
Then you will need to use either a shared data segment in the DLL to communication the information back to you, or some other form of Interprocess Communucation (IPC).
Good luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
thanks a lot, but I'm kind of new to windows programming and this all seem a bit abstract. So after I put my hooking procedures in a dll, am I able to call those procedures from another piece of code?
would you give me some explanation/code snipets in details?
thanks
|
|
|
|
|
I am trying to recursively list all the files on a FTP server. Right now, all it does is list the files in root. The function appears to be called for each directory it encounters, but it never finds any files on it. The server log never shows a list command being issued, but a printf shows that the function is entered. Any suggestions?
CInternetSession sess(_T("SomeApp/1.0"));
CFtpConnection* pConnect = NULL;
void Search(CString sPath)
{
CFtpFileFind finder(pConnect);
CString sSearch;
sSearch.Format("%s/*",sPath);
try
{
BOOL bWorking = finder.FindFile(sSearch);
while (bWorking)
{
bWorking = finder.FindNextFile();
printf("%s\n", (LPCTSTR)finder.GetFilePath());
if(finder.IsDirectory() && !finder.IsDots())
Search(finder.GetFilePath());
}
finder.Close();
}
catch (CInternetException* pEx)
{
TCHAR sz[1024];
pEx->GetErrorMessage(sz,1024);
printf("ERROR: %s\n",sz);
pEx->Delete();
}
}
pConnect = sess.GetFtpConnection(_T("server"),"Username","password");
Search("");
Thanks,
Aaron Stubbendieck
modified 12-Jul-20 21:01pm.
|
|
|
|
|
hi guys I have a windowns application that tries to reboot window, but according the error code, A required privilege is not held by the client application. how do I resolve this problem? the following is my code:
thanks!!
#include <windows.h>
#include <stdio.h>
#include <iostream.h>
void main(){
int res=ExitWindowsEx(EWX_REBOOT,0);
printf("%d",res);
DWORD d=GetLastError();
cout<
|
|
|
|
|
Try this code:
void ShutDownMe()
{
OS_VERSION_INFO osvi;
BOOL bNeedPrivileges;
ZeroMemory(&osvi,sizeof(OS_VERSION_INFO));
GetOSVersion(&osvi);
if (IsWindows95(&osvi) || IsWindows95OSR2(&osvi) || IsWindows95SP1(&osvi) ||
IsWindows98(&osvi) || IsWindows98SE(&osvi) || IsWindows98SP1(&osvi))
bNeedPrivileges=FALSE;
else
bNeedPrivileges=TRUE;
if (bNeedPrivileges)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
return;
}
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES)NULL, 0);
if (GetLastError() != ERROR_SUCCESS)
{
return;
}
}
ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0);
}
A. Riazi
|
|
|
|
|
thanks Riazi,
but what headers do I need to include to make this work? OS_VERSION_INFO does not exist in windows.h
thanks
|
|
|
|
|
Take a look at GetVersionEx function.
OSVERSIONINFO declared in Winnt.h and included in Windows.h.
A. Riazi
|
|
|
|
|
Hi. I have a CTypedPtrArray of CObjects derivade class. Im trying to implement a operator= overload, it compiles well, but the operator is not called!! ive putted a breakpoint inside it and it never enters it! Take a look...
class CLSITask : public CObject
{
...
CLSITask &operator=(const CLSITask &task);
...
}
//.CPP
CLSITask &CLSITask::operator=(const CLSITask &task)
{
...copying variables...
}
Thanks in advance!
|
|
|
|
|
how do u use it when u say "not called"?
CLSITask c0;
CLSITask c1;
c1=c0; //called in this way?
another thing is if define operator=, u must define copy constructor at same time (keep it as a habit).
includeh10
|
|
|
|
|
I'm trying to create an MDI app with multiple document templates.
When I have just one AddDocTemplate the file/new creates a new window.
CMultiDocTemplate* pMaintainTemplate;
pMaintainTemplate = new CMultiDocTemplate(
IDR_GOOGLETYPE,
RUNTIME_CLASS(CGoogleDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CGoogleView));
AddDocTemplate(pMaintainTemplate);
As soon as i add a second AddDocTemplate right below the above code in my InitInstance method the file/new does nothing. My second AddDocTemplate looks like this
CMultiDocTemplate* pProductionTemplate;
pProductionTemplate = new CMultiDocTemplate(
IDR_GOOGLETYPE,
RUNTIME_CLASS(cProductionDoc),
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(cProductionView));
AddDocTemplate(pProductionTemplate);
How can I get the file/new command to ask me which document type to create??
-perseus
|
|
|
|
|
What you are asking about should happen automatically when you have multiple document templates. When you click ID_FILE_NEW, command processing should get mapped through by the application framework to the void CDocManager::OnFileNew() function declared in DOCMGR.CPP in the MFC. If you look at the function code, you will see that by default if there are 2 or more doc templates a selection dialog box will be displayed.
The function is virtual so if you have your own implementation of this function already then you may have altered this behaviour.
Roger Allen
Sonork 100.10016
WHats brown and sticky?
A stick or some smelly stuff!
|
|
|
|
|
thats what i thought...but i couldn't figure out why it wasn't working.
It turns out that i fixed my problem. I needed to add string table entries for my menu resources. once i did that my problems went away.
do you know why this is??
thanks for the response
-perseus
|
|
|
|
|
I have no idea as to how to do this. I have my window set up with a file menu and everything (print and exit work), however I can not figure out how to do this (or an open file dialog for that matter). I was wondering if anyone could help by telling me how to do this with MSVC++. I only ask because I have been searching on the internet for a few months and I cannot find any tutorials on this subject that actually work. Some seem to work just fine for the creator, but not for me. Any help would be appreciated.
Thanks,
orcblood
|
|
|
|
|
It's GetSaveFileName() if you're using the API, or CFileDialog if you're using MFC or WTL.
--Mike--
The Internet is a place where absolutely nothing happens.
-- Strong Bad
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Hmm thanks, how would I add file support (ie a .txt file - should be easiest no bit blitting or anything )? I have a book on windows programming but it doesn't mention anything about doing this in there. I would like to use the API, but I just don't know how to program anything in. Or if theres a tut site that you know of where I could find an easy explination (that works) then that would help too.
Any help would be appreciated once again, thanks.
orcblood
|
|
|
|
|
Hi all
Is it possible to get the name of a key on the keyboard but only knowing the virtual-key code? I know you can store all the key names and use it as a list to get the name. But isn’t it possible to get it from a windows API? I also know that you can use the GeyKeyNameText API function but that requires an lParam parameter with keystroke information but isn’t it possible to fake an lParam message and use it in GeyKeyNameText? Or are there other methods or functions of getting the key name from a virtual-key code?
Aidman » over and out
|
|
|
|
|
You are probably looking to function GetKeyNameText Function [^]
To use it, virtual-key codes have to be converted using MapVirtualKeyEx .
HTH,
K.
Angels banished from heaven have no choice but to become demons
Cowboy Bebop
|
|
|
|
|
Yes, but the GetKeyNameText function needs a lParam parameter and where the ScanCode is in a bitfeild. How do I place the Scancode (that is converted from the virtual-keycode) in a bitfeild?
Aidman » over and out
|
|
|
|
|
Here's the way to do it:
Let's suppose you want to convert the virtual key nVirtKey (UINT)
#define BUFFER_LEN 50<br />
TCHAR szBuffer [BUFFER_LEN + 1];<br />
<br />
UINT nScanCode = ::MapVirtualKeyEx (nVirtKey, 0, ::GetKeyboardLayout (0)) <<16 | 0x1;<br />
<br />
if (nVirtKey >= VK_PRIOR && nVirtKey <= VK_HELP){<br />
nScanCode |= 0x01000000;<br />
}<br />
<br />
HTH,<br />
<br />
K.<br />
::GetKeyNameText (nScanCode, szBuffer, BUFFER_LEN);
Angels banished from heaven have no choice but to become demons
Cowboy Bebop
|
|
|
|
|
Thanks this works, but I can oneastly say I have no idea how it all works
Sorry, but could you explain exactly what the "<<16 | 0x1;" and "nScanCode |= 0x01000000;" part does?
Aidman » over and out
|
|
|
|
|
The GeyKeyNameText takes as first parameter lParam.
MSDN says:
lParam
[in] Specifies the second parameter of the keyboard message (such as WM_KEYDOWN) to be processed. The function interprets the following portions of lParam.
Bits Meaning
16–23 Scan code.
24 Extended-key flag. Distinguishes some keys on an enhanced keyboard.
25 "Don't care" bit. The application calling this function sets this bit to indicate that the function should not distinguish between left and right CTRL and SHIFT keys, for example.
the operation <<16 (shifting 16 bits to the left) sets the bits 16 to 23. The operation |= 0x01000000 sets the extendey key flag, the bit 24.
If you look in MSDN to the description of WM_KEYDOWN, you'll see that the bits 0 to 15 are used to set the repeat count. Here it's done with the |0x1
This last operation is probably useless, 'cause it should not be interpreted by GetKeyNameText.
HTH,
K.
Angels banished from heaven have no choice but to become demons
Cowboy Bebop
|
|
|
|
|
Ok thank you for you help it is great, I think I got parts of it figuerd. But I don't completly understand the bit shifting operation and the "|=" operation. Do you know any other good examples or articales/tutorials on this type of operations? And what is this type of operations called?
Aidman » over and out
|
|
|
|
|
These operators are standard C operators. You should find all the info about them in MSDN
(note: a |= b <=> a = a | b , as i += j <=> i = i + j )
Angels banished from heaven have no choice but to become demons
Cowboy Bebop
|
|
|
|