[C con Clase] Una ayuda con l barra de progreso
Juan Antonio
jalr43 en hotmail.com
Mie Ene 24 17:17:21 CET 2007
Hola Danny,
busca en internet "progress bar control msdn". El ejemplo que adjunto abajo lo he sacado de la MSDN y estoy seguro que te puede orientar con el control.
Si lo quieres crear en la ventana principal haz uso del mensaje WM_CREATE en tu función CALLBACK. Por el contrario si lo quieres usar en un diálogo usa la clase PROGRESS_CLASS para crearlo con estilos como están en CreateWindowEx abajo. Pero antes de abrir el diálogo tienes que hacer una inicialización que muestro abajo.
// 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.
InitCommonControls();
Espero que te ayude.
Un saludo,
Juan Antonio.
// 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
extern HINSTANCE g_hinst;
BOOL ParseALargeFile(HWND hwndParent, LPSTR lpszFileName)
{
RECT rcClient; // Client area of parent window
int cyVScroll; // Height of scroll bar arrow
HWND hwndPB; // Handle of progress bar
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
// 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.
InitCommonControls();
GetClientRect(hwndParent, &rcClient);
cyVScroll = GetSystemMetrics(SM_CYVSCROLL);
hwndPB = CreateWindowEx(0, PROGRESS_CLASS,
(LPSTR) NULL, WS_CHILD | WS_VISIBLE,
rcClient.left, rcClient.bottom
cyVScroll, rcClient.right, cyVScroll,
hwndParent, (HMENU) 0, g_hinst, NULL);
// 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);
// 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);
// TODO: Write an error handler to check that all the
// requested data was read.
.
.
// Include here any code that parses the
// file.
.
// Advance the current position of the
// progress bar by the increment.
SendMessage(hwndPB, PBM_STEPIT, 0, 0);
} while (cb);
CloseHandle((HANDLE) hFile);
DestroyWindow(hwndPB);
return TRUE;
}
----- Original Message -----
From: Danny Roldan
To: cconclase en listas.conclase.net
Sent: Wednesday, January 24, 2007 4:36 PM
Subject: [C con Clase] Una ayuda con l barra de progreso
Hola: Quisiera que me ayudaran a crear( o simular) una barra de progreso, la verdad es que no trabajo con las MFC, pero me dejaron el trabajo en l universidad y no tengo idea de que hacer. Muchas Gracias de antemano.
Danny
------------------------------------------------------------------------------
Éxitos, grandes clásicos y novedades. Un millón de canciones en MSN Music.
------------------------------------------------------------------------------
_______________________________________________
Lista de correo Cconclase Cconclase en listas.conclase.net
http://listas.conclase.net/mailman/listinfo/cconclase_listas.conclase.net
Bajas: http://listas.conclase.net/index.php?gid=2&mnu=FAQ
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.conclase.net/pipermail/cconclase_listas.conclase.net/attachments/20070124/c528dfa6/attachment-0001.html>
Más información sobre la lista de distribución Cconclase