Certain parameters wont work?

This is a discussion on Certain parameters wont work? within the Windows Programming forums, part of the Platform Specific Boards category; Alright, first post, lets hope this is in the right section. Anyway, I've got a function prototype here I'd like ...

  1. #1
    Registered User
    Join Date
    May 2009
    Posts
    5

    Certain parameters wont work?

    Alright, first post, lets hope this is in the right section. Anyway, I've got a function prototype here I'd like you guys to take a look at and tell me if it's just plain wrong. I'm using this as a quick way to format and create my windows for direct3d testing. Here's the prototype:
    Code:
    HWND windowCreator(LPCWSTR className, LPCWSTR windowTitle, HINSTANCE hInst, WNDPROC WndProc, DWORD style=WS_OVERLAPPEDWINDOW);


    edit: Quick note, I've created with a return type as HWND so I can get the window handle back for later use with direct3d and some windows functions.

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,304
    I see nothing obviously wrong other than the thread belongs in the Windows section.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,753
    You might want to say what the function is supposed to do, and how does it not work.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    5
    Alright, thanks, and noted.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    5
    Was hoping it was something simple enough to just catch, you know? But that's not the norm so I should have expected that. Anyway, the function itself is for me to easily create a window for some d3d testing/experimenting. The errors I'm getting are syntax like errors, but it's asking that I put extra parentheses in the parameter list, which makes no sense to me. One example: Missing ')' before identifier className

    Here's the full code:

    Code:
    	HWND windowCreator(LPCWSTR className, LPCWSTR windowTitle, HINSTANCE hInst, WNDPROC WndProc, DWORD style=WS_OVERLAPPEDWINDOW)
    	{
    		wc.style		= CS_HREDRAW | CS_VREDRAW;
    		wc.lpfnWndProc	= WndProc;
    		wc.cbClsExtra	= 0; 
    		wc.cbWndExtra	= 0; 
    		wc.hInstance	= hInst;
    		wc.hIcon		= ::LoadIcon(0, IDI_APPLICATION);
    		wc.hCursor		= ::LoadCursor(0, IDC_ARROW);
    		wc.hbrBackground= static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH));
    		wc.lpszMenuName	= NULL;
    		wc.lpszClassName= TEXT(className);
    
    		if(!RegisterClass(&wc))
    		{
    			MessageBox(0, TEXT("Failed to register windows class."), TEXT("Windows Error"), 0);
    			return 0;
    		}
    
    
    
    		hWnd = CreateWindow(
    			className,
    			windowTitle,
    			style,
    			CW_USEDEFAULT,
    			CW_USEDEFAULT,
    			windowWidth,
    			windowHeight,
    			0,
    			0,
    			hInst,
    			0);
    
    		if( hWnd == 0 )
    		{
    			MessageBox(0, TEXT("Create Window - Failed"), TEXT("Windows Error"), 0);
    			return 0;
    		}
    		else
    		{
    			return hWnd;
    		}
    	}

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You probably need to give us a COMPLETE, compilable example - there is nothing DIRECTLY wrong in the code you have posted, but there's tons of things that could be wrong AROUND your code - e.g not including the right include files, syntax errors before the function you posted, etc.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Registered User
    Join Date
    May 2009
    Posts
    5
    That's pretty much it, I've got it in a class with the variables you see there declared above as global for ease of use while I'm making it. The full .h file is:

    Code:
    #ifndef windowCreator
    #define windowCreator
    #include <windows.h>
    
    
    class window
    {
    	//Global windows based declarations
    	HWND hWnd;
    	WNDCLASS wc;
    	MSG msg;
    
    	
    	//Global class-needed declarations
    	int windowWidth;
    	int windowHeight;
    	bool bWindowed;
    
    
    	window()
    	{
    		//Class constructor with default values
    		windowWidth = 640;
    		windowHeight = 480;
    		bWindowed = true;
    		hWnd = 0;
    	}
    
    	
    
    	HWND windowCreator(LPCWSTR className, LPCWSTR windowTitle, HINSTANCE hInst, WNDPROC WndProc, DWORD style=WS_OVERLAPPEDWINDOW)
    	{
    		wc.style		= CS_HREDRAW | CS_VREDRAW;
    		wc.lpfnWndProc	= WndProc;
    		wc.cbClsExtra	= 0; 
    		wc.cbWndExtra	= 0; 
    		wc.hInstance	= hInst;
    		wc.hIcon		= ::LoadIcon(0, IDI_APPLICATION);
    		wc.hCursor		= ::LoadCursor(0, IDC_ARROW);
    		wc.hbrBackground= static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH));
    		wc.lpszMenuName	= NULL;
    		wc.lpszClassName= TEXT(className);
    
    		if(!RegisterClass(&wc))
    		{
    			MessageBox(0, TEXT("Failed to register windows class."), TEXT("Windows Error"), 0);
    			return 0;
    		}
    
    
    
    		hWnd = CreateWindow(
    			className,
    			windowTitle,
    			style,
    			CW_USEDEFAULT,
    			CW_USEDEFAULT,
    			windowWidth,
    			windowHeight,
    			0,
    			0,
    			hInst,
    			0);
    
    		if( hWnd == 0 )
    		{
    			MessageBox(0, Text("Create Window - Failed"), TEXT("Windows Error"), 0);
    			return 0;
    		}
    		else
    		{
    			return hWnd;
    		}
    	}
    
    
    };
    #endif

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    If you either name your include guard or windowCreator function to different names, it will get a bit further - you are then using the TEXT macro incorrectly.

    [The first problem is caused by windowCreator function name being removed by the preprocessor - so you get a bunch of function parameters immediately after HWND, which confuses the compiler a tad].

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Code:
    #pragma comment(lib, "user32.lib")
    #pragma comment(lib, "gdi32.lib")
    #include <windows.h>
    #include <tchar.h>
    
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
    
    class window
    {
    	public:
    
    	//Global windows based declarations
    	HWND hWnd;
    	WNDCLASS wc; 
    	MSG msg;
    	//Global class-needed declarations
    	int windowWidth;
    	int windowHeight;
    	bool bWindowed;
    
    	window()
    	{
    		//Class constructor with default values
    		windowWidth = 640;
    		windowHeight = 480;
    		bWindowed = true;
    		hWnd = 0;
    	}
    
    	HWND windowCreator(LPCSTR className, LPCSTR windowTitle, HINSTANCE hInst, WNDPROC WndProc, DWORD style=WS_OVERLAPPEDWINDOW)
    	{
    		memset(&wc, 0, sizeof(WNDCLASS));
    
    		wc.style        = CS_HREDRAW | CS_VREDRAW;
    		wc.lpfnWndProc  = WndProc;
    		wc.cbClsExtra   = 0; 
    		wc.cbWndExtra   = 0; 
    		wc.hInstance    = hInst;
    		wc.hIcon        = ::LoadIcon(0, IDI_APPLICATION);
    		wc.hCursor      = ::LoadCursor(0, IDC_ARROW);
    		wc.hbrBackground= static_cast<HBRUSH>(::GetStockObject(WHITE_BRUSH));
    		wc.lpszMenuName = NULL;
    		wc.lpszClassName= TEXT(className);
    
    		if(!RegisterClass(&wc))
    		{
    			MessageBox(0, TEXT("Failed to register windows class."), TEXT("Windows Error"), 0);
    			return 0;
    		}
    		hWnd = CreateWindow(
    			className,
    			windowTitle,
    			style,
    			CW_USEDEFAULT,
    			CW_USEDEFAULT,
    			windowWidth,
    			windowHeight,
    			0,
    			0,
    			hInst,
    			0);
    
    		if( hWnd == 0 )
    		{
    			MessageBox(0, TEXT("Create Window - Failed"), TEXT("Windows Error"), 0);
    			return 0;
    		}
    		else
    		{
    			return hWnd;
    		}
    	}
    };
    
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
    					LPSTR lpCmdLine,int nCmdShow)
    {
    	MSG Msg;
    	HWND hwnd;
    	TCHAR chClassName[]=TEXT("Testing");
    	window win1;
    
    	hwnd = win1.windowCreator(chClassName, "Mywindow", hInstance, WndProc );
    	if(hwnd==NULL)
    	{
    		MessageBox(0,"Window Creation Failed!","Error",MB_ICONSTOP|MB_OK);
    		return 0;
    	}
    	ShowWindow(hwnd,nCmdShow);
    	UpdateWindow(hwnd);
    	while(GetMessage(&Msg,NULL,0,0))
    	{
    		TranslateMessage(&Msg);
    		DispatchMessage(&Msg);
    	}
    	return Msg.wParam;
    }
    LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
    {
    	switch(msg)
    	{
    		case WM_CLOSE:
    			DestroyWindow(hwnd);
    			break;
    		case WM_DESTROY:
    			PostQuitMessage (0);
    			break;
    		default:
    			return DefWindowProc(hwnd,msg,wParam,lParam);
    	}
    	return 0;
    }

  10. #10
    Registered User
    Join Date
    May 2009
    Posts
    5
    Thanks guys, it was that I had a function with the same name as the #ifndef/#define statements. Appreciate it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  2. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  3. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 03:48 AM
  4. Why won't my OpenGL work?
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 11-26-2005, 10:53 AM
  5. Developers Wanted
    By Quasicom in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 08-24-2005, 12:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21