|
|
You are welcome!
|
|
|
|
|
i define a hot key in my app with RegisterHotKey.
ATOM identiferForTest=GlobalAddAtom(_T("test"));
if (!RegisterHotKey(this->m_hWnd,identiferForTest,0,'T'))
{
AfxMessageBox(_T("hot key conflict!"));
}
and in the event handler~showing a MessageBox respond to the hot key(press 'T' keyboard key)
later at somewhere i call UnRegisterHotKey!
then later i call RegisterHotKey again as mentioned above
now when i press other key~~ a debug assertion failure Window pop up!
what's going on?
can anybody give me some advice?
|
|
|
|
|
What does the ASSERT say? You get a lot of information by examining it. (Press Retry in the assertion dialog.)
|
|
|
|
|
ASSERT say:
Debug Assertion Failure
XXXXXXXXXXXXXX
XXXXXXXXXXXXXX
for more information on how your program can cause an assertion
XXXXXXXXX
(Press Retry to debug he program)
then i press Retry
and VS locate:
_AFXCOLL_INLINE void*& CPtrList::GetNext(POSITION& rPosition)
{ CNode* pNode = (CNode*) rPosition;
ASSERT(AfxIsValidAddress(pNode, sizeof(CNode)));
if( pNode == NULL )
AfxThrowInvalidArgException();
rPosition = (POSITION) pNode->pNext;
return pNode->data; }
|
|
|
|
|
It basically says that the argument rPosition is not part of your container. It might have been at one stage, but has been deleted and is no longer valid.
Examine the call stack and see where it's coming from. That might give you a hint what the problem is.
|
|
|
|
|
seems that i know where problem come from!!
my dialog have no input box! but when i invoke hot key~
it will open a child ActiveX control window which have input box
then i input something
when i invoke hot key again
the Child ActiveX control window will be hidden
and go back to my dialog have no input box
when i press character key! the debug assertion failure window pop up
i think at that moment program still think he have input focus in the child ActiveX control window
but the window has been hidden!!
if so~~~ how can i solve this problem?????????
|
|
|
|
|
When you register the hot key, can't you just verify that the window handle is a valid one and that it is visible before registration? Use ::IsWindow(hwnd) and ::IsWindowVisible(hwnd)
|
|
|
|
|
I can't tell what goes wrong without seeing more of the relevant code, such as the call to UnRegisterHotKey and the next call to RegisterHotKey.
Are you using the same identifierForTest value?
Are you calling RegisterHotKey more than once without unregistering?
Do read the relevant MSDN pages, they contain useful remarks sections.
|
|
|
|
|
LRESULT CtestSDRDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if(message==WM_HOTKEY)
{
if (wParam==identiferForHelp)
{
if(m_bShow)
{
UnregisterHotKey(this->m_hWnd,identiferForTest);
theApp.m_bShorcutAllow=false;
}
else
{
RegisterHotKey(this->m_hWnd,identiferForTest,0,'T');
theApp.m_bShorcutAllow=true;
}
m_bShow=!m_bShow;
}
else if(wParam==identiferForTest)
{
AfxMessageBox(_T("hotkey 'T' invoked"));
}
}
return CDialog::WindowProc(message, wParam, lParam);
}
|
|
|
|
|
|
Hi!
I've to assign a multivalued string to a variable. If I use the following code only the last part is assigned to the variable. ie If I assign "Sri Lanka", only "Lanka" get assigned to the variable. This is the code:
array<stringc> ctyLst = SQLdb.Query("Select DISTINCT Team from Test ORDER BY Team DESC");
array<stringc> playerLst;
char query[512];
for(int i = 0; i<ctyLst.size(); i++)
{
ctyLst[i].trim();
printf("%s \n",ctyLst[i].c_str());
sprintf_s(query,512,"Select Name From Test WHERE Team=(%s) ORDER BY RANDOM() LIMIT 11",ctyLst[i].c_str());
playerLst = SQLdb.Query(query);
}
What to do to assign the full string to the variable Team?
|
|
|
|
|
What is stringc declared as? I would guess that its trim() function is a bit dodgy.
|
|
|
|
|
why do you put string literals in quotes in this message, and not in your SQL query?
what is the purpose of the parentheses in the WHERE clause???
|
|
|
|
|
I created a project with VS2008, dialog-based MFC.
What I want to do with that project is Sending 'User-defined-Message' in APP Class.
So I registered my own message in app class(xxxApp.h) like this:
#define USER_MESSAGE_2 (WM_USER+ 102)
And, in message map, I added ON_MESSAGE code in app class(xxxApp.cpp) like below:
BEGIN_MESSAGE_MAP(CwmUserApp, CWinAppEx)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
ON_MESSAGE( USER_MESSAGE_2, OnMyMessage1HandlerApp )
...
END_MESSAGE_MAP()
Also I wrote message handler like this:
LRESULT CwmUserApp::OnMyMessage1HandlerApp(WPARAM wParam, LPARAM lParam)
{
AfxMessageBox(_T("Is it working?"));
return 0;
}
I compiiled. Then one error came up:
error C2440: 'static_cast': 'LRESULT (__thiscall CwmUserApp::* )(WPARAM,LPARAM)'에서 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'(으)로 변환할 수 없습니다.
Sorry, it's korean. If I translate, it says
Can not convert from 'LRESULT (__thiscall CwmUserApp::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
I am not that good with programming, but as much as I understand,
Does that say I simply cannot use 'User-defined-Message' in APP class?
'User-defined-Message' in dlg class or view class works fine with me though.
Thanks in advance
chan
|
|
|
|
|
ON_MESSAGE
check the definition of ON_MESSAGE macro in afxmsg_.h
See: The type of the function must be afx_msg LRESULT (CWnd::*)(WPARAM, LPARAM).
|
|
|
|
|
The type of the function must be afx_msg LRESULT (CWnd::*)(WPARAM, LPARAM).
Which means, Some kind of type casting is needed?
I don't follow the details how to fix this problem;
Would you be more specific?
Thanks in advance
Chan
|
|
|
|
|
specifically, you have to write your ON_MESSAGE handler function in a CWnd derived class. If you have a window class CMyWnd which is derived from CWnd, then message map entry will be
ON_MESSAGE( USER_MESSAGE_2, &CMyWnd::OnMyMessage1HandlerApp )
Declare and define OnMyMessage1HandlerApp function in CMyWnd class.
|
|
|
|
|
Are you sure CWinApp derived classes can recieve arbitrary windows messages in MFC? I could be wrong but I thought they could only handle commands.
Cheers,
Ash
|
|
|
|
|
No. CWinApp derived class is never meant to handle windows messages. I forgot to mention him to move the ON_MESSAGE( USER_MESSAGE_2, &CMyWnd::OnMyMessage1HandlerApp ) entry to CMyWnd class's message map. Thanks..
He might have already done it, since he wouldn't find a way to SendMessage to a CWinApp derived class
Cheers..
|
|
|
|
|
Dear Cool_Dev
Thank you for your help
I've solved this problem.
Here are what I've done;
First of all,
It is not nessesary to move the ON_MESSAGE( USER_MESSAGE_2, &CMyWnd::OnMyMessage1HandlerApp ) entry to CMyWnd class's message map.
Even though CWinApp derived class is never meant to handle windows messages,
We still can hanlde windows messages in CWinApp derived class.
How?
This is how to get it done. It was simple.
Cast the Handler in App class's message map with CWnd::*
It should be like this;
ON_MESSAGE( USER_MESSAGE_2, (afx_msg LRESULT(AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM))OnMyMessage1HandlerApp )
Cast the Handler with (afx_msg LRESULT(AFX_MSG_CALL CWnd::*)(WPARAM, LPARAM))
Then, problem solved.
But I haven't proved the safety of this casting during the application run-time.
Well, I compiled and run the application. It seems fine. Nothing odd happened so far with this type casting.
Thanks.
Chan from SEOUL
modified on Wednesday, August 11, 2010 3:50 AM
|
|
|
|
|
Yes.. you are right. The above scenario works well with theApp.PostThreadMessage(USER_MESSAGE_2, 0, 0);
But when you want to send USER_MESSAGE_2 message to a window, you should move the entry to curresponding window's message map.
|
|
|
|
|
let me write you my coding for user defined msgs maybe this will give you something:
#define WM_USER_THREAD_COMPLETED WM_USER + 2
#define WM_USER_THREAD_ENDED WM_USER + 3 in stdafx.h
ON_MESSAGE( WM_USER_THREAD_COMPLETED, OnThreadCompleted )
ON_MESSAGE( WM_USER_THREAD_ENDED, OnThreadEnded ) on the messagemap
and my handles are like this:
LRESULT CStartStopDlg::OnThreadCompleted( WPARAM wParam, LPARAM lParam)
{
...
return 1;
}
LRESULT CStartStopDlg::OnThreadEnded( WPARAM wParam, LPARAM )
{
...
return 1;
}
to call these,
i use
::PostMessage( m_hWnd, WM_USER_THREAD_COMPLETED, (WPARAM)ps, (LPARAM)ns );
::PostMessage(m_hWnd,WM_USER_THREAD_ENDED,(WPARAM)ps,0); where m_hWnd is my main dialog window
|
|
|
|
|
I encapsulate an ActiveX control(Microsoft web browser) in DLL!
which offer to a game program~ in the game program there's maybe some hotkey for example: press 'M' will open a map.etc! but my DLL will display some page which allow user to input some text!
the problem occur~ if user input 'm' in the textbox. the operation will activate the hotkey 'M' to open a map!! how can i solve the problem~ or i don't need to solve it~~but let the game programmer do that????
|
|
|
|
|
I think, its the game programmer who can do some thing in his WM_HOTKEY message handler to check whether the edit field in webpage of web browser is active and being changed. Then he can show the map accordingly.
The webpage can have java script functions to return the state of edit fields in Form. This article shows the javaScript calls from C++. http://www.codeguru.com/cpp/i-n/ieprogram/article.php/c4399
|
|
|
|