LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

progress bar in CVI 5.5

Hi all,
Can anybody tell me how
to make a progress bar
in labwindows CVI 5.5 ?


Thanks,
MK. Tan
0 Kudos
Message 1 of 4
(3,705 Views)
Have you tried with CreateProgressDialog() in the Programmer's Toolbox?
You'll find it in \toolslib\toolbox directory and you can load it as an
instrument or as a library (options/library options).
Roberto
0 Kudos
Message 2 of 4
(3,705 Views)
I use a horizontal numeric slide control.
Regards,
Reed.
//----------------------------------------------------------
Reed Blake
Beta Technology
Industrial and Scientific Computing

MK. Tan wrote in message <39e9bc8e@newsgroups.ni.com>...
>
>Hi all,
>Can anybody tell me how
>to make a progress bar
>in labwindows CVI 5.5 ?
>
>
>Thanks,
>MK. Tan
0 Kudos
Message 3 of 4
(3,705 Views)
"MK. Tan" wrote:
>>Hi all,>Can anybody tell me how >to make a progress bar >in labwindows
CVI 5.5 ?>>>Thanks,>MK. Tan

To get a Window-like progress bar I tried this way.





#include
/*
#define PB_DELTAPOS PBM_DELTAPOS
#define PB_SETPOS PBM_SETPOS
#define PB_SETRANGE PBM_SETRANGE
#define PB_SETSTEP PBM_SETSTEP
#define PB_STEPIT PBM_STEPIT
*/
extern int CreateProgressBar (int panelhandle, int left, int top, int width,
int height, HWND *handlePB);
extern void DestroyProgressBar (HWND handlePB);
extern void ResetProgressBar (HWND handlePB);
extern int ConvertFromGraphProgressBar (int panelhandle, int controlID, HWND
*handlePB);










#include
#include
//#include NON SI PUO' INCLUDERE PROBLEMI CON GetFileSize
#include


HINSTANCE g_hinst;


static RECT rcClient; // client area of parent window
static int cyVScroll; // height of scroll bar arrow

/*
* CreateProgressBar
* disegna una Progress Bar
* POSIZIONE :
* di default (left = 0, top = 0, width = 0, height = 0) sul fondo della
finestra padre
* altrimenti e' possibile impostare valori diversi per ognuno o qualcuno
dei quattro
* valori impostabili (left, top, width, height)
* RESTITUISCE :
* 1) handle (HWND) della Progress Bar a cui riferirsi per le altre funzioni
* 2) error (int) 0 se operazione riuscita con successo
*
*/
int CreateProgressBar (int panelhandle, int left, int top, int width, int
height, HWND *handlePB)
{
HWND hwndParent;
int number, error;

error = GetPanelAttribute (panelhandle, ATTR_SYSTEM_WINDOW_HANDLE,
&number);

hwndParent = (HWND) number;

InitCommonControls();
GetClientRect(hwndParent, &rcClient);

if (height == 0)
cyVScroll = GetSystemMetrics(SM_CYVSCROLL);
else
cyVScroll = height;

*handlePB = CreateWindowEx(0, PROGRESS_CLASS, (LPSTR) NULL,
WS_CHILD | WS_VISIBLE,
(left == 0) ? rcClient.left : left,
(top == 0) ? (rcClient.bottom - cyVScroll) : top,
((left + width) == 0) ? rcClient.right : (left + width),
(height == 0) ? cyVScroll : height,
hwndParent, (HMENU) 0, g_hinst, NULL);

return (error);
}


/*
*
*/
int ConvertFromGraphProgressBar (int panelhandle, int controlID, HWND *handlePB)

{
HWND hwndParent;
int number, error;
int left, top, width, height;

error = GetPanelAttribute (panelhandle, ATTR_SYSTEM_WINDOW_HANDLE,
&number);

hwndParent = (HWND) number;

InitCommonControls();

GetCtrlAttribute (panelhandle, controlID, ATTR_LEFT, &left);
GetCtrlAttribute (panelhandle, controlID, ATTR_TOP, &top);
GetCtrlAttribute (panelhandle, controlID, ATTR_WIDTH, &width);
GetCtrlAttribute (panelhandle, controlID, ATTR_HEIGHT, &height);


cyVScroll = height;

*handlePB = CreateWindowEx(0, PROGRESS_CLASS, (LPSTR) NULL,
WS_CHILD | WS_VISIBLE,
left,
top,
width,
height,
hwndParent, (HMENU) 0, g_hinst, NULL);

return (error);
}

void DestroyProgressBar (HWND handlePB)
{
DestroyWindow(handlePB);
}


void SetProgressBar (HWND handlePB)
{
SendMessage(handlePB, PBM_SETPOS, 0, 0);
}


void ResetProgressBar (HWND handlePB)
{
SendMessage(handlePB, PBM_SETPOS, 0, 0);
}









#include
#include /* Needed if linking in external compiler; harmless
otherwise */
//#include
#include "panello.h"

static int panelHandle;

// ParseALargeFile - parses a large file and uses a progress bar to
// indicate the progress of the parsing operation.
// Returns TRUE if successful or FALSE otherwise.
// hwndParent - parent window of the progress bar
// lpszFileName - name of the file to parse
//
// Global variable
// g_hinst - instance handle
#include
#include
//#include NON SI PUO' INCLUDERE PROBLEMI CON GetFileSize
#include

int DrawProgressBar (int panelhandle, HWND *handlePB);
BOOL ParseALargeFile(LPSTR lpszFileName);
void EraseProgressBar (HWND handlePB);

HINSTANCE g_hinst;


//int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
lpszCmdLine, int nCmdShow)
//{
//}

RECT rcClient; // client area of parent window
int cyVScroll; // height of scroll bar arrow
HWND hwndPB; // handle of progress bar


int DrawProgressBar (int panelhandle, HWND *handlePB)
{
HWND hwndParent;
int number, error;

error = GetPanelAttribute (panelhandle, ATTR_SYSTEM_WINDOW_HANDLE,
&number);

hwndParent = (HWND) number;

InitCommonControls();
GetClientRect(hwndParent, &rcClient);
cyVScroll = GetSystemMetrics(SM_CYVSCROLL);
*handlePB = CreateWindowEx(0, PROGRESS_CLASS, (LPSTR) NULL,
WS_CHILD | WS_VISIBLE, rcClient.left,
rcClient.bottom - cyVScroll,
rcClient.right, cyVScroll,
hwndParent, (HMENU) 0, g_hinst, NULL);

return (0);
}

void EraseProgressBar (HWND handlePB)
{
DestroyWindow(handlePB);
}


void ResetProgressBar (HWND handlePB)
{
SendMessage(handlePB, PBM_SETPOS, 0, 0);
}

BOOL ParseALargeFile(LPSTR lpszFileName)
{
HANDLE hFile; // handle of file
DWORD cb; // size of file and count of bytes read
LPCH pch; // address of data read from file
LPCH pchTmp; // temporary pointer
long pippo;

// Ensure that the common control DLL is loaded and create a
// progress bar along the bottom of the client area of the
// parent window. Base the height of the progress bar on
// the height of a scroll bar arrow.

// Open the file for reading, and retrieve the size of the file.
hFile = CreateFile(lpszFileName, GENERIC_READ, FILE_SHARE_READ,
(LPSECURITY_ATTRIBUTES) NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, (HANDLE) NULL);

if (hFile == (HANDLE) INVALID_HANDLE_VALUE)
return FALSE;

// cb = GetFileSize(hFile, (LPDWORD) NULL);
GetFileSize(lpszFileName, &pippo);
cb = (DWORD) pippo;

// Set the range and increment of the progress bar.
SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0, cb / 2048));
SendMessage(hwndPB, PBM_SETSTEP, (WPARAM) 1, 0);

// Parse the file.
pch = (LPCH) LocalAlloc(LPTR, sizeof(char) * 2048);
pchTmp = pch;
do {
ReadFile(hFile, pchTmp, sizeof(char) * 2048, &cb,
(LPOVERLAPPED) NULL);

// Include here any code that parses the file.


Delay (0.01);

// Advance the current position of the progress bar
// by the increment.
SendMessage(hwndPB, PBM_STEPIT, 0, 0);
} while (cb);

ResetProgressBar (hwndPB);

CloseHandle((HANDLE) hFile);

return TRUE;
}


int main (int argc, char *argv[])
{

if (InitCVIRTE (0, argv, 0) == 0) /* Needed if linking in external compiler;
harmless otherwise */
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "panello.uir", PANEL)) < 0)
return -1;
DisplayPanel (panelHandle);

DrawProgressBar (panelHandle, &hwndPB);


RunUserInterface ();

return 0;
}



int CVICALLBACK ExitApp_xButton (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
switch (event)
{
case EVENT_COMMIT:
EraseProgressBar (hwndPB);

QuitUserInterface (0);
break;
}
return 0;
}

int CVICALLBACK StartProgressBar (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{


switch (event)
{
case EVENT_COMMIT:
ParseALargeFile ("pippo.ppp");

break;
case EVENT_LEFT_CLICK:

break;
case EVENT_RIGHT_CLICK:

break;
case EVENT_RIGHT_DOUBLE_CLICK:

break;
case EVENT_KEYPRESS:

break;
}
return 0;
}
0 Kudos
Message 4 of 4
(3,704 Views)