![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#31 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 816
Rep Power: 4
![]() |
Where are you getting hwndPB from? In your previous code it was never initialised.
|
|
|
|
|
|
#32 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Well I can't test it here, but try something like: (don't forget to inlude the lib)
#include <windows.h>
#include <commctrl.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
/* Global var */
char * className = "ProgressbarApp";
char * captionName = "Progressbar Application";
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 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(msg)
{
case WM_CLOSE:
DestroyWindow(hwnd);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_CREATE:
void OnWmCreate(hInstanceGlobal, hwnd);
break;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED)
{
if(LOWORD(wParam) == 1)
{
OnButtonClicked();
}
}
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
}
void OnWmCreate( HINSTANCE hInstance, HWND hwnd )
{
HWND hButton;
RECT rcClient;
HWND hwndPB;
hButton = CreateWindow("BUTTON", "Increment", WS_CHILD | WS_VISIBLE | BS_PUSBUTTON, 100, 100, 100, 100, hwnd, (HMENU) 1, hInstanceGlobal, NULL);
InitCommonControls();
GetClientRect(hwndParent, &rcClient);
hwndPB = CreateWindowEx(0, PROGRESS_CLASS, (LPCTSTR) NULL, WS_CHILD | WS_VISIBLE,
rcClient.left, rcClient.bottom, rcClient.right - rcClient, rcClient.top - rcClient.bottom,
hwnd, (HMENU) 0, hInstance, NULL);
SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
SendMessage(hwndPB, PBM_SETSTEP, (WPARAM) 20, 0);
DestroyWindow(hwndPB);
}
void OnButtonClicked()
{
SendMessage(hwndPB, PBM_STEPIT, 0, 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 |
|
|
|
|
|
#33 |
|
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 |
|
|
|
|
|
#34 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
[Linker error] undefined reference to `InitCommonControls@0' I got this message before one some code that I wrote that was exactly like an example that I saw, except altered for the ranges, variables that I need in my prog. Bug in Dev-C++? I have version 4.9.9.2 Thanks for the help nnxion, -BB98
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
|
|
#35 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
|
#36 | |
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 925
Rep Power: 4
![]() |
Quote:
Hmm. My school has recently changed things around, and now my campus email is different, and I've started to get new emails from the MSDN's 'Academic Alliance' program; I wonder if this means I can get additional copies of the software. You know, in case I run out of 'activations' or something. ![]()
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp |
|
|
|
|
|
|
#37 | |
|
Caffeinated Neural Net
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 925
Rep Power: 4
![]() |
Quote:
![]()
__________________
A man's knowledge is like an expanding sphere, the surface corresponding to the boundary between the known and the unknown. As the sphere grows, so does its surface; the more a man learns, the more he realizes how much he does not know. Hence, the most ignorant man thinks he knows it all. - L. Sprague de Camp |
|
|
|
|
|
|
#38 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
I'll give it a try, thanks
-BB98
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
|
|
#39 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
Adding that library worked, let me try that in my program.
Thanks for the help -BB98
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
|
|
#40 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
Well now I have got the progress bar to show, but it will not increment... The program actually does what it is supposed to do, except the user does not get any notification that it has done anything. Obviously, I would like the progress bar to increment, as well as some text to be displayed after each file is removed (or attempted to be removed, if it does not exist). You can find the code that I want to do this in a previous post (the one that starts with "case WM_COMMAND:" in the code field.) Is it possible to do what I am asking in that area of the code? or probably a different way to go about it...
Thanks for the help, you guys have been great. Without your help this would have been a very long, drawn out, frustrating process. -BB98
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|