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;