Resource edit box not show content

Hi forum!
In my program I make a dialogbox with an edit box for text input via the resource editor.
It works fine, but when I attach it to a procedure function with the SetWindowLong to recieve WM_KEYDOWN, it won't update itself. It receives the enter key but it cannot receive any text I type.

Here's the procedure for the edit box:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//Procedure for editbox (New playlist).
LRESULT CALLBACK editproc(HWND hedit, UINT message, WPARAM wparam, LPARAM lparam) {

	switch (message) {
	//If a key is pressed:
	case WM_KEYDOWN:
		//If enter is pressed:
		if(wparam == VK_RETURN) {
			//Recieve handle for the dialogbox and send mouseclick message so it presses the OK button.
			HWND dlg = FindWindow(NULL, L"New Playlist");
			PostMessage(dlg, WM_LBUTTONDOWN, 0, MAKELPARAM(120,50));
		}
		break;

	default:
		return DefWindowProc(hedit, message, wparam, lparam);

	}

}


Here is also an image of my dialog box, so you can see the problem:
http://imageshack.dk//viewimage.php?file=/imagesfree/1UQ83072.jpg

Note: The edit box should be white (I've painted the background of the dialog box black).

Regards,

Simon H.A.
I think you need to write return DefWindowProc(hedit, message, wparam, lparam); instead of break; on line 13, so the the edit box could process the keys.

1
2
3
4
5
6
7
8
case WM_KEYDOWN:
	//If enter is pressed:
	if(wparam == VK_RETURN) {
		//Recieve handle for the dialogbox and send mouseclick message so it presses the OK button.
		HWND dlg = FindWindow(NULL, L"New Playlist");
		PostMessage(dlg, WM_LBUTTONDOWN, 0, MAKELPARAM(120,50));
	}
	else return DefWindowProc(hedit, message, wparam, lparam); // process other keys 
Hmm... that didn't work :S
If he set the windows procedure for the editbox to his own prodedure, he should have kept the
address of the old (original) procedure, and he should call the original window procedure as well so
that the usual stuff will get done.


See here:
http://msdn.microsoft.com/en-us/library/ms633571%28v=vs.85%29.aspx


What I'm trying to say is that because of the subclassing the DefWindowProc for the
editbox is now his procedure - so he is going around in a circle - he should be calling the old
editbox window procedure so that normal editbox operation is maintained.
(So I believe, but I'm going to check)
Last edited on
You were right about that guestgulkan.

I did the following to fix my problem:

In the initialization of the edit box I did the following:
1
2
3
4
5
6
7
8
9
10
	//When the dialog box is created: Attach the edit box procedure to the edit box.
	case WM_INITDIALOG: {
		//Gets edit box handle.
		HWND edit = GetDlgItem(hdlg, 301);
		//Assign standard procedure to 'oldeditproc'
		oldeditproc = (WNDPROC)GetWindowLong(edit, GWL_WNDPROC);
		//Sets the custom procedure to the edit box.
		SetWindowLong(edit, GWL_WNDPROC, (LONG)editproc);

					}

Then I changed my custom procedure to the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//Standard procedure for edit box.
LRESULT (CALLBACK *oldeditproc)(HWND, UINT, WPARAM, LPARAM);
//Procedure for edit box (New playlist).
LRESULT CALLBACK editproc(HWND hedit, UINT message, WPARAM wparam, LPARAM lparam) {

	switch (message) {
	//If a key is pressed:
	case WM_KEYDOWN:
		//If enter is pressed:
		if(wparam == VK_RETURN) {
			//Recieve handle for the dialogbox and send mouseclick message so it presses the OK button.
			HWND dlg = FindWindow(NULL, L"New Playlist");
			PostMessage(dlg, WM_LBUTTONDOWN, 0, MAKELPARAM(120,50));
		}
	}
	//Standard procedure.
	return CallWindowProc(oldeditproc, hedit, message, wparam, lparam);

}


Regards,

Simon H.A.
Last edited on
Topic archived. No new replies allowed.