Jump to content
  • Advertisement
Sign in to follow this  
dathui

problems with EditBox

This topic is 4406 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Lately i've been working on a little wrapper for gui-handling in windows and it all went fine until i tried to implement textboxes. Labels, lists and buttons didn't pose any problems but with editboxes they refuse to enter any chars. Since other types of controls work perfectly i'm kind of clueless. I have dug around a little bit on msdn but nothing i've found has worked. Here's my code, i've tried to cut out parts that shouldn't matter. CEdit.cpp
CEdit::CEdit(std::tstring& text, uint32 x, uint32 y, uint32 height, uint32 width, IWindow* parent, bool pswfield, int styles)
: IWindow(parent)
{
	int usedstyles = WS_CHILD | WS_VISIBLE | ES_LEFT | styles;
	m_hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, _T("EDIT"), _T(""), usedstyles,
		x, y, width, height, m_parent, (HMENU)m_id, GetModuleHandle(NULL), NULL);
	if(m_hwnd == NULL)
		globals::printError(_T("CEdit::CEdit()"), __TFILE__, __LINE__, GetLastError());
	setOnCommand(makeOnCommand(CEdit, *this, &CEdit::defOnCommand));
	parent->addChild(this);
}

--------------------------------------------------------------------------- CWindow.cpp
LRESULT CALLBACK tools::win32::wndProcProxy(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	window_it it = windows.begin();
	while(it != windows.end())
	{
		if(hwnd == (*it)->getHWND())
		{
			LRESULT retr = (*it)->wndProc(hwnd, message, wParam, lParam);
			++it;
			return retr;
		}
		else
			++it;
	}
	return (BOOL)DefWindowProc(hwnd, message, wParam, lParam);
}

int CWindow::handle(MSG& msg) 
{
	//is this window the reciever?
	if(msg.hwnd == m_hwnd)
	{
		if(wndProc(msg.hwnd, msg.message, msg.wParam, msg.lParam) == 0)
			return Window_MessageHandled;
		return Window_MessageNotHandled;
	}

	//it's not this window, check if a childwindow is the reciever
	if(m_children.size() > 0)
	{
		child_it it = m_children.begin();
		while(it != m_children.end())
		{
			if(IsDialogMessage((*it++)->getHWND(), &msg))
				return Window_MessageHandled;
		}
	}
	return Window_MessageNotHandled;
}

LRESULT CALLBACK CWindow::wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch(message)
	{
	case WM_CREATE:
	case WM_SIZE:
	case WM_DROPFILES:
	case WM_KEYDOWN:
		{
			(*m_onKeyDown)(wParam, lParam);
		}
		break;
	case WM_COMMAND:
		{
			child_it it = m_children.begin();
			while(it != m_children.end())
			{
				int32 id = (*it)->getID();
				uint32 p = LOWORD(wParam);
				if((*it)->getID() == LOWORD(wParam))
				{
					(*(*it)->getOnCommand())(wParam, lParam);
					break;
				}
				else
					++it;
			}
		}
		break;
	case WM_DESTROY:
	default:
		return (BOOL)DefWindowProc(m_hwnd, message, wParam, lParam);
	}
	return 0;
}

----------------------------------------------------------------------------- win32main.cpp
int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nFunsterStil)
{
 	MSG msg;
	string cmdline(lpszArgument);
	//calling main
	if(!app->start())
		return -1;

	//messageloop
	while(GetMessage(&msg, NULL, 0, 0) > 0)
	{
		TranslateMessage(&msg);
		bool handled = false;
		WindowCollection::window_it it = WindowCollection::windows.begin();
		while(it != WindowCollection::windows.end())
		{
			if((*it)->handle(msg) == Window_MessageHandled) //for one of our windows
			{
				handled = true;
				break;
			}
			else
				++it;
		}
		if(!handled)
			DispatchMessage(&msg);
	}

	// The program return-value is 0 - The value that PostQuitMessage() gave
    return (int)msg.wParam;
}

----------------------------------------------------------------------------- main.cpp
class App : public Application
{
public:
	bool start()
	{
		window = new CWindow(string("mickes app"));
		if(window->create(100, 100, 350, 350, 0) == 0)
			return false;
	
		edit = new CEdit(string("test"), 250, 50, 25, 50, window);
		return true;
	}
private:
	CWindow* window;
	CEdit* edit;
};

Application* win32::app = new App;

Share this post


Link to post
Share on other sites
Advertisement
if you are forwarding EN_ notification messages from the parent's WM_COMMAND to the edit class, which it does look like you're doing, make sure that if you want the default to happen, you use the right window handle when you call DefWindowProc or return FALSE from a dialog to do the default from your edit class's WM_COMMAND. ie. i think your EN_ notification messages are not being handled correctly.

Share this post


Link to post
Share on other sites
You cannot use the result from the wndProc call as a signal if a message got handled or not:

if(wndProc(msg.hwnd, msg.message, msg.wParam, msg.lParam) == 0)
return Window_MessageHandled;

You'd have to add another parameter if you want to do this.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:

m_hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, _T("EDIT"), _T(""), usedstyles,
x, y, width, height, m_parent, (HMENU)m_id, GetModuleHandle(NULL), NULL);

Pass NULL for argument 3. What your currently have limits the amount of text that can be entered to zero characters. I'm not even sure that a EM_LIMITTEXT can even increase that.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!