|
Seting the hook using :-
SetWindowsHook
removing the hook:-
UnhookWindowsHook
MSDN and codeproject are having nice article on hooking.
Regards,
FarPointer
Blog:FARPOINTER
|
|
|
|
|
|
|
|
can anyone send some simple examples showing the WM_TIMER implementation?
|
|
|
|
|
|
|
Hi,
Try the below sample,
void CMainFrame::OnStartTimer() <br />
{<br />
m_nTimer = SetTimer(1, 2000, 0);<br />
}<br />
<br />
void CMainFrame::OnStopTimer() <br />
{<br />
KillTimer(m_nTimer); <br />
}<br />
<br />
void CMainFrame::OnTimer(UINT nIDEvent) <br />
{<br />
AfxMessageBox("Timer"); <br />
CFrameWnd::OnTimer(nIDEvent);<br />
}
|
|
|
|
|
See example in msdn Here[^]
whitesky
|
|
|
|
|
Thanks for that.
For my application, can I use the following
Is this correct way of doing?
On_send(wparam,lparam)
{
//packet sent to serial device
//timer has to be triggered on here
SetTimer();
}
On_rx(wparam,lparam)
{
//checks for packet received
//if no packet received from serial device, then
{
//check for timer has elapsed
OnTimer()
{
//resend the packet to MPU
post_message(WM_RESEND,null)
}
}
}
On_resend(wparam,lparam)
{
//send same packet to PC
here, I have to restart the timer again to see if the
serial device responded within particular time as in On_rx.
KillTimer();
SetTimer();
}
What more do I need to add?
|
|
|
|
|
timer will call itself, you don't need to call that function!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Created a class i.e. CFlipCustomViewer derived from COleConrol class(abstact class)and
overridden the "virtual void OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)" method of COleControl class in the void CFlipCustomViewer::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid).I tried to call this in OnInitDialog() method of my dialog class of the application.Here the code snippets..
BOOL CFlip::OnInitDialog()
{
//having a CStatic as a place holder and then
//create the flip custom control in InitDialog
COleControl* ptrOleControl; //abstract base class pointer
CFlipCustomViewer* ptrFlipCustomViewer; //derived class pointer
ptrOleControl = ptrFlipCustomViewer; //derived class pointer assigned to abstract base class pointer
ptrOleControl = new CFlipCustomViewer(); //error in this instantiation of derived one
CDC* pdc = GetDC(); //get the device context
CRect rcBounds;
CRect rcInvalid;
GetClientRect( &rcBounds);
GetClientRect( &rcInvalid);
ptrOleControl->OnDraw(pdc,rcBounds,rcInvalid);//place holder for flipping action
CDialog::OnInitDialog();
return TRUE;
}
****************************************************************************************
but while compiling i am getting the following errors as below :
error C2259: 'CFlipCustomViewer' : cannot instantiate abstract class due to following members:
d:\fancyviewer\flipsample\flipcustomviewer.h(14) : see declaration of 'CFlipCustomViewer'
d:\fancyviewer\flipsample\flip.cpp(200) : warning C4259: 'long __thiscall COleControl::GetClassID(struct _GUID *)' : pure virtual function was not defined
d:\program files\microsoft visual studio\vc98\mfc\include\afxctl.h(683) : see declaration of 'GetClassID'
d:\fancyviewer\flipsample\flip.cpp(200) : warning C4259: 'unsigned int __thiscall COleControl::GetUserTypeNameID(void)' : pure virtual function was not defined
d:\program files\microsoft visual studio\vc98\mfc\include\afxctl.h(936) : see declaration of 'GetUserTypeNameID'
d:\fancyviewer\flipsample\flip.cpp(200) : warning C4259: 'unsigned long __thiscall COleControl::GetMiscStatus(void)' : pure virtual function was not defined
d:\program files\microsoft visual studio\vc98\mfc\include\afxctl.h(937) : see declaration of 'GetMiscStatus'
d:\fancyviewer\flipsample\flip.cpp(200) : error C2259: 'CFlipCustomViewer' : cannot instantiate abstract class due to following members:
d:\fancyviewer\flipsample\flipcustomviewer.h(14) : see declaration of 'CFlipCustomViewer'
****************************************************************************************
Can anyone helpme out please ?
|
|
|
|
|
You need to override all the pure virtual functions of an abstract base class, but why not just derive from from CWnd instead?
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Hello everyone!
Look at my code:
int Interface::InitScreen()<br />
{<br />
ifstream mainUIScreen((string(".\\") + string(DIR_SCREENS) + string("mainui.asc")).c_str());<br />
ofstream mainUIScreen_Edit((string(".\\") + string(DIR_SCREENS) + string("mainui_edited.asc")).c_str());<br />
<br />
if (!mainUIScreen.is_open())<br />
{<br />
MessageBox(NULL, "Cannot open program file 'mainui.asc'!", "Error",<br />
MB_OK | MB_ICONEXCLAMATION);<br />
exit(-1);<br />
}<br />
<br />
if (!mainUIScreen.good())<br />
{<br />
MessageBox(NULL, "Cannot open program file 'mainui.asc'!", "Error",<br />
MB_OK | MB_ICONEXCLAMATION);<br />
exit(-1);<br />
}<br />
<br />
char c;<br />
for (int x = 0; x < WIDTH*HEIGHT; x++)<br />
{<br />
c = mainUIScreen.peek();<br />
mainUIScreen_Edit.put(c);<br />
}
When I open the output file (mainui_edited.asc ), I get a bunch of 0x98 's instead of the chars I want... Why is that? Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
To anyone that reads this: I was using an Unicode file...
Windows Calculator told me I will die at 28.
|
|
|
|
|
Hey all,
In my application, I need to turn on the timer once the Pc sends a packet to the serial device. the serial device should respond immediately to teh PC's request. The Pc should get response from the serial device within "m" secs. the Pc will wait for response from serial device and check for the timer. if elapsed, will resend the packet again.
in brief,
On_send(wparam,lparam)
{
//packet sent to serial device
//timer has to be triggered on here
}
On_rx(wparam,lparam)
{
//checks for packet received
//if no packet received from serial device, then
{
//check for timer
while(timer has elapsed)
{
//resend the packet to MPU
post_message(WM_RESEND,null)
}
}
}
On_resend(wparam,lparam)
{
//send same packet to PC
here, I have to restart the timer again to see if the
serial device responded within particular time as in On_rx.
}
this is the idea i have in mind. but i dont know how to implement. Can I use WM_TIMER...? I know there are various timers like multimedai timers, etc., But dont know which one suits my need as I am still in the learning curve of MFC.
I would appreciate if anyone can help me with this.
Thanks in advance.
----
This was my query that I posted yesterday for which I got solutions that WM_TIMER and SetTimer() would be best option.
But doesnt the timer posts the WM_TIMER message to the message queue and we can not be sure when this message will be processed. If that is the case, then how can I use this for my application.?
any help?
|
|
|
|
|
From what you described, Windows (normal) timer will meet your requirement.
thathvamsi wrote: But doesnt the timer posts the WM_TIMER message to the message queue and we can not be sure when this message will be processed.
That is from the high resolution (~10 ms) point of view. I don't foresee any issues in your case.
Best,
Jun
|
|
|
|
|
Is this correct way of doing?
On_send(wparam,lparam)
{
//packet sent to serial device
//timer has to be triggered on here
SetTimer();
}
On_rx(wparam,lparam)
{
//checks for packet received
//if no packet received from serial device, then
{
//check for timer
//while(timer has elapsed)
OnTimer()
{
//resend the packet to MPU
post_message(WM_RESEND,null)
}
}
}
On_resend(wparam,lparam)
{
//send same packet to PC
here, I have to restart the timer again to see if the
serial device responded within particular time as in On_rx.
KillTimer();
SetTimer();
}
Waht more do I need to add?
|
|
|
|
|
try multimedia timer :- http://www.codeproject.com/audio/mult_media_timer.asp
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Iam getting confused by reading the various articles on timers.
Cant I use the code that I had sent in my previous message post.
Which is the best...WM_TIMER or the multimedia timers ...or whichone?
|
|
|
|
|
thathvamsi wrote: Which is the best...WM_TIMER or the multimedia timers ...or whichone?
Which ever you like! which ever you found easy!
anyway Timer Work like this
SetTimer(...)
OnTimer()
{
call function based on time!
}
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Re
|
|
|
|
|
I'm not going to check the details of your code. Rather, I'll treat it as pseudo code.
First, be careful with OnTimer() and On_rx() logic, which could be conflicting. If you use timer, you should check whether your received the feedback inside OnTimer(), not On_rx(). If you must use On_rx(), you can check how much time elapsed since last On_send() call without using timer. OnTimer() and On_rx() complicate things unnecessarily.
Second, the blocks {} you used in the segment are incorrect:
thathvamsi wrote: On_rx(wparam,lparam)
{
//checks for packet received
//if no packet received from serial device, then
{
//check for timer
//while(timer has elapsed)
OnTimer()
{
//resend the packet to MPU
post_message(WM_RESEND,null)
}
}
}
Best,
Jun
|
|
|
|
|
In single thread
LRESULT WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)<br />
{<br />
switch (uMsg)<br />
{<br />
case WM_SHOWWINDOW:<br />
SendMessage(hWnd, WM_ENABLE, FALSE, 0);<br />
break;<br />
}<br />
<br />
.......<br />
}
SPY++ watch message:
WM_SHOWWINDOW...
WM_ENABLE...
WM_ENABLE...(RETURN)
WM_SHOWWINDOW...(RETURN)
message WM_SHOWWINDOW not handled, but the window procedure can handle WM_ENABLE, why?
Thanks.
|
|
|
|
|
From your Spy++ trace, it looks like WM_SHOWWINDOW is sent to your window.
Deus caritas est
|
|
|
|
|
That's correct.
From MSDN:
The SendMessage function sends the specified message to a window or windows. It calls the window procedure for the specified window and does not return until the window procedure has processed the message.
I think you can use PostMessage if you want this scenario:
WM_SHOWWINDOW
WM_SHOWWINWOW (RETURN)
WM_ENABLE
WM_ENABLE (RETURN)
Not sure why it would make a difference, the window will be disabled. You can also use the API function EnableWindow(hWnd, FALSE) to disable the window.
- S
50 cups of coffee and you know it's on!
|
|
|
|