|
Hi,
I have a dialog which contains different controls,and I want to send
a WM_KEYDOWN message to the parent dialog when a control receives a WM_KEYDOWN
message.
In the dialog,I overrided the OnKeyDown() method as follow:
void Frm_WKFailureMatrix::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
and in the control,I also overrided the OnKeyDown() method , and inside
that handler I call the ::SendMessage(...) method,as follow:
void WkMfcButton::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
int x = 0;
::SendMessage(GetOwner()->GetSafeHwnd() , WM_KEYDOWN , 0 , 0);
}
My problem is that ::SendMessage() accept the third and fourth parameters
as WPARAM and LPARAM(UINT_PTR and LONG_PTR).
How can I convert nChar,nRepCnt and nFlags to WPARAM and LPARAM so the
parent dialog will receive the correct parameters???
With best regards,
Eli
|
|
|
|
|
|
toxcct wrote: static_cast<>()...
Actually, that won't work correctly. The OP actually needs to pack the three parameters back into the wParam and lParam. The MAKELPARAM and MAKEWPARAM macros will do this. Refer to the WM_KEYDOWN doc to determine where each item goes.
Judy
|
|
|
|
|
|
Why are you doing such a messy thing? This way, you will be writing keydown handlers for each and every control. Do you want your code to look like Sphagetti? What if you add two new controls later? Did I not ask you to override the PreTranslateMessage() ? Did you ever try that?
|
|
|
|
|
Hi brahmma,
I know the way of overriding PreTranslateMessage.
The problem is that I've put a breakpoint inside that function but I never
stop there.
My code is :
virtual BOOL PreTranslateMessage(MSG* pMsg);
and the implementation is :
BOOL Frm_WKFailureMatrix::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
int x = 0;
}
return TRUE;
}
However,if i move the focus into a button(by mouse click),the button receives the WM_KEYDOWN message.
1. Is it because of that automatically when I select a window , the focus
is moving into the first control inside that window?
2. As far as I understand , the parrent windw shall receive the WM_KEYDOWN
message and dispatch it to all of its children , isn't it???
Thanks again,
Eli
|
|
|
|
|
if(pMsg->message == WM_KEYDOWN)
{
if(pMsg->wParam == VK_ESCAPE)
AfxMessageBox(_T("You pressed the Escape Key"));
}
This is just an example. Use the virtual key codes to verify which key was pressed. Check out MSDN for virtual key codes.
|
|
|
|
|
Hello,
I have never worked with C++.
I've a project writtern by another person which creates a OCX output.
Actually it's only a class library. Now I want to change the output type to .DLL instead of .OCX.
Any idea how to do it??
|
|
|
|
|
...in the project properties in all probabilities...
|
|
|
|
|
hi toxcct,
I tried but could not find project property which lets me to change the output type.
Can you pls explain the steps how do I do it?
|
|
|
|
|
what IDE do you use (VC6, VS7, VS71, VS8) ?
|
|
|
|
|
VC 6 IDE....
Regards,
Nilesh
|
|
|
|
|
Got to Settings-->Link-->Output File name . Change its extension to .dll.
Prasad
MS MVP - VC++
|
|
|
|
|
Thank you very much Prasad
|
|
|
|
|
Dear all,
I am programming against an API of an application that simulates robot movements.
Whenever I send a command that makes the robot move, the application starts a new thread for that movement and sends a callback when this thread and the accompanying movement have ended. I have no access/handle to that thread, but only the callback. However, the movement only starts, when the function, in which the movement command was issued, returns to the main runloop. So I cannot wait inside the function for the callback to occur, because then the motion would never been started, I cannot wait (or ::Sleep) "outside", because the runloop would get blocked and would also prevent the motion from beeing started.
The reason for waiting is that I have to check feedback from that particular motion (e.g. whether there is a collision), before I can start a new motion.
Is there any way to work around for what seems to me like an unsolvable dilemma?
Thanks a lot for all your comments
|
|
|
|
|
Assuming that you have an event based application (a windows application with GUI), then you could simply let the callback handler post a message to your event queue. If you can provide a value (context) to the callback handler, you could have one static method in your class that does something like the following:
RobotApi::RegisterCallback(CRobotOverlord::OnRobotCallback, (DWORD)this);<br />
<br />
void CRobotOverlord::OnRobotCallback(DWORD dwContext)<br />
{<br />
ASSERT(dwContext);<br />
CRobotOverlord* my = reinterpret_cast<CRobotOverlord*>(dwContext);<br />
ASSERT(my->m_hTargetWnd);<br />
<br />
::PostMessage(my->hTargetWnd, WM_APP, 0, 0);<br />
}
In your application's message map create a handler for message WM_APP:
BEGIN_MESSAGE_MAP(CDialogMain, CDialog)<br />
...<br />
ON_MESSAGE(WM_APP, OnRobotEvent)<br />
END_MESSAGE_MAP()
Using PostMessage() and a message handler makes sure that you will process the event in the thread context of your application, so even when the callback would be in the thread context of the robot library's worker thread you would (in this example code) process it in your own thread context. Saying this I welcome our robot overlords!
Hope it helps
-- modified at 5:50 Wednesday 2nd May, 2007
|
|
|
|
|
can anyone help me to read a tiff image byte by byte and draw its histogram then equalize it and change it to a desired histogram drowed by mouse?
thnx alot
ndadashi
|
|
|
|
|
Hi,
The following is the example I have (and works):
const char *labels[] = {"Mon", "Tue", "Wed"}
SomeFunctions(labels, 3);
Now I want to initialize the contents of the array at run-time.
I tried the following but an error comes up:
const char *labels= NULL;
*labels = new char[3];
labels[0]=_T("Mon");
labels[1]=_T("Tue");
labels[2]=_T("Wed");
SomeFunctions(labels, 3);
error C2665: SomeFunctions : none of the 3 overloads can convert parameter 1 from type 'const char *'
Can someone please show me how declare the same type of array as the examples? Thanks.
|
|
|
|
|
Joe Smith IX wrote: *labels = new char[3];
This is wrong.
labels = new char *[3];
looks better.
You want to create three char *s, not an array of three chars
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
oops, you are right.
But now that I changed it as you suggested, it added a new error:
<br />
error C2440: '=' : cannot convert from 'char ** ' to 'const char *'
|
|
|
|
|
const char *labels= NULL;*labels = new char[3];labels[0]=_T("Mon");labels[1]=_T("Tue");labels[2]=_T("Wed");SomeFunctions(labels, 3);
Something like
char ** labels = new char *[3];
labels[0] = "test";
label[1] = "Not sure if this is exactly right, you may need to use new and strcpy";
label[2] = "I agree with the other poster, you should use vector if you can";
In fact, a vector is a dynamic array, so if you use char * instead of string, the index of the first char in the first item, would represent the start of a block of memory with three strings in it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Yup, you nailed it exactly. Thanks a lot.
P.S.: Since this is not my class, I cannot change it.
|
|
|
|
|
can you please show us how is declared SomeFunction(), and what you're trying to do exactly...
just a guess: why aren't you using std::vector<> ?
-- modified at 4:39 Wednesday 2nd May, 2007
[edit]
what about overloading SomeFunction() into Somefunction(const std::vector<std::string>&) and use this code instead :
std::vector<std::string> vec;
vec.push_back("mon");
vec.push_back("tue");
vec.push_back("wed");
SomeFunction(vec);
[/edit]
|
|
|
|
|
This function is from a lib. here is the declaration in the header file
(Somefunction=StringArray)
<br />
class StringArray<br />
{<br />
public :<br />
int len;<br />
const char * const *data;<br />
StringArray() : len(0), data(0) {}<br />
StringArray(const char * const *data, int len) : len(len), data(data) {}<br />
const char *operator[](int i) const { return data[i]; }<br />
};
|
|
|
|
|
Joe Smith IX wrote: StringArray(const char * const * data, int len)
oh my god !!! does this really compile, and even if so, is this really necessary, rather that const char* ??
and is this class yours ?
why using C style stuff in a C++ code ? (i mean, char* strings when you obviously use classes, so, could use std::string ...)
|
|
|
|