|
Hi,
I want to process data from an edit control by pressing "enter" but I don't know how I I can "tell" the programm that the enter button has been pushed. Can anybody help me with this? Maybe there is an easy way to do this, I tried the WM_CHAR or WM_KEYDOWN without success. Maybe someone can give me a link to the propper tutorial or wirte a few lines.
Thanks in advance
|
|
|
|
|
read down a bit further, there's an answer for you ... using PreTranslateMessage.
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
PreTranslateMessage is a big hammer that gets recommended probably too often. It's also not too easy to write - it tends to end up as spaghetti code.
When you have a dialog box, you first ask the dialog box if it wants to handle messages, by calling ::IsDialogMessage() for a modeless dialog. This is done automatically by the modal message loop for a modal dialog. MFC 'modal' dialogs are in fact modeless Win32 dialogs - you can see this in CDialog::DoModal(). CDialog::PreTranslateMessage() calls ::IsDialogMessage() for you.
When you press certain keys (TAB, Enter, Escape) ::IsDialogMessage() performs the operation you requested and returns FALSE so that the message isn't dispatched by TranslateMessage()/DispatchMessage().
In order to allow the controls to override this behaviour, ::IsDialogMessage() sends a WM_GETDLGCODE message to the control with the focus. You can handle this message in a subclass window procedure in order to catch the return key - from memory, you should call the original window procedure, OR in the DLGC_WANTMESSAGE flag and handle the message directly in the WM_GETDLGCODE handler.
This has two advantages: this behaviour works in a standard Win32 app (no MFC) without having to add a lot of extra plumbing, and for MFC apps, you can create a class derived from CEdit that has this behaviour and reuse that class elsewhere.
The built-in MFC OnGetDlgCode() handler isn't very helpful for DLGC_WANTMESSAGE, because it doesn't allow access to lParam (which points to the MSG structure). To handle this properly, don't use the ON_WM_GETDLGCODE() message map entry - use ON_MESSAGE, as defined in MFC Technical Note 6 (look for TN006 in the MSDN Library index).
--
Mike Dimmick
|
|
|
|
|
In the Message Map of your window/dialog you have to add:
ON_NOTIFY(EN_MSGFILTER, IDC_YOUR_EDIT_ID, OnEnMsgfilterCompose)
The OnEnMsgfilterCompose looks like this:
OnEnMsgfilterCompose(NMHDR *pNMHDR, LRESULT *pResult)
In it do this:
MSGFILTER *pMsgFilter = reinterpret_cast<msgfilter *="">(pNMHDR);
if (pMsgFilter->wParam == VK_RETURN) { // this is the "enter"
}
-----
We are what we repeatedly do. Excellence, then, is not an act, but a habit.
|
|
|
|
|
I created a CDHtmlDialog based dialog and I wanna get content of a Text Field html element so I wrote this code.
<br />
HRESULT CMyHtmlDlg::OnTest(IHTMLElement* pElement)<br />
{<br />
IHTMLElement* pTextElement = NULL;<br />
if (GetElement(_T("Text1"), &pTextElement) == S_OK && pTextElement != NULL)<br />
{<br />
pTextElement->put_innerText(_bstr_t("majid"));<br />
CString str;<br />
BSTR bstrText;<br />
pTextElement->get_innerText(&bstrText);<br />
str = bstrText;<br />
}<br />
return S_OK;<br />
}<br />
the put_innerText function works properly but
get_innerText function doesn't get content of TextField and bstrText set to <bad Ptr>.
so how could I solve this problem?
Thank u in advance
|
|
|
|
|
See if changing BSTR bstrText to CComBSTR bstrText helps.
|
|
|
|
|
I don't have an intimate knowledge of the finer points of macro expansion, but these look suspicious to me, and I am wondering if they will cause problems:
#define ABC 120<br />
#define HALF_ABC ABC / 2<br />
#define QUART_ABC ABC / 4 // this is one-quarter
The first one is normally what I expect to see as a simple substitution. The second one is an operation. The third is an operation with a trailing comment. Will these be expanded properly if used as follows:
for (int i = 0; i < QUART_ABC; ++i)<br />
{<br />
if (i >= HALF_ABC)<br />
}
Besides converting all of these to const ints, what is a
better way to make sure they do what is intended? The software appears to be working properly, but those last pesky hard-to-find bugs may be in these areas.
Dave
"You can say that again." -- Dept. of Redundancy Dept.
|
|
|
|
|
Based on the fact that the preprocessor replaces the #define constants with what you have defined them as right inline, you should always surround compound #define values with parenthesis. EX:
#define ABC 120
#define HALF_ABC (ABC / 2)
#define QUART_ABC (ABC / 4)
This way, they will be evaluated the way that you intended, rather than the way that the expanded expression evaluation order dictates. EX:
for (int i = 0; i < QUART_ABC; ++i)
{
if (i >= HALF_ABC)
// ... processing
}
with your code as is really gets preprocessed into the following:
for (int i = 0; i < 120 / 4; ++i)
{
if (i >= 120 / 2)
// ... processing
}
when it properly should be:
for (int i = 0; i < (120 / 4); ++i)
{
if (i >= (120 / 2))
// ... processing
}
|
|
|
|
|
Thanks. I guess I don't see much difference between
for (i=0; i < 120/4; ++i)
and
for (i=0; i < (120/4); ++i)
But, in an earlier thread below, I do see problems for
#define ABC 120
#define ABC_LESS ABC - 50
i = 100 - ABC_LESS;
simply because of the order of evaluation with addition and subtraction, where we would get
i = 100 - 120 - 50
rather than
i = 100 - (120 - 50)
"You can say that again." -- Dept. of Redundancy Dept.
|
|
|
|
|
As a rule, I put parens around everything that I #define. Even strings.
#define FRED ("fred")
#define X (2)
If you get bitten by that bug once, you never want to chase that bug again.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
Santa Cruz Networks
|
|
|
|
|
#define ABC 120
This is fine.
#define HALF_ABC ABC / 2
This will work most of the time, but could come back to bite you. You almost certainly want:
#define HALF_ABC (ABC / 2)
#define QUART_ABC ABC / 4 // this is one-quarter
You have the same problem as before, and could use brackets. The comment is dealt with by the preprocessor, and earlier than macro expansion in my experience, so its as if you hadn't typed it.
Iain.
|
|
|
|
|
Hi all,
I have a small GDI question.
I have created a bunch of child windows that can be moved around. I want to find out when the windows intersect. Is there a simple API that can tell me that or do I have to calculate the window rect and check if it intersects with other windows.
Thanks
Pankaj
Without struggle, there is no progress
|
|
|
|
|
CRect oR1, oR2, oIntersect;
pWnd1->GetClientRect(&oR1);
pWnd2->GetClientRect(&oR2);
if (oIntersect.IntersectRect(&oR1,&oR2))
{
// they intersect and the overlap
// area is defined in oIntersect
}
|
|
|
|
|
Hi,
How can I do a shift+Tab in PreTranslateMessage()?
In an earlier post, I get an answer to do the Tab:
pMsg->wParam = VK_TAB;
Now I want to force a shift+Tab.
Thanks,
Claude
|
|
|
|
|
With difficulty. The Shift and Tab key presses are sent in different messages. The only way I can think of is to prevent the default processing for this message, and post the following messages:
WM_KEYDOWN for the shift key
WM_KEYDOWN for the tab key
WM_KEYUP for the tab key
WM_KEYUP for the shift key
You may be able to get away without the WM_KEYUP messages, but it's good to be safe just in case.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
One solution is ::GetKeyState(VK_SHIFT).
Kuphryn
|
|
|
|
|
Hi everybody!
Could anyone tell me how to create a moving text in Win32?
|
|
|
|
|
There is no magic way of creating moving text in Win32...
You have a few choices, depending on what you want to do.
The simplest is to create a timer (::SetTimer, ::KillTimer) and
in the WM_TIMER handler change some XY coordinates according to
some rule. Then redraw your text in the newly changed position.
If you can be more specific about what you want to do, then
we can be more specific in our replies.
Iain.
|
|
|
|
|
hi,
I'm c beginner.
I have a small problem. How can I make buttons which are dynamically created and erased with the same ResourceID.
Programmed as below:
CtlNewControl ((void **)&frmP, 1323, checkboxCtl, "Hello" , 1, 1, 15, 11, 1, 1, true);
But unfortunately it's doesn't work Maby you could help me with tis stuff .
There is no error's, but there are no buttons either nothing happens.
Thanks
|
|
|
|
|
You should try any other sites concerning CodeWarrior, Apple Dev. and Apple programming.
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
Soory, but Codewarrior used c++, so people transferred me here. Would be nice if someone helps.
Thanks.
|
|
|
|
|
but this is not generic C++ (which we could help).
It does not look like PowerPlant GUI programming (codewarrior UI framework).
What is it ? can you tell us more ?
I googled for it, and it sounds like PalmOS programming; maybe look for more info on the palmos site ( http://www.palmos.com/dev/support/forums/ [^] )
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
Hi Everyone
How do you increase the font size of the text in CTreeCtrl?
thanks
|
|
|
|
|
You need to set a new font for the control. Normally I would do it something like this (assuming your control is part of a dialog)
OnInitDialog()
{
LOGFONT lf;
m_TreeCtrl.GetFont()->GetLogFOnt(&lf):
lf.lfHeight += 2;
m_Font.CreateFontIndirect(&lf);
m_TreeCtrl.SetFont(&m_Font);
}
m_Font needs to be part of your dialog class as it needs to live at least as long as the tree control using it. After setting the font, the tree control should work quite happily with it.
Roger Allen
Sonork 100.10016
Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
|
|
|
|
|