int CWindow::create(uint32 x, uint32 y, uint32 height, uint32 width, int resourceID, int styles, IWindow* parent)
{
WNDCLASSEX wincl; /* Data structure for the windowclass */
m_regTitle = m_title;
/* The Window structure */
wincl.hInstance = ThisInstance;;
wincl.lpszClassName = m_title.c_str();
wincl.lpfnWndProc = wndProcProxy; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof(WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH)COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
{
TCHAR* buff = new TCHAR[256];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, buff, 256, 0);
MessageBox(NULL, buff, "Error", MB_OK);
delete[] buff;
return 0;
}
m_hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
m_title.c_str(), /* Classname */
m_title.c_str(), /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
width, /* The programs width */
height, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
ThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
if(m_hwnd == NULL)
{
//stringstream ss;
//ss <<"Error: " <<GetLastError() <<endl;
//MessageBox(NULL, ss.str().c_str(), "Error", MB_OK);
TCHAR* buff = new TCHAR[256];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, buff, 256, 0);
MessageBox(NULL, buff, "Error", MB_OK);
delete[] buff;
return 0;
}
ShowWindow (m_hwnd, TRUE);
WindowCollection::windows.push_back(*this);
return (int)(m_hwnd != NULL);
}
Thanks in advance
problems with CreateWindowEx
i'm trying to put together a little framework for making handling the win32 api easier, but i can't get the CreateWindowEx to work properly.
here's the create function, m_hwnd becomes null and GetLastError returns 183, or "Cannot create a file when that file already exists.", which i simply don't understand.
I've tried changing m_title(set in the ctor) but it doesn't help.
Quote:From Some (Google-cached) Flipcode Thread
I solved it...under the MSG switch, I had the default case return (0). Whoops
Which I assume means that in his message procedure, he returned true instead of the return from DefWindowProc(). You do something like that as well?
nope
edit: fixed it, my proxy function returned 0 so you led me on the right path. thanks alot for the help.
LRESULT CALLBACK CWindow::wndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){ switch(message) { case WM_CREATE: (*m_onCreate)(lParam); break; case WM_SIZE: (*m_onSize)(wParam, lParam); break; case WM_DROPFILES: { vector<string> files; char filename[MAX_PATH]; HDROP hdrop = (HDROP)wParam; int numFiles = DragQueryFile(hdrop, -1, NULL, 0); for(int a = 0; a < numFiles; ++a) { if(DragQueryFile(hdrop, a, filename, MAX_PATH) > 0) { files.push_back(filename); } } (*m_onDragDrop)(files); } break; case WM_KEYDOWN: { (*m_onKeyDown)(wParam, lParam); } break; case WM_COMMAND: { child_it it = m_children.begin(); while(it != m_children.end()) { if((*it)->getID() == LOWORD(lParam)) { (*(*it)->getOnCommand())(wParam, lParam); break; } } } break; case WM_DESTROY: (*m_onDestroy)(); break; default: return (BOOL)DefWindowProc(hwnd, message, wParam, lParam); } return 0;}
edit: fixed it, my proxy function returned 0 so you led me on the right path. thanks alot for the help.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement