Parent not repainting Bitmp after child window closes

This is a discussion on Parent not repainting Bitmp after child window closes within the Windows Programming forums, part of the Platform Specific Boards category; Can someone take a look at my code and see if I'm missing something thats causing my parent window not ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    3

    Parent not repainting Bitmp after child window closes

    Can someone take a look at my code and see if I'm missing something thats causing my parent window not to repaint the bitmap.

    Code:
    #include <windows.h>
    #include <commdlg.h>
    
    #include "resource.h"
    #include "Functions.h"
    #include "Variables.h"
    
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    				   LPSTR lpCmdLine, int nCmdShow)
    {
    	WNDCLASSEX wc; //Structure and call RegisterClassEX()
    	HWND MainWindow;
    	MSG Msg;
    
    		wc.cbSize		= sizeof(WNDCLASSEX);				//Size of the structure
    		wc.style		= CS_HREDRAW |CS_VREDRAW;								//Class Styles(cs_*), not be confused withwindow Styles(WS_*)This can usually be set to 0.
    		wc.lpfnWndProc	= WndProc;							//Pointer to the window procedure for this window class.
    		wc.cbClsExtra	= 0;								//Amount of extra data allocated for this class in memory. Usually 0.
    		wc.cbWndExtra	= 0;								//Amount of extra data allocatedin memory per window of this type. Usually 0.
    		wc.hInstance	= hInstance;						//Handle to application instance( that I got in the first parameter of WinMain().
    		wc.hCursor		= LoadCursor(NULL, IDC_ARROW);		//Cursor that will be displayed over the window.
    		wc.hbrBackground= (HBRUSH) GetStockObject (WHITE_BRUSH);//Background brush to set the color of the window.
    		wc.lpszMenuName	= NULL;		//Name of a menu resource to use for the windows with this class.
    		wc.lpszClassName= main_window;						//Name to identify the class with.
    		wc.hIcon		= LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
    		wc.hIconSm		= (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, 0);
    		
    if(!RegisterClassEx(&wc))		// To check for failure
    {
    	MessageBox(NULL, "Window Registration Failed!", "Error!",
    		MB_ICONEXCLAMATION | MB_OK);
    	return 0;
    }//End of IF
    //************************************************************************
    MainWindow = CreateWindowEx(					//Create a the window
            WS_EX_CLIENTEDGE,						//Extended windows style
            main_window,							//Class name
            "Busby Cabinets",						//Title
            WS_OVERLAPPEDWINDOW | WS_MAXIMIZE,		//Window style parameter
            0,0, CW_USEDEFAULT, CW_USEDEFAULT,	//X,Y coordinates or use CW_USEDEFAULT, CW_USEDEFAULT for default positioning
            NULL, NULL, hInstance, NULL);			//Parent window, menu handle, windows on application handle,
    												//pointer to window creation data.
    //************************************************************************   
    if(MainWindow == NULL)								// Check to make sure that we have a valid handle.
        {
            MessageBox(NULL, "Window Creation Failed!", "Error!",
                MB_ICONEXCLAMATION | MB_OK);
            return 0;
        }
    //************************************************************************
        ShowWindow(MainWindow, nCmdShow);					
        UpdateWindow(MainWindow);
    //************************************************************************
    	//The Message LOOP
    
    	while(GetMessage(&Msg, NULL, 0, 0) > 0)		//Gets a message from your application's message queue.
    	{
    		TranslateMessage(&Msg);					//Requesting the next available message
    		DispatchMessage(&Msg);					//Does some more processing
    	}
    	return Msg.wParam;
    }
    //***********************************************************************
    //The Window Procedure
    	LRESULT CALLBACK WndProc(HWND MainWindow, UINT msg, WPARAM wParam, LPARAM lParam)
    	{
    		static HBITMAP	hBitmap;
    		static RECT		rect;
    		static int		cxClient, cyClient, cxSource, cySource;
    		BITMAP			bitmap1;
    		HINSTANCE		hInstance;
    		PAINTSTRUCT		ps;
    		HDC				hdc, hdcMem;
    		switch(msg)
    		{
    		case WM_CREATE:
    			//**************************************************
    			HMENU hMenuMain;
    			hMenuMain = LoadMenu(hInst,MAKEINTRESOURCE (IDR_MENU1));
    
    			hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
    			hBitmap = LoadBitmap(hInstance,TEXT("Bee"));
    			GetObject (hBitmap, sizeof (BITMAP), &bitmap1);
    			cxSource = bitmap1.bmWidth;
    			cySource = bitmap1.bmHeight;
    			SetMenu(MainWindow,hMenuMain);
    			return 0;
    			//**************************************************
    
    		case WM_SIZE:
    			
    			cxClient = LOWORD(lParam);
    			cyClient = HIWORD(lParam);
    			return 0;
    
    		case WM_PAINT:
    			
    			hdc = BeginPaint(MainWindow, &ps);
    			hdcMem = CreateCompatibleDC(hdc);
    			SelectObject (hdcMem, hBitmap);
    
    			SetStretchBltMode(hdc,STRETCH_DELETESCANS);
    			StretchBlt (hdc,0,0,cxClient, cyClient, hdcMem,0,0,cxSource, cySource, MERGECOPY);
    
    			DeleteDC (hdcMem);
    			EndPaint(MainWindow, &ps);
    			return 0;
            case WM_COMMAND:
    		switch (LOWORD(wParam))
    		{
    		case ID_NEW_BSIGNATURE:
    			switch (msg)
    			{
    			case WM_COMMAND:
    				MessageBox(MainWindow, TEXT ("BSignature's library is not Implemented at this time."),"BSignature",0);
    				case WM_CREATE:
    				HWND Bsignature;
    				HMENU hmenu;
    				hmenu = LoadMenu(hInst,MAKEINTRESOURCE (IDR_MENU2));
    				SetMenu(MainWindow,hmenu);
    				case WM_PAINT:
    					InvalidateRect(MainWindow, &rect,TRUE);
    				
    				Bsignature = CreateWindow(main_window,NULL, WS_CHILD | WS_VISIBLE, 200,
    					0, 200,200,MainWindow,NULL,hInst,NULL, NULL);
    			return 0;
    			}
    ////////////////////////////////////////////////////////////////////
    ///////// Menu For BSignature /////////////////////////////////
    		case ID_FILE_SAVE40012:
    			return 0;
    		case ID_FILE_SAVEAS40013:
    			return 0;
    		case ID_FILE_CLOSE40014:
    				case WM_CREATE:
    				HMENU hMenuMain;
    				hMenuMain = LoadMenu(hInst,MAKEINTRESOURCE (IDR_MENU1));
    				SetMenu(MainWindow,hMenuMain);
    				UpdateWindow(MainWindow);
    				
    		case ID_EDIT_UNDO40015:
    			return 0;
    		case ID_EDIT_REDO40016:
    			return 0;
    		case ID_EDIT_UNITSOFMEASURE:
    			return 0;
    		case ID_WINDOW:
    			return 0;
    		case ID_HELP40019:
    			return 0;
    ////////////////////////////////////////////////////////////////////
    		case ID_NEW_BSELECT:
    			return 0;
    		case ID_NEW_KC:
    			return 0;
    		case ID_NEW_KC40009:
    			return 0;
    		case ID_NEW_EK:
    			return 0;
    		case ID_FILE_SAVE40003:
    			return 0;
    		case ID_FILE_SAVEAS:
    			return 0;
    		case ID_FILE_OPEN40002:
    			MessageBox(MainWindow, TEXT ("OPEN is not Implemented at this time."),"Open",0);
    			return 0;
    		case ID_FILE_EXIT:
    			SendMessage (MainWindow, WM_CLOSE, 0, 0);
    			return 0;
    		case ID_ABOUT:
    			MessageBox(MainWindow,TEXT ("Version = [Prototype]\n")
    						TEXT ("Company = [C]\n")
    						TEXT ("Designer = []\n")
    						TEXT ("Program = [B]\n"),"About",MB_ICONINFORMATION);
    			return 0;
    			break;
    }//End Switch
    		case WM_DESTROY:
    			DeleteObject(hBitmap);
    			PostQuitMessage(0);
    			return 0;
    			break;
    	default:
    		return DefWindowProc(MainWindow, msg, wParam, lParam);
    		}//End Switch
    		return 0;
    	}//End WinProc
    //*****************************************************************

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    I see nothing wrong with your code. In fact, I copied into my compiler, and it ran just fine. You need to a be a little more specific with what your problem is, because it's repainting just fine on my computer.

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3

    Little more info

    If you go to file then new and select Bsignature, a child window will pop up, then if you go to file and close. The Child window erased a part of the parent window, and the parent will not repaint the bitmap. Hope thats enough of info.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    Call InvalidateRect() right before your call to UpdateWindow().

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    3

    Not what I'm looking for

    Maybe this will help.

    Say you start the exe, the paerent window pops up with a bitmap in the client area. Thats the main area. Then you go to create a new job then the parent window loads a new menu, tools, and a place to paint, and the bitmap goes away. Then after your done, you close the job, and the parent window goes back to its normal state with the bitmap in the client area.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    I don't see anything in your code which causes the bitmap to "go away", nor do I see anything that would cause the bitmap to not get repainted.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  2. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM
  3. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

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