Hi
Since i am a newbie to win32 programming i am facing difficulty in understanding how to use these GetMessage(), SendMessage(), PostTHreadMessage() apis, please help me ...
Here is the code
#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
#include "conio.h"
#include "windef.h"
#include "winbase.h"
HINSTANCE hins;
HOOKPROC hkprc;
HHOOK hk;
HANDLE hnd;
FILE *fp;
char c;
int flag=0;
int i;
HWND wndhnd;
DWORD threadid;
BOOL bret;
MSG msg;
TCHAR buf[1024];
LPARAM lp;
int _tmain(int argc, _TCHAR* argv[])
{
//Sleep(1000);
HWND checkproc(HWND);
void install_hook(DWORD,HWND);
wndhnd=FindWindow(_T("NotePad"),NULL);
install_hook(threadid,wndhnd);
getch();
}
HWND checkproc(HWND hnd)
{
while(hnd==NULL)
{
Sleep(3000);
printf("Waiting for NOTEPAD thread\n");
wndhnd=FindWindow(_T("NotePad"),NULL);
hnd=wndhnd;
}
return hnd;
}
void install_hook(DWORD threadid,HWND windowhandle)
{
HWND wnd;
bool windowalive;
if(windowhandle==NULL)
{
wndhnd=checkproc(NULL);
} threadid=GetWindowThreadProcessId(wndhnd,NULL); hins=LoadLibrary(TEXT("C:\\Documents and Settings\\manu\\My Documents\\Visual Studio 2008\\Projects\\globalkeyhook\\Debug\\globalkeyhook.dll"));
hkprc=HOOKPROC)GetProcAddress(hins,"KeyboardProc");
hk=SetWindowsHookEx(WH_KEYBOARD,hkprc,hins,threadid);
GetModuleFileName(hins,buf,1024);
wprintf(_T("%s\n"),buf);
//RegisterHotKey(0,1,MOD_CONTROL,0x41);
MSG msg;
while(GetMessage(&msg,0,0,0))
{
switch(msg.message)
{
case WM_CLOSE:
/*if(msg.wParam==1)*/
FILE *f3=fopen("C:\\text.txt","a+");
fprintf(f3,"Hotkey pressed");
break;
}
}
if(threadid==0)
{
printf("Unhooked\n");
UnhookWindowsHookEx(hk);
}
else
{
printf("hooked to threadid-->%lu:\n",threadid);
}
while(1)
{
windowalive=IsWindow(wndhnd);
if(!windowalive)
{
//PostThreadMessage(threadid,WM_CLOSE,999,lp);
install_hook(NULL,NULL);
break;
}
}
}
This is my console application code written in vc++ VS 2008 which hooks on to notepad. I have one DLL for recording keystrokes.
Now where should i implement my GetMessage() in the console application exe or the dll.
I have to send a message to my console application when my active notepad window is closed so tat i print "WINDOW CLOSED" on my console.How to communicate between notepad and my console app using these api's. I have used GetMessage in the above code but not working. Please explain how to invoke Getmessage(), when will it be actually invoked, from where to where and how it sends messages
THank you