Creating two Windows/Forms

This is a discussion on Creating two Windows/Forms within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I am trying to create an application which will display two forms, one will "roll" a dice (create a ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    7

    Exclamation Creating two Windows/Forms

    Hello,

    I am trying to create an application which will display two forms, one will "roll" a dice (create a random number) and I will then pass this to the other window/form which will display the result.

    Unfortunately I need to be able to do it within another thread so I will be sharing memory between them so I can pass the data across.

    So far i've completed the first screen, added menus and the random number side of things and now i'm trying to implement a second form in a similar attempt as the first one to display the results. I'm adding the CreateWindowEx() command in the WM_CREATE section so it is created when the first window starts.

    I've been trawling the internet and documents for a few days and I still can't find a solution to what I need.

    I've posted the entire solution I have so far (Minus the random number stuff, not really important).

    Would anybody be able to help in getting another window up and running? Im primarily from a C# background and i've not used C for long so it's all a bit new to me still.

    Thank you for your time.


    The application so far

    Code:
    //////////////////
    // WINDOWS MAIN //
    //////////////////
    int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst, 
    				   LPSTR lpszArgs, int nWinMode)
    {
    	// Declaration of window class (used to register program), 
    	// handle to window (returned by CreateWindow)
    	// and windows message (holds messages received from windows)
    	WNDCLASS wcl;
    	HWND hwnd;
    	MSG msg;
    
    	// Name of window and window class
    	LPCWSTR szWinName   = L"DiceRoller - Producer";
    	LPCWSTR szClassName = L"DiceRollProd";
    
    	// Set up the windows class struct
    	wcl.hInstance = hThisInst;
    	wcl.lpszClassName = szClassName;
    	wcl.lpfnWndProc = WindowFunc;
    	wcl.style = 0;
    	wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wcl.lpszMenuName = NULL;
    	wcl.cbClsExtra = 0;
    	wcl.cbWndExtra = 0;
    	wcl.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    
    	// Register the windows class
    	if(!RegisterClass(&wcl))
    	{
    		return 0;
    	}
    
    	// Create the main window
    	hwnd = CreateWindowEx(0,
    		szClassName,
    		szWinName,
    		WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN,
    		100,
    		100,
    		400,
    		400,
    		HWND_DESKTOP,
    		NULL,
    		hThisInst,
    		NULL );
    
    
    	// Show the main window
    	ShowWindow(hwnd, nWinMode);
    	UpdateWindow(hwnd);
    
    	// Main message processing loop
    	while(GetMessage(&msg, NULL, 0, 0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    	return (int)msg.wParam;
    }
    
    
    
    //////////////////////
    // WINDOWS FUNCTION //
    //////////////////////
    LRESULT CALLBACK WindowFunc(HWND hMainWindow, UINT message, 
    							WPARAM wParam, LPARAM lParam)
    {
    	//Fields
    	WCHAR buffer[256];
    	struct DiceData storage;
    	HWND hwnd;
    
    	// Act on current message
    	switch(message)    
    	{
    	case WM_CREATE:
    		AddMenus(hMainWindow);
    
    		hwnd = CreateWindowEx(
    			0,
    			"ChildWClass",
    			(LPCTSTR) NULL,
    			WS_CHILD | WS_BORDER | WS_VISIBLE,
    			0,
    			0,
    			400,
    			400,
    			hMainWindow,
    			NULL,
    			NULL,
    			NULL);
    
    		ShowWindow(hwnd, SW_SHOW);
    		UpdateWindow(hwnd);
    
    		break;
    Last edited by AnkleSpankle; 04-07-2010 at 04:17 PM.

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    In the second call to CreateWindowEx, you are saying that you want a child window but you aren't specifying required parameters.

    CreateWindowEx Function (Windows)

    You still need to specifiy the HINSTANCE and a child window identifier (just a unique integer value). To get the HINSTANCE when you aren't in WinMain (without declaring a global variable), look into GetWindowLong ( GetWindowLong Function (Windows) ).

    Oh, and make sure that "ChildWClass" is actually a class. Note that classes aren't global unless specifically set like that, so you can't register a class from another application unless the application has specified CS_GLOBALCLASS when it registered the class.

    Another thing, when GetMessage encounters an error, it returns -1. So you shouldn't check to see whether it's true, check to see if it is greater than 0 instead.

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    7
    Excellent, thank you for the help.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help creating multiple text files
    By Tom Bombadil in forum C Programming
    Replies: 19
    Last Post: 03-28-2009, 12:21 PM
  2. Error in creating socket in a client (UDP)
    By ferenczi in forum Networking/Device Communication
    Replies: 2
    Last Post: 11-27-2008, 11:11 AM
  3. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 10:38 AM
  4. creating an application
    By Cpro in forum C++ Programming
    Replies: 21
    Last Post: 05-30-2008, 01:21 AM
  5. problems creating a linked list
    By jamjar in forum C Programming
    Replies: 5
    Last Post: 10-23-2002, 06:50 AM

Tags for this Thread


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