|
Hi! I need to create a program on keyboard hook on C++. The problem is that I'm confuse on how to use the SetWindowsHookEx() especially on the first parameter idHook. Can anyone give me advice on this matter?
Thank you in advance.
|
|
|
|
|
Will71 wrote:
The problem is that I'm confuse on how to use the SetWindowsHookEx() especially on the first parameter idHook.
It's the type of hook that you are interested in installing. The documentation sums it up real well. In your case, it sounds like you want a WH_KEYBOARD or WH_KEYBOARD_LL hook.
Will71 wrote:
Can anyone give me advice on this matter?
Aside from Googling, you can also search the CP articles for SetWindowsHookEx() .
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
DavidCrow wrote:
WH_KEYBOARD or WH_KEYBOARD_LL hook
Thank you for your quick response.
Let me rephrase my question. I tried using WH_KEYBOARD or WH_KEYBOARD_LL on the parameters before, but it always give me unknown identifier when I compile. I also tried "complete word" but it never shows these two hooks.
Thank you again.
|
|
|
|
|
Will71 wrote:
...but it always give me unknown identifier when I compile.
It sounds as though you failed to include a header file. Perhaps you could provide a code snippet and the compiler message.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi there
Is there any way to "put" a window created by my application into antoher window's thread so it can receive message e.g. wm_paint?
Thanks for reading
|
|
|
|
|
I'm not sure if this is a working idea or not!
Call GetWindowLong() with GWL_WNDPROC or DWL_DLGPROC . After that you can call SetWindowLong() to assign a window in your app the the window procedure returned by GetWindowLong(). But be sure then to call thge original window procedure (returned by SetWindowLong())!
Search MSDN for more help or Google... but as I said, I'm not sure if this will work.
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
|
|
|
|
|
|
You can send/post messages to a window from any thread. WM_PAINT is a special message, in that it's not a message that is sent or posted. Windows calls the window procedure directly for WM_PAINT under certain conditions.
Taking a guess, it sounds like you're trying to have a separate thread update a window in the primary thread. The best way to accomplish this is to have the separate thread send a user-defined message to the window. In the handler for the user-defined message, call UpdateWindow() , RedrawWindow() , or whatever is necessary.
Software Zen: delete this;
|
|
|
|
|
I dont have control over the other thread - It is another application Except Microsoft will offer me their source code (I dont think this will happening in the next few weeks ) ...
I also tried to hijack the other windows WindowProc ... it works ... but if my application crashes the other application wont be function correctly anymore
It seems like i need to take another way
|
|
|
|
|
the sdi app is already in use and i'm considering switching it to an mdi app. this is due to a customer request. the customer did not request a change to mdi specifically, but implementing the request would make a lot more sense and be a hell of a lot easier if the app was mdi. if i create a new mdi app and add my old doc/view classes to it, will i be able to read my old files with Serialize()? is this switch more trouble than it's worth?
|
|
|
|
|
I have done it in the past... do not try to do it directly onto your project... use the App wizard with the same name and then copy your files over (be careful with CWinApp:IniInstance though)
And yes serialize works the same...
Good luck!
|
|
|
|
|
I am trying to use CComPtr and I get the following compiler error:
'CComPtr' : undeclared identifier
I have included the following .h files:
#include <atlbase.h>
extern CComModule _Module;
#include <atlcom.h>
#include <initguid.h>
#include <objmodel\bldauto.h>
#include <objmodel\bldguid.h>
#include <atlbase.h>
#include <atlcom.h>
what am i missing?
|
|
|
|
|
I found the solution by moving those .h files to stdafx.h
|
|
|
|
|
Hi,
In my application, MDI, I have to read an output file in one of the dialog boxes.
According to the output file, lets say 6 is read in the file.
I then have to make 6 Buttons in that Dialog box.
the number 6 could change, so I would like to know how to make it dynamic.
Any ideas?
Ehsan Behboudi
|
|
|
|
|
CButton:Create() would be a great start
Just call this function inside a for loop or something and space the buttons accordingly. You'll probably have to handle button clicks inside OnCommand() though instead of MFC message map function.
Cheers
I'm drinking triples, seeing double and acting single
|
|
|
|
|
Hi,
In my application, MDI, I have to read an output file in one of the dialog boxes.
According to the output file, lets say 6 is read in the file.
I then have to make 6 Buttons in that Dialog box.
the number 6 could change, so I would like to know how to make it dynamic.
Any ideas?
Ehsan Behboudi
|
|
|
|
|
Just use a std::vector of CButtons.
std::vector<CButton> m_Buttons;
ifstream inFile;
char buff[1024] = {0};
CString szBuff;
inFile.open("YourFile.txt");
while !inFile.eof())
{
inFile.getline(buff, sizeof(buff), chDelim);
szBuff = buff;
m_Buttons.push_back(CButton());
if(!m_Buttons.back().Create(static_cast<const char*>(szBuff), STYLEFLAGS, rectforbutton, this, uiSomeID))
TRACE("Error creating button");
m_Buttons.back().ShowWindow(SW_SHOW);
}
inFile.close();
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
how to add "find text" feature in CHtmlView to find text in its html content?
includeh10
|
|
|
|
|
I want to use the same dialog resource for three different tabs in a property sheet because each tab has the same appearance, e.g. one list control. Kind of data loaded to the list will be based on which tab is selected. Can this be done?
Eilzabeth
|
|
|
|
|
are you asking how to dynamically set the text on the property page tabs? if so, see below code.
void CMYPropertySheet::SetTabNames( const CString& page1Name, const CString& page2Name, const CString& page3Name )
{
TC_ITEM tcItem;
tcItem.mask = TCIF_TEXT;
tcItem.pszText = (LPTSTR)((LPCTSTR)page1Name);
GetTabControl()->SetItem( 0, &tcItem );
tcItem.pszText = (LPTSTR)((LPCTSTR)page2Name);
GetTabControl()->SetItem( 1, &tcItem );
tcItem.pszText = (LPTSTR)((LPCTSTR)page3Name);
GetTabControl()->SetItem( 2, &tcItem );
}
|
|
|
|
|
This is one of the constructors of CPropertyPage:
CPropertyPage( UINT nIDTemplate, UINT nIDCaption = 0 )
Simply pass the relevant string identifier as the second parameter
|
|
|
|
|
I tried Add(&m_testpage("test")) at the property sheet class's constructor, but the compiler did not like it. It says term does not evaluate to a function. May be you can tell me where to fix. I have this in the property page:
IMPLEMENT_DYNCREATE(CInboxPropPage, CPropertyPage)
CInboxPropPage::CInboxPropPage() : CPropertyPage(CInboxPropPage::IDD)
{
//{{AFX_DATA_INIT(CInboxPropPage)
//}}AFX_DATA_INIT
}
Eilzabeth
|
|
|
|
|
ElizabethC wrote:
but the compiler did not like it
Yeah the buggers have no sense of humour!
First create your string in the .rc file (Call it IDS_MYSTRING "String")
in InboxPropPage.h, change your contructor to be
CInboxPropPage(UINT nCaptionId=0);
in InboxPropPage.cpp, change your contructor to be
CInboxPropPage::CInboxPropPage(UINT nCaptionId) : CPropertyPage(CInboxPropPage::IDD,nCaptionId)
When you create the sheet with its pages, write
CInboxPopPage pagInbox(IDS_MYSTRING);
and you should be in business!
Good luck!
|
|
|
|
|
I added the contructor and tried to compile the code, but getting another error message:
error C2668: 'CInboxPropPage::CInboxPropPage' : ambiguous call to overloaded function
It was complaining on the IMPLEMENT_DYNCREATE line:
IMPLEMENT_DYNCREATE(CInboxPropPage, CPropertyPage)
CInboxPropPage::CInboxPropPage() : CPropertyPage(CInboxPropPage::IDD)
{
//{{AFX_DATA_INIT(CInboxPropPage)
m_message_flag = "0";
//}}AFX_DATA_INIT
}
CInboxPropPage::CInboxPropPage(UINT nIDCaption) : CPropertyPage(CInboxPropPage::IDD, nIDCaption)
{
//{{AFX_DATA_INIT(CInboxPropPage)
//}}AFX_DATA_INIT
}
Eilzabeth
|
|
|
|
|
Do not add the constructor, replace it...
|
|
|
|