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;
}
///////////////////////////////////////////////////////////////////////////////////////////