|
Programming Guru
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 
|
Sorry all wrong (comes from doing all by heart, without compiler), here is a good version:
#include <windows.h>
#include <commctrl.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
/* Global var */
char * className = "ProgressbarApp";
char * captionName = "Progressbar Application";
HWND hwndPB;
HINSTANCE hInstanceGlobal;
/* Function prototypes */
int APIENTRY WinMain( HINSTANCE, HINSTANCE, LPSTR, int );
BOOL InitApplication( HINSTANCE );
BOOL InitInstance( HINSTANCE, int );
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
MSG msg;
hInstanceGlobal= hInstance;
if (!InitApplication(hInstance))
return FALSE;
if (!InitInstance(hInstance, nCmdShow))
return FALSE;
while((GetMessage(&msg, NULL, 0, 0)) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
/* Initialise Application */
BOOL InitApplication( HINSTANCE hInstance )
{
WNDCLASS WndClass;
WndClass.style = 0;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.lpfnWndProc = WndProc;
WndClass.hInstance = hInstance;
WndClass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = className;
return RegisterClass(&WndClass);
}
BOOL InitInstance( HINSTANCE hInstance, int nCmdShow )
{
HWND hWnd = CreateWindow(className, captionName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
if(!hWnd)
return FALSE;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
switch(message)
{
case WM_CLOSE:
DestroyWindow(hwnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_CREATE:
HWND hButton;
RECT rcClient;
int cyVScroll;
hButton = CreateWindow("BUTTON", "Increment", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 100, 100, 100, 50, hwnd, (HMENU) 1, hInstanceGlobal, NULL);
InitCommonControls();
GetClientRect(hwnd, &rcClient);
cyVScroll = GetSystemMetrics(SM_CYVSCROLL);
hwndPB = CreateWindowEx(0, PROGRESS_CLASS,(LPCTSTR) NULL, WS_CHILD | WS_VISIBLE,
rcClient.left, rcClient.bottom - cyVScroll, rcClient.right, cyVScroll,
hwnd, (HMENU) 0, hInstanceGlobal, NULL);
SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
SendMessage(hwndPB, PBM_SETSTEP, (WPARAM) 20, 0);
break;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED)
{
if(LOWORD(wParam) == 1)
{
static int counter = 0;
if(!(counter > 4))
{
SendMessage(hwndPB, PBM_STEPIT, 0, 0);
counter++;
}
else
{
DestroyWindow(hwndPB);
}
}
}
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
|