Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 27th, 2005, 7:20 PM   #31
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 816
Rep Power: 4 The Dark is on a distinguished road
Where are you getting hwndPB from? In your previous code it was never initialised.
The Dark is offline   Reply With Quote
Old Oct 28th, 2005, 3:46 AM   #32
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
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);
}
Got to run now, I'll help you later if it doesnt work
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Oct 28th, 2005, 6:15 AM   #33
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
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
nnxion is offline   Reply With Quote
Old Oct 28th, 2005, 7:29 AM   #34
badbasser98
Hobbyist Programmer
 
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4 badbasser98 is on a distinguished road
[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.
badbasser98 is offline   Reply With Quote
Old Oct 28th, 2005, 11:56 AM   #35
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by The Dark
InitCommonControls is in comctl32.lib, so you need to add that library to your project or linker line.
This is what you need to do. I don't have Dev-cpp but you should add the file to your resources.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Oct 29th, 2005, 9:53 AM   #36
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 925
Rep Power: 4 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by nnxion
Go to some college or university, ask them if they have can get really cheap copies of programs, ask him if he can get one for you, and bam! You have yourself a copy of a legal VC++ 2003 cd for just 20 bucks
Haha, I was thinking the same thing. I got VS.NET 2003, Project 2003, Visio 2003, and uhm.. WinXP Pro through my college, and the shipping cost dwarfed the actual cost of the software.

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
lectricpharaoh is offline   Reply With Quote
Old Oct 29th, 2005, 10:01 AM   #37
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 925
Rep Power: 4 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by badbasser98
[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
See if you can track down a local copy of the Win32 API reference. You can also use MSDN or the online help in VC++. There should be a listing of requirements for any classes, functions, and/or constants you want to use, including what header and library files you need, as well as what OS (for example, something might work under Win2000 but not under Win98). If you're compiling under VC++, just use whatever libs they say to use, but if using DevC++, you'll have to use the same library name, only with a '.a' extension (has to do with MinGW being a GNU-based compiler). Go to Project -> Project Options, hit the 'Parameters' tab, and under the 'Linker' list box, you'll see an 'Add Library or Object' button. You should be able to find your way from there.
__________________
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
lectricpharaoh is offline   Reply With Quote
Old Oct 31st, 2005, 7:17 AM   #38
badbasser98
Hobbyist Programmer
 
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4 badbasser98 is on a distinguished road
I'll give it a try, thanks

-BB98
__________________
Learning to use C++ and loving every minute of it.
badbasser98 is offline   Reply With Quote
Old Nov 1st, 2005, 9:23 AM   #39
badbasser98
Hobbyist Programmer
 
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4 badbasser98 is on a distinguished road
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.
badbasser98 is offline   Reply With Quote
Old Nov 1st, 2005, 1:40 PM   #40
badbasser98
Hobbyist Programmer
 
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4 badbasser98 is on a distinguished road
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.
badbasser98 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC