Creating a New Window

This is a discussion on Creating a New Window within the Windows Programming forums, part of the Platform Specific Boards category; Okay here is my code: Code: int CreateExpenseWnd() { char error[701]; // register expense module class if( RegWndClassEx(sizeof(WNDCLASSEX), 0, ExpWndProc, ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    132

    Creating a New Window

    Okay here is my code:

    Code:
    int CreateExpenseWnd()
    {
    	char error[701];
    
    	// register expense module class
    	if( RegWndClassEx(sizeof(WNDCLASSEX), 0, ExpWndProc, 0, 0, g_hInst, LoadIcon(NULL, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW), (HBRUSH)(COLOR_WINDOW+1), NULL, g_szExp, LoadIcon(NULL, IDI_APPLICATION)) != 0 )\
    	{
    		sprintf(error, "Could not initialize Expense module. (Error Code: 0050; %u)", GetLastError());
    		MessageBox(NULL, error, "Error", MB_ICONEXCLAMATION);
    		return(-1);
    	}
    
    	// create Expense window
    	if( (hExp = CreateWindow(g_szExp, "Expenses", WS_BORDER | WS_VISIBLE, 50, 50, 600, 400, NULL, NULL, g_hInst, NULL)) == NULL )
    	{
    		sprintf(error, "Could not initialize Expense module. (Error Code: 0051; %u)", GetLastError());
    		MessageBox(NULL, error, "Error", MB_ICONEXCLAMATION);
    		return(-1);
    	}
    
    	return(0);
    }
    
    LRESULT CALLBACK ExpWndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    	char error[701];
    	LVCOLUMN LVColumn;
    	LVITEM LVItem;
    
    	switch(Message)
    	{
    		case WM_CREATE:
    			// create the different controls
    			hLV_Wnd = CreateWindow("SysListView32", NULL, WS_CHILD | WS_VISIBLE | LVS_REPORT | WS_BORDER | WS_VSCROLL | WS_EX_RIGHTSCROLLBAR | WS_TABSTOP, 100, 100, 500, 400, hParent, (HMENU)iLVID, g_hInst, NULL);
    			if( hLV_Wnd == NULL )
    			{
    				sprintf(error, "Could not initialize Expense module. (Error Code: 0052; %u)", GetLastError());
    				MessageBox(NULL, error, "Error", MB_ICONEXCLAMATION);
    				return(-1);
    			}
    
    			LVColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT;
    			LVColumn.fmt = LVCFMT_LEFT;
    			LVColumn.cx = (int)(500 * 0.17);
    			LVColumn.pszText = "Date";
    			LVColumn.cchTextMax = 4;
    			LVColumn.iSubItem = 1;
    			LVColumn.iImage = 0;
    			LVColumn.iOrder = 0;
    			ListView_InsertColumn(hLV_Wnd, 1, &LVColumn);
    
    			LVColumn.cx = (int)(500 * 0.50);
    			LVColumn.pszText = "Description";
    			LVColumn.cchTextMax = 11;
    			LVColumn.iSubItem = 2;
    			ListView_InsertColumn(hLV_Wnd, 2, &LVColumn);
    
    			LVColumn.cx = (int)(500 * 0.17);
    			LVColumn.pszText = "Amount";
    			LVColumn.cchTextMax = 6;
    			LVColumn.iSubItem = 3;
    			ListView_InsertColumn(hLV_Wnd, 3, &LVColumn);
    
    			LVColumn.cx = (int)(500 * 0.17);
    			LVColumn.pszText = "Paid";
    			LVColumn.cchTextMax = 4;
    			LVColumn.iSubItem = 4;
    			ListView_InsertColumn(hLV_Wnd, 4, &LVColumn);
    			break;
    
    		case WM_CLOSE:
    			DestroyWindow(hwnd);
    			break;
    
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			break;
    
    		default:
    			return(DefWindowProc(hwnd, Message, wParam, lParam));
    	}
    
    	return(DefWindowProc(hwnd, Message, wParam, lParam));
    }
    When I run the program, I get an error message (the error code 0050 with GetLastError() returning 87 -- this error message is "The parameter is incorrect." when looked up). I don't understand what is wrong with it. If you can tell me, then please let me know!

    Thanks,
    Tyouk

  2. #2
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    RegWndClassEx - ??

    Is this a custom function? Or is it some MFC thing I don't know about.

    Additionally all three spots where your program cites an error displays the exact same message. Why don't you change it up so you know which line is failing?

    [edit]

    Seriously though, RegWndClassEx. Someone enlighten me here.

    [/edit]
    Last edited by andyhunter; 01-02-2005 at 04:17 PM.
    i don't think most standard compilers support programmers with more than 4 red boxes - Misplaced

    It is my sacred duity to stand in the path of the flood of ignorance and blatant stupidity... - quzah

    Such pointless tricks ceased to be interesting or useful when we came down from the trees and started using higher level languages. - Salem

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    132
    RegWndClassEx is a custom function. And the error messages do not all say the same thing. Each line with an error code is one number off (at least) followed by a number produced by GetLastError() and so you would never get the exact same message as long as it's not the same bit of code thats failing. The line thats failing is the error code 0050 (those others on this section of code is 0051 and 0052... not the same lines). The entire message I get (error message that is) is as follows:

    "Could not initialize Expense module. (Error Code: 0050; 87)"

    87 is the error code being left by GetLastError() and when I use the Error Lookup Tool in MSVC, I get the message "The parameter is incorrect." Although I wish I knew which parameter was incorrect. Any ideas?

    This btw is a second window trying to be created. My main window is created in the WinMain where as this window is being created when a user clicks a button on the main windows. Could this be the reason why I am getting this error?

    Thanks,
    Tyouk

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    132
    Okay never mind. Me just being stupid...

    g_szExp was initialized as: char g_szExp = "Expense Module";

    anyone see my error? lol

    Thanks though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Creating a child window in a parent window
    By vopo in forum Windows Programming
    Replies: 8
    Last Post: 10-06-2007, 05:15 PM
  2. Creating a window causes a trackbar to stop working?
    By kidburla in forum Windows Programming
    Replies: 2
    Last Post: 09-20-2007, 06:44 AM
  3. help with creating window
    By Darkinyuasha1 in forum Windows Programming
    Replies: 6
    Last Post: 06-12-2007, 07:51 PM
  4. Creating a window through menu
    By Homunculus in forum Windows Programming
    Replies: 17
    Last Post: 02-20-2006, 06:56 PM
  5. Problem with creating new window, from another window
    By Garfield in forum Windows Programming
    Replies: 6
    Last Post: 01-11-2004, 02:10 PM

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