Thread: Creating a progress window

  1. #1
    Registered User Xzyx987X's Avatar
    Join Date
    Sep 2003
    Posts
    107

    Creating a progress window

    Been a while since I had a problem bad enough to need to post it here. I guess that's a good sign . Anyway, I'm creating a window class and supporting functions for a window that will pop up and show a progress bar and a cancel button. I'm writing it so it will be able to be draw inside of another window as well as in it's own window. I've gotten to the point where by calling the create function I should at least be seeing something, but no matter what I try I can't get what I have so far to display anything at all. I've tried messing with it numerous ways, but it just won't show any signs of working. I posted below the full code I have written for this. Can anyone here figure out what I'm doing wrong?
    Code:
    //Include files////////////////////////////////////////////////////////////////////////////
    
    #include "global_definitions.h"
    
    #include <windows.h>
    #include <commctrl.h>
    #include "debug.h"
    #include "memory.h"
    #include "window_classes.h"
    
    ///////////////////////////////////////////////////////////////////////////////////////////
    
    
    
    //Function prototypes//////////////////////////////////////////////////////////////////////
    
    //Progress Window
    
    //Usage Notes:
    //
    //First, Initialize the progress window class be calling InitProgressWindowClass
    //Before calling a funtion that uses a progress routine, call CreateProgressWindow and
    //save the return to a HWND variable.
    //When calling a funtion that uses a progress routine, pass CopyProgressRoutine as the
    //routine and the address of the HWND from the previous step as the data pointer
    
    void InitProgressWindowClass(void);
    
    HWND CreateProgressWindow(HWND hWndParent, char * title, BOOL popup, RECT * progressCords);
    
    void DestroyProgressWindow(HWND hWndProgress, BOOL cancel);
    
    INT_PTR CALLBACK ProgressWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    
    DWORD CALLBACK CopyProgressRoutine(LARGE_INTEGER TotalFileSize, LARGE_INTEGER TotalBytesTransferred, LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData);
    
    ///////////////////////////////////////////////////////////////////////////////////////////
    
    
    
    //Function definitions/////////////////////////////////////////////////////////////////////
    
    void InitProgressWindowClass(void)
    {
    
        WNDCLASSEX wc = {0};
    
        //Register the progress window class
    
        wc.cbSize         = sizeof(wc);
        wc.lpszClassName  = "Progress Window";
        wc.hInstance      = GetModuleHandle(NULL);
        wc.lpfnWndProc    = ProgressWindowProc;
        wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
        wc.hbrBackground  = (HBRUSH)GetSysColorBrush(COLOR_BTNFACE);
        wc.cbWndExtra     = sizeof(PROGRESSINFO *);
    
        RegisterClassEx(&wc);
    
    }
    
    HWND CreateProgressWindow(HWND hWndParent, char * title, BOOL popup, RECT * progressCords)
    {
    
    	HWND hWndProgress;
    	DWORD dwStyle = WS_CHILD | WS_VISIBLE;
    	char * windowTitle = 0;
    
    	if(!windowTitle)
    		windowTitle = "";
    
    	if(popup)
    		dwStyle |= WS_OVERLAPPED;
    	else
    		dwStyle |= WS_DLGFRAME;
    
    	hWndProgress = CreateWindow(
    		"Progress Window",
    		windowTitle,
    		dwStyle,
    		progressCords->left,
    		progressCords->top,
    		progressCords->right - progressCords->left,
    		progressCords->bottom - progressCords->top,
    		hWndParent,
    		NULL,
    		GetModuleHandle(NULL),
    		&hWndParent);
    
    	return hWndProgress;
    
    }
    
    void DestroyProgressWindow(HWND hWndProgress, BOOL cancel)
    {
    
    
    
    }
    
    INT_PTR CALLBACK ProgressWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    
    	PROGRESSINFO * pip = (PROGRESSINFO *) GetWindowLongPtr(hWnd, GWL_USERDATA);
    
    	switch(uMsg)
    	{
    
    	case WM_NCCREATE:
    		SetWindowLongPtr(hWnd, GWL_USERDATA, (LONG) ClearMemAlloc(sizeof(PROGRESSINFO)));
    		return FALSE;
    		break;
    
    	case WM_CREATE:
    		pip->progressBar = CreateWindowEx(
    			0,
    			PROGRESS_CLASS,
    			NULL,
    			WS_CHILD | WS_VISIBLE,
    			0,
    			0,
    			50,
    			50,
    			hWnd,
    			0,
    			GetModuleHandle(NULL),
    			NULL);
    		return FALSE;
    		break;
    
    	case WM_DESTROY:
    		free((void *) GetWindowLongPtr(hWnd, GWL_USERDATA));
    		return FALSE;
    		break;
    
    	}
    
        return DefWindowProc(hWnd, uMsg, wParam, lParam);
    
    }
    
    DWORD CALLBACK CopyProgressRoutine(LARGE_INTEGER TotalFileSize, LARGE_INTEGER TotalBytesTransferred, LARGE_INTEGER StreamSize, LARGE_INTEGER StreamBytesTransferred, DWORD dwStreamNumber, DWORD dwCallbackReason, HANDLE hSourceFile, HANDLE hDestinationFile, LPVOID lpData)
    {
    
    	return PROGRESS_CONTINUE;
    
    }
    
    ///////////////////////////////////////////////////////////////////////////////////////////

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    If you use the WS_CHILD style, you must provide a parent window. I think you probably want to change:
    Code:
    DWORD dwStyle = WS_CHILD | WS_VISIBLE;
    to:
    Code:
    DWORD dwStyle = (hWndParent != NULL ? WS_CHILD : 0) | WS_VISIBLE;

  3. #3
    Registered User Xzyx987X's Avatar
    Join Date
    Sep 2003
    Posts
    107
    Doing that probobly is a good idea, but it still doesn't get my create function to display anything...

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Quote Originally Posted by MSDN
    WM_NCCREATE documentation

    If an application processes this message, it should return TRUE to continue creation of the window. If the application returns FALSE, the CreateWindow or CreateWindowEx function will return a NULL handle.
    1234

  5. #5
    Registered User Xzyx987X's Avatar
    Join Date
    Sep 2003
    Posts
    107
    how did I miss that? Looks like I've been using dialog boxes too much lately...

  6. #6
    Registered User Xzyx987X's Avatar
    Join Date
    Sep 2003
    Posts
    107
    Ungh, now I can't get the progress bar to appear. Here's what my ProgressWindowProc looks like at this point.
    Code:
    INT_PTR CALLBACK ProgressWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    
    	PROGRESSINFO * pip = (PROGRESSINFO *) GetWindowLongPtr(hWnd, GWL_USERDATA);
    
    	switch(uMsg)
    	{
    
    	case WM_NCCREATE:
    		SetWindowLongPtr(hWnd, GWL_USERDATA, (LONG) ClearMemAlloc(sizeof(PROGRESSINFO)));
    		return TRUE;
    		break;
    
    	case WM_CREATE:
    		pip->progressBar = CreateWindowEx(
    			0,
    			PROGRESS_CLASS,
    			NULL,
    			WS_CHILD | WS_VISIBLE | PBS_SMOOTH,
    			0,
    			0,
    			50,
    			GetSystemMetrics(SM_CYVSCROLL),
    			hWnd,
    			0,
    			GetModuleHandle(NULL),
    			NULL);
    		pip->hWndProgress = (HWND) lParam;
    		return FALSE;
    		break;
    
    	case WM_DESTROY:
    		free((void *) GetWindowLongPtr(hWnd, GWL_USERDATA));
    		return FALSE;
    		break;
    
    	}
    
        return DefWindowProc(hWnd, uMsg, wParam, lParam);
    
    }
    EDIT:
    In case you were wondering, yes I did initialize the progress class:
    Code:
    	INITCOMMONCONTROLSEX initControls;
    
    	initControls.dwSize = sizeof(INITCOMMONCONTROLSEX);
    	initControls.dwICC = ICC_PROGRESS_CLASS;
    
    	InitCommonControlsEx(&initControls);
    I also checked if the call to CreateWindowEx was returning a valid hWnd, and it was.
    Last edited by Xzyx987X; 10-06-2004 at 02:48 PM.

  7. #7
    Registered User Xzyx987X's Avatar
    Join Date
    Sep 2003
    Posts
    107
    Err nm, it actually was appearing, I just couldn't tell because I didn't give it a border :P.

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, 04: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, 05:44 AM
  3. help with creating window
    By Darkinyuasha1 in forum Windows Programming
    Replies: 6
    Last Post: 06-12-2007, 06: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