Click here to Skip to main content
16,016,184 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Can I add a menu item to the popup menu of any CEdit? Pin
Hamid_RT31-Oct-06 4:50
Hamid_RT31-Oct-06 4:50 
GeneralRe: Can I add a menu item to the popup menu of any CEdit? Pin
ThatsAlok31-Oct-06 4:56
ThatsAlok31-Oct-06 4:56 
GeneralRe: Can I add a menu item to the popup menu of any CEdit? Pin
Hamid_RT31-Oct-06 5:15
Hamid_RT31-Oct-06 5:15 
GeneralRe: Can I add a menu item to the popup menu of any CEdit? Pin
ThatsAlok31-Oct-06 17:22
ThatsAlok31-Oct-06 17:22 
GeneralRe: Can I add a menu item to the popup menu of any CEdit? Pin
Hamid_RT31-Oct-06 18:15
Hamid_RT31-Oct-06 18:15 
AnswerRe: Can I add a menu item to the popup menu of any CEdit? Pin
James R. Twine31-Oct-06 5:03
James R. Twine31-Oct-06 5:03 
GeneralRe: Can I add a menu item to the popup menu of any CEdit? Pin
ThatsAlok31-Oct-06 5:09
ThatsAlok31-Oct-06 5:09 
QuestionCWinThread reading event messages [modified] Pin
edvintas31-Oct-06 4:07
edvintas31-Oct-06 4:07 
Hello everybody Smile | :)
I am trying to launch "An All-Purpose Keyboard Hook"(http://www.codeproject.com/system/KeyHook.asp[^]) dll with my application, but not successful... I have no idea why dll doesn't post messages to my application. Confused | :confused: This is a source code:
***Thread.cpp***<br />
<pre>#include "stdafx.h"
#include "ThreadsApp.h"
#include "KeyHook.h"

IMPLEMENT_DYNCREATE(Thread, CWinThread)

Thread::Thread(){ theApp.FileWrite("Thread constructed\n"); }
Thread::~Thread(){ theApp.FileWrite("Thread destructed\n"); }

BOOL Thread::InitInstance()
{
	InstallKeyHook();
	KEYENTRY m_entry;
	m_entry.nMessage = WM_MYTHREADMESSAGE; // Our message ID
	m_entry.hCallWnd = (HWND)Thread::m_hThread;// Send message to this window
	m_entry.hHookWnd = 0; // Capture key-strokes occurred in any windows
	m_entry.iCombKeys = 0; // combination keys don't matter
	m_entry.iIndicators = 0; // Caps-lock, Num-lock, Scroll-lock on/off states do not matter
	m_entry.iKeyEvent = 0; // Capture all key events
	m_entry.iMinVKCode = 0x00; // Capture all keys
	m_entry.iMaxVKCode = 0xff;
	
	if(AddKeyEntry(&m_entry) != KH_OK)
	{
		theApp.FileWrite("AddKeyEntry failed\n");
		return TRUE;
	}
	theApp.FileWrite("Thread initialized\n");
	return TRUE;
}

int Thread::ExitInstance()
{
	theApp.FileWrite("Thread clean up\n");
	return CWinThread::ExitInstance();
}

void Thread::MyMessageHandler(WPARAM wParam, LPARAM lParam)
{
	char data[64] = "";
	itoa(wParam, data, 10);
	strcat(data, " <<< WPARAM\n");
	theApp.FileWrite(data);
}

BEGIN_MESSAGE_MAP(Thread, CWinThread)
	ON_THREAD_MESSAGE(WM_MYTHREADMESSAGE, MyMessageHandler)
END_MESSAGE_MAP()</pre><br />
<br />
<code>***ThreadsApp.h***<br />
<pre>class ThreadsApp : public CWinApp
{
	public:
		ThreadsApp();
		void FileWrite(char *data);
		virtual BOOL InitInstance();
};

class Thread : public CWinThread
{
	DECLARE_DYNCREATE(Thread)

public:
	Thread();           
	virtual ~Thread();
	virtual BOOL InitInstance();
	virtual int ExitInstance();
	void MyMessageHandler(WPARAM wParam, LPARAM lParam);

protected:
	DECLARE_MESSAGE_MAP()
};

extern ThreadsApp theApp;</pre><br />
<br />
<code>***ThreadsApp.cpp***<br />
<pre>#include "stdafx.h"
#include "ThreadsApp.h"

ThreadsApp::ThreadsApp()
{
}

void ThreadsApp::FileWrite(char *data)
{
	FILE *f;
	errno_t err;
	err = fopen_s(&f, "C:\\debug.txt", "a");
	fprintf(f, data);
	fflush(f);
	fclose(f);
}

ThreadsApp theApp;

BOOL ThreadsApp::InitInstance()
{
	FileWrite("Application initialized\n");
	Thread* pThread;
     pThread = new Thread();
     pThread->CreateThread();
     pThread->PostThreadMessage(WM_MYTHREADMESSAGE,1,NULL);
	 pThread->PostThreadMessage(WM_MYTHREADMESSAGE,2,NULL);
	 pThread->PostThreadMessage(WM_MYTHREADMESSAGE,3,NULL);
    FileWrite("Waiting for the end of thread...\n");
	WaitForSingleObject(pThread->m_hThread, 5000);
    FileWrite("Program terminated...\n");
	return TRUE;
}</pre><br />
<br />
So, what i am doing wrong? :^)<br />
I hope somebody will help :rolleyes:<br />
and thank you very much in advance :rose: :)<br />
<br />
<br />
 -- modified at 10:15 Tuesday 31st October, 2006

AnswerRe: CWinThread reading event messages Pin
TClarke31-Oct-06 5:59
TClarke31-Oct-06 5:59 
GeneralRe: CWinThread reading event messages [modified] Pin
edvintas31-Oct-06 6:52
edvintas31-Oct-06 6:52 
GeneralRe: CWinThread reading event messages Pin
TClarke1-Nov-06 0:27
TClarke1-Nov-06 0:27 
GeneralRe: CWinThread reading event messages Pin
edvintas1-Nov-06 3:03
edvintas1-Nov-06 3:03 
QuestionRounded windows Pin
Waldermort31-Oct-06 3:44
Waldermort31-Oct-06 3:44 
AnswerRe: Rounded windows Pin
ThatsAlok31-Oct-06 4:47
ThatsAlok31-Oct-06 4:47 
AnswerRe: Rounded windows Pin
Michael Dunn31-Oct-06 7:13
sitebuilderMichael Dunn31-Oct-06 7:13 
GeneralRe: Rounded windows Pin
Waldermort31-Oct-06 10:25
Waldermort31-Oct-06 10:25 
QuestionBackgound file operation monitoring Pin
TPN31-Oct-06 3:31
TPN31-Oct-06 3:31 
QuestionRe: Backgound file operation monitoring Pin
David Crow31-Oct-06 4:01
David Crow31-Oct-06 4:01 
AnswerRe: Backgound file operation monitoring Pin
ThatsAlok31-Oct-06 4:51
ThatsAlok31-Oct-06 4:51 
Questionmulti language Pin
Russell'31-Oct-06 3:27
Russell'31-Oct-06 3:27 
AnswerRe: multi language Pin
toxcct31-Oct-06 3:43
toxcct31-Oct-06 3:43 
GeneralRe: multi language Pin
Russell'31-Oct-06 5:14
Russell'31-Oct-06 5:14 
GeneralRe: multi language Pin
toxcct31-Oct-06 5:28
toxcct31-Oct-06 5:28 
QuestionCalling a Web service in VC++ Pin
Programm3r31-Oct-06 2:21
Programm3r31-Oct-06 2:21 
AnswerRe: Calling a Web service in VC++ Pin
Chris Losinger31-Oct-06 3:29
professionalChris Losinger31-Oct-06 3:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.