Skip to main content
gamedev.net
🔒 Locked

Std::Sting question

Started by dejangex Aug 14, 2006 at 3:38 PM 3 replies 850+ views
Original Post
dejangex
dejangex
I have the most basic window screation program
//includes
#include <windows.h>
#include <string>
#include "res/resource.h"
#include "WinMain.h"

//using namespace std;
std::string strAppName = "WindowProject";

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
	// Set up window class
	WNDCLASSEX wndclass;
	wndclass.cbSize = sizeof(WNDCLASSEX);
	wndclass.cbClsExtra = 0;
	wndclass.cbWndExtra = 0;

	wndclass.lpfnWndProc = WndProc;
	wndclass.hInstance = hInstance;
	wndclass.lpszClassName = strAppName.c_str(); //Problematic
	wndclass.lpszMenuName = NULL;

	wndclass.style = CS_HREDRAW | CS_VREDRAW;
	wndclass.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_ICON32);
	wndclass.hIconSm = LoadIcon(hInstance, (LPCTSTR)IDI_ICON16);
	wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
	wndclass.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);

	// Register the window class
	if(0 == RegisterClassEx(&wndclass))
		return 0;

	// Create the window TODO: Enter Class name, titlebar message and starting position
	HWND hWnd;
	hWnd = CreateWindow("ClassNameHere","Application", WS_OVERLAPPEDWINDOW, 100, 100, 640, 480, NULL, NULL, hInstance, NULL);

	// Display the window
	ShowWindow(hWnd, iCmdShow);
	UpdateWindow(hWnd);

	// Process messages until the program is terminated
	MSG msg;
	while(GetMessage (&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	return (msg.wParam);
}
When I run the program it doesnt display its window but I can see it in procesess. When I replace the line I marked problematic with this: wndclass.lpszClassName = "WindowProject"; then it works fine. Im still noob at c++ and I think this is a trivial problem but you can tell me whats happening.
CC
dejangex
dejangex
OMG, sorry for the post I know hte problem now. In
hWnd = CreateWindow("ClassNameHere","Application", WS_OVERLAPPEDWINDOW, 100, 100, 640, 480, NULL, NULL, hInstance, NULL); I forgot to replace the class name it was using:

hWnd = CreateWindow(strAppName.c_str(),"Application", WS_OVERLAPPEDWINDOW, 100, 100, 640, 480, NULL, NULL, hInstance, NULL);
Do delete this post if necessary.
CC
brainsocket
brainsocket
Quote:
Original post by Deyja
std::sting should only be used with the std::bee class anyway.


ZING!

Topic Locked

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

Sign in to reply to this topic.