|
Hello and good day. I have this one big dialog with different objects (buttons, listboxes, picturebox, static text, etc.) in it. All of these have a common process that should be called first when the user left clicks the mouse over the object. I have checked the OnLButtonDown method but it seems that it is not called when the user clicks over a component (for a button, it processes the OnClick
method and doesn't process the OnLButtonDown). Now, the reason I want to do this is because I don't want to add an OnClick for every component I have then place the same codes over again; but instead just check a coordinates table and see if the user clicked over an object. Is this possible with OnLButtonDown or would there be any other functions I can use to achieve what I am trying to do?
Thank you for the time and help.
|
|
|
|
|
Llasus wrote: Now, the reason I want to do this is because I don't want to add an OnClick for every component I have then place the same codes over again;
Actually you have only to call the same piece of code, in each event handler. I think it is not a big overhead. Why do you want to go against Windows event handling mechanism?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
CPallini wrote: Actually you have only to call the same piece of code, in each event handler. I think it is not a big overhead. Why do you want to go against Windows event handling mechanism?
The problem is, there are tons of objects in there, and I think by adding one OnClick for each objects will cause the code to be longer than what it should be. Like adding OnClick for each textbox and there are 20 of them and all of those 20 contains just one call of a function.
|
|
|
|
|
Actually MFC allows to map messages of multiple controls to a single handler, provided their ID s are contiguous, see for instance
[^]
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Thanks! I have only seen this one just now though, I'll stick with PreTranslateMessage for now since its the best solution for my problem for now. Thank you for your help and time!
|
|
|
|
|
Llasus wrote: ...cause the code to be longer than what it should be.
You can't seriously think this is a problem, can you? See here for more.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: You can't seriously think this is a problem, can you?
When you've got firmware programmers as your leaders, yes its a problem
|
|
|
|
|
Llasus wrote: would there be any other functions I can use to achieve what I am trying to do?
overide the PreTranslateMessage function in the dialog class and check for the WM_LBUTTONDOWN message.
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)<br />
{<br />
if( pMsg->message == WM_LBUTTONDOWN )<br />
{<br />
if( pMsg->hwnd != m_hWnd )
{<br />
}<br />
}<br />
return CDialog::PreTranslateMessage( pMsg );<br />
}
|
|
|
|
|
Naveen wrote: overide the PreTranslateMessage function in the dialog class and check for the WM_LBUTTONDOWN message.
Thank you! Just what I was looking for Thank you very much!
|
|
|
|
|
What about WM_MOUSEACTIVATE?
Sincerely,
Spy++
|
|
|
|
|
Within the WM_MOUSEACTIVATE handler, I guess you could call
GetDlgCtrlID(GetFocus()) to get the identity of the control.
|
|
|
|
|
//In DlgProc:
if ((msg == WM_MOUSEACTIVATE) &&
(HIWORD(lParam) == WM_LBUTTONDOWN)) {
POINT pt;
GetCursorPos(&pt);
int ctrlID = GetDlgCtrlID(WindowFromPoint(pt)));
}
|
|
|
|
|
You can write your answers at one message.
|
|
|
|
|
Thanks for the help and sorry for the late reply (different timezone) At what event handler should I place this code? I checked OnMouseActivate but lParam and msg is not there.
|
|
|
|
|
How to check the admin/user previleges in Vista and XP
|
|
|
|
|
|
See IsUserAnAdmin()[^] method.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
I want check if a certain file is present at a certain location.
I am using the FileCreate function for this, but I have a problem in the creation of the filename parameter.
if I use the next line to create the filename everything works fine if the specified file is in the same directory as the source:
sprintf(FileName,"%s.txt",ProdBest[i]); //ProdBest is an array of strings containing the filename.
But I want a clear seperation between my Production files and the programm files, and store the Production files in a seperate directory (C:\ProdIn)
If I use the following line I always end up getting a INVALID_HANDLE_VALUE with GetLastError code = 2 (FILE_NOT_FOUND).
sprintf(FileName,"C:\ProdIn\%s.txt",ProdBest[i]);
So clearly I am making a mistake, but I don't know where or what
Can someone help me out?
|
|
|
|
|
Try using double back slash instead of single like this.
sprintf(FileName,"C:\\ProdIn\\%s.txt",ProdBest[i]);
|
|
|
|
|
|
You can use of FindFirstFile for see file exist or no.
|
|
|
|
|
I want to allow user for open my application only 1 time in one PC.
for avoid resource duplication problem.
How can I do?
|
|
|
|
|
If you are using MFC, take a look at this article[^].
BTW, searching before asking the qestion sometimes brings a lot of usefull results. There are plenty of nice articles on codeproject about a very broad range of subjects.
|
|
|
|
|
thank a lot
but that article doesn't work
|
|
|
|
|
Max++ wrote: but that article doesn't work
Which means ?
|
|
|
|