Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catching Return key in edit box 4

Status
Not open for further replies.

MinnisotaFreezing

Programmer
Jun 21, 2001
120
KR
My declares

LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
LRESULT CALLBACK btnProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK EditBoxProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK LstBoxProc (HWND, UINT, WPARAM, LPARAM);
WNDPROC oldBtn, oldEdit, oldList;

Under Create:

hwndEdit = CreateWindow (TEXT("edit"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | ES_LEFT
| ES_MULTILINE , 3, 250, 5, 5, hwnd, (HMENU) 3, ((LPCREATESTRUCT)
lParam)->hInstance, NULL);

oldEdit = (WNDPROC) SetWindowLong (hwndEdit, GWL_WNDPROC, (LONG) EditBoxProc);

And finally the callback itself:

LRESULT CALLBACK EditBoxProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
hdc = GetDC(hwnd);
//TextOut(hdc, 3, 150 + 20, TEXT("Entered editProc"), sizeof(TEXT("Entered editProc")));
switch (message)
{
case WM_KEYDOWN:
if (wParam == VK_RETURN)
{
TextOut(hdc, 3, 150 + 20, TEXT("Enter pushed in EditBoxProc"), sizeof(TEXT("Enter pushed in EditBoxProc")));
}
break;
}
ReleaseDC(hwnd, hdc);
return CallWindowProc(oldEdit, hwnd, message, wParam, lParam);
}


My problem is that this does not catch the enter key being presed. I have two other child windows, and they have procedures that are almost identical to this one, and they trap the Enter key just fine. The example is:

LRESULT CALLBACK LstBoxProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
hdc = GetDC(hwnd);
CString MessageString = "Return Key pushed in LstBoxProc";
if (message == WM_KEYDOWN && wParam == VK_RETURN)
{
TextOut(hdc, 3, 150, TEXT(MessageString), strlen(MessageString));
}
ReleaseDC(hwnd, hdc);
return CallWindowProc(oldList, hwnd, message, wParam, lParam);
}

In the case of the non-working EditBoxProc, I did some testing, and I dont think my program ever even enters EditBoxProc, and I don't know why. Also, can anyone tell me how to change the color of my text in these posts? I would have liked to make my comments red. Like <textcolor>Red</textcolor>

Thank you very much in advance for your help
CJB
 
how about WM_CHAR? John Fill
1c.bmp


ivfmd@mail.md
 
I went and tried using WM_CHAR, and I still get the same result, my callback works for the listbox and the button, but not the edit box. In the code I encluded above, I commented out a TextOut line, which should execute every time any message is sent to the EditBoxProc, but it never executes. For some reason, it seems I never even enter the EditBoxProc. I even tried trapping for other keystrokes, such as tab and space, and still got no responce, but I am able to trap any keystrok in other subclass procs using WM_KEYDOWN and WM_CHAR. Any thoughts?
 
1.SetWindowLong is working?
Or in the oldEdit you have a 0 value. (error)

because acording to MSDN:
&quot;Windows 95/98/Me: The SetWindowLong function may fail if the window specified by the hWnd parameter does not belong to the same process as the calling thread.&quot;
Also I don't understand why you put the cast to (WNDPROC) before SetWindowLong. I never done this before, but I will write it like that:
oldEdit = SetWindowLong (hwndEdit, GWL_WNDPROC, (WNDPROC) EditBoxProc);

2.Have you tried to use RegisterClass in order to register your window procedure?

Hope this helps,s-) s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Oh, sorry, I think you forgot about return. If you don't, the CallWindowProc will execute the lists native wndproc.

if (message == WM_KEYDOWN && wParam == VK_RETURN)
{
TextOut(hdc, 3, 150, TEXT(MessageString), strlen(MessageString));
return 0;
}
John Fill
1c.bmp


ivfmd@mail.md
 
Thank you guys very much for your help.

Burtani, I was getting a sucessfull return from SetWindowLong.

Jon, I need to &quot;return CallWindowProc(oldEdit, hwnd, message, wParam, lParam);&quot; to return control to the default proc.

What was happinging here:
hdc = GetDC(hwnd);
was that the hwnd in this case was a handle to the child window.I set the Edit box for multi line, but didn't include any scroll bars, so it wrote to the edit box, I couldn't see it. Anyway, I substituted:
hdc = GetDC(GetParent(hwnd));
and it worked.

Anyway, I have a related question. If I type

if (message == WM_KEYDOWN && wParam == VK_TAB )
{}

it enters the loop on a tab.

if (message == WM_KEYDOWN && wParam == VK_RETURN)
{}

it enters the loop on a enter stroke.

however, I type:
if (message == WM_KEYDOWN && (wParam == VK_TAB || VK_RETURN))

and it enters the loop on every key stroke, when I expect it to ender only on tab or return. Can you show me where my logical gap is? Also, I get the same results for WM_KEYDOWN and WM_CHAR

Thanks again guys,

CJB
 
For your most recent question:

if (message == WM_KEYDOWN && (wParam == VK_TAB || VK_RETURN))

should be

if (message == WM_KEYDOWN && (wParam == VK_TAB || wParam == VK_RETURN))

otherwise, since VK_RETURN is non-zero, you indeed enter the loop for every key stroke!

Vincent
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top