Skip to main content
GameDev.net gamedev.net
🔒 Locked

Win32 Problems

Started by anonuser Feb 23, 2005 at 5:15 PM 5 replies 700+ views
Original Post
anonuser
anonuser
Windows is giving me an odd errors

WNDCLASSEX wc;
	char* className = "LMS CONSOLE CLASS";
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hIcon = LoadIcon(NULL, IDI_EXCLAMATION);
	wc.hIconSm = LoadIcon(NULL, IDI_EXCLAMATION);
	wc.hInstance = hInstance;
	wc.lpfnWndProc = (WNDPROC)lmsConsoledefDlgproc;
	wc.lpszClassName = className;
	wc.lpszMenuName = NULL;
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.cbSize = sizeof(WNDCLASSEX);
	
	if(!RegisterClassEx(&wc)) {
			DWORD errorNumber = GetLastError();
	LPVOID buffer;
	FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, errorNumber, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (char*)&buffer, NULL, NULL);
	MessageBox(NULL, (char*)buffer, "Error!", MB_OK);
	}
	
	HWND window = CreateWindow(className, "LMS Client 2", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
if(window == NULL) {
	DWORD errorNumber = GetLastError();
	LPVOID buffer;
	FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, errorNumber, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (char*)&buffer, NULL, NULL);
	MessageBox(NULL, (char*)buffer, "Error!", MB_OK);
}

and when run i receive "The System Cannot Find The Specified File" error! Makes no sense to me. Anyone see anything wrong with the code?
anonuser
anonuser
After some more investigating it will always give me that error through out the program o.O

but still doesn't explain why my window doesn't show.


I have no idea what is wrong with that class declaration. But if i put in a different class name it spawns the window. go figure -_- since this code is copy and pasted.
Anon Mike
Anon Mike
GetLastError is fairly meaningless for window and GDI functions despite what MSDN might claim about the subject.

You didn't say which call was failing (the RegisterClassEx or the CreateWindow). However the last several times somebody had this problem it was because they had a bug in thier window procedure. Fire up your debugger, put a breakpoint on the window procedure, and the handling of each message that comes through.
-Mike
anonuser
anonuser
*EDIT*

[Edited by - anonuser on February 23, 2005 10:59:54 PM]
anonuser
anonuser
On Second Thought Its Not Working Correctly At All -_-


i decided to rework it and it still doesn't work.
It says my register class is fine, but CreateWindow is returning null. and the only error i get is System Cannot Find Specified File! This is getting old and quickly.

This is based on Glowdots Win32 tutorials.
#include "lmsConsole.h"void MessageError2(void) {	DWORD errorNumber = GetLastError();	LPVOID buffer;	FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, errorNumber, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (char*)&buffer, NULL, NULL);	MessageBox(NULL, (char*)buffer, "Error!", MB_OK);}lmsConsole::lmsConsole(HINSTANCE hInstance, WNDPROC wndProc) {		WNDCLASSEX wc;	wc.cbClsExtra = 0;	wc.cbSize = sizeof(WNDCLASSEX);	wc.cbWndExtra = 0;	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);	wc.hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));	wc.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_EXCLAMATION));	wc.hIconSm = LoadIcon(NULL, MAKEINTRESOURCE(IDI_EXCLAMATION));	wc.hInstance = hInstance;	wc.lpfnWndProc = (stWndProc);	wc.lpszClassName = "LMSCONSOLEWINDOWCLASS";	wc.lpszMenuName = NULL;	wc.style = CS_HREDRAW | CS_VREDRAW;			if(!RegisterClassEx(&wc)) {		MessageError2();	}	}void lmsConsole::create(HINSTANCE hInstance, HWND parentWindow) {	HWND window = CreateWindowEx(WS_EX_CLIENTEDGE,"LMSCONSOLEWINDOWCLASS", "windowstuff", WS_OVERLAPPEDWINDOW, 					CW_USEDEFAULT, CW_USEDEFAULT, 500, 800, NULL, NULL, hInstance, (void*)this);						if(window != NULL) {			this->mainWindow = window;	}		}void lmsConsole::show() {	ShowWindow(this->mainWindow, SW_SHOWNORMAL);}lmsConsole::~lmsConsole() {}HWND lmsConsole::getWindowHandle(void) {	return this->mainWindow;}void lmsConsole::setCallback(LMSCALLBACK callBack, void* param) {}void lmsConsole::printLine(char* buffer) {}LRESULT CALLBACK lmsConsole::stWndProc(HWND hWND, UINT msg, WPARAM wPARAM, LPARAM lParam) {	lmsConsole* sysConsole;		if(msg == WM_NCCREATE) {		SetWindowLong(hWND,	GWL_USERDATA, (long)((LPCREATESTRUCT(lParam))->lpCreateParams));	}		sysConsole = (lmsConsole*)GetWindowLong(hWND, GWL_USERDATA);	if(sysConsole == NULL) {		return DefWindowProc(hWND, msg, wPARAM, lParam);	}	else {		return sysConsole->WndProc(hWND, msg, wPARAM, lParam);	}		}LRESULT CALLBACK lmsConsole::WndProc(HWND hWND, UINT msg, WPARAM wPARAM, LPARAM lParam) {	switch(msg) {		case WM_DESTROY:			PostQuitMessage(WM_QUIT);			break;		default:			DefWindowProc(hWND, msg, wPARAM, lParam);	}	return 0;}void lmsConsole::setCallbackParam(void* param) {


that's the entire class. not much to break at all.
Anon Mike
Anon Mike
lmsConsole::WndProc needs to be doing "return DefWindowProc()". The code you posted is returned 0 for WM_NCCREATE which causes the whole window creation sequence to abort.
-Mike
anonuser
anonuser
thanks.

i feel dumb now.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.