Hi!
I would like to do an overlap window, over my main window (of my
application), with a Progress Bar. Exactly when I push a button of my
application I want show a window, with a Progress bar, during the processing
time.
The first question is: Is it possible to have an overlap window? (I create
my windows by the "CreateWindowEx" command) By which command
Is possible to create a "MessageBox" with a progress bar?
Someone know where can I found some sample like this?
I tried to do that first with the application below, maybe someone can give
a look and suggest me something, thanks!!
#include <windows.h>
#include <commctrl.h>
HINSTANCE g_hInst = NULL; // Handle to the application instance
HWND g_hwndMain = NULL; // Handle to the application main window
HWND g_hwndMain2 = NULL; // Handle to the application main window
TCHAR g_szTitle[80] = TEXT ("Main Window"),
// Application main window name
g_szClassName[80] = TEXT ("Main window class");
// Main window class name
#define ID_COMPONTXT 1
/************************************************** *********************
FUNCTION:
WndProc
PURPOSE:
The callback function for the main window. It processes messages that
are sent to the main window.
************************************************** *********************/
LRESULT CALLBACK WndProc (HWND hwnd, UINT umsg, WPARAM wParam,
LPARAM lParam)
{
switch (umsg)
{
// Add cases such as WM_CREATE, WM_COMMAND, WM_PAINT if you don't
// want to pass these messages along for default processing.
case WM_CLOSE:
DestroyWindow (g_hwndMain);
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (g_hwndMain, umsg, wParam, lParam);
}
/************************************************** *********************
FUNCTION:
InitInstance
PURPOSE:
Create and display the main window.
************************************************** *********************/
BOOL InitInstance (HINSTANCE hInstance, int iCmdShow)
{
g_hInst = hInstance;
g_hwndMain2 = CreateWindow (
g_szClassName, // Registered class name
g_szTitle, // Application window name
WS_OVERLAPPED, // Window style
70, // Horizontal position of the window
120, // Vertical position of the window
100, // Window width
100, // Window height
NULL, // Handle to the parent window
NULL, // Handle to the menu the identifier
hInstance, // Handle to the application instance
NULL); // Pointer to the window-creation data
g_hwndMain = CreateWindow (
g_szClassName, // Registered class name
g_szTitle, // Application window name
WS_EX_CLIENTEDGE, // Window style
CW_USEDEFAULT,//70, // Horizontal position of the window
CW_USEDEFAULT,//120, // Vertical position of the window
CW_USEDEFAULT,//100, // Window width
CW_USEDEFAULT,//100, // Window height
NULL, // Handle to the parent window
NULL, // Handle to the menu the identifier
hInstance, // Handle to the application instance
NULL); // Pointer to the window-creation data
// If it failed to create the window, return FALSE.
if (!g_hwndMain)
return FALSE;
ShowWindow (g_hwndMain, iCmdShow);
UpdateWindow (g_hwndMain);
// If it failed to create the window, return FALSE.
if (!g_hwndMain2)
return FALSE;
ShowWindow (g_hwndMain2, iCmdShow);
UpdateWindow (g_hwndMain2);
return TRUE;
}
/************************************************** *********************
FUNCTION:
InitApplication
PURPOSE:
Declare the window class structure, assign values to the window class
structure members, and register the window class.
************************************************** *********************/
BOOL InitApplication (HINSTANCE hInstance)
{
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = (WNDPROC)WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hIcon = NULL;
wndclass.hInstance = hInstance;
wndclass.hCursor = NULL;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = g_szClassName;
return RegisterClass (&wndclass);
}
/************************************************** *********************
FUNCTION:
WinMain
PURPOSE:
The WinMain function of the application. It is called by the system as
the initial entry point for this Windows CE-based application.
************************************************** *********************/
int WINAPI WinMain (
HINSTANCE hInstance, // Handle to the current instance
HINSTANCE hPrevInstance, // Handle to the previous instance
LPWSTR lpCmdLine, // Pointer to the command line
int iCmdShow) // Shows the state of the window
{
MSG msg; // Message structure
HACCEL hAccel; // Handle of the accelerator
// table
// Use this code to prevent your application from starting twice
// assuming that your application has not changed its window text
if (FindWindow(g_szClassName, g_szTitle)){
SetForegroundWindow(FindWindow(g_szClassName, g_szTitle));
return FALSE;
}
if (!hPrevInstance)
{
if (!InitApplication (hInstance))
return FALSE;
}
if (!InitInstance (hInstance, iCmdShow))
return FALSE;
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Initialize the common controls and then create the progress bar.
int i;
int iSpacing; // Controls the size of the progress bar.
HWND hwndPB, h1, hC2; // Handle of progress bar.
INITCOMMONCONTROLSEX iccInit;
RECT rcClient, rcClient2; // Client area of the application window.
// Initialize the common controls.
iccInit.dwSize = sizeof(iccInit);
iccInit.dwICC = ICC_PROGRESS_CLASS;
InitCommonControlsEx(&iccInit);
// Create the window for the progress bar.
GetClientRect(g_hwndMain2, &rcClient2);
iSpacing = (int)(0.10 * (rcClient2.right - rcClient2.left));
GetClientRect(g_hwndMain, &rcClient);
iSpacing = (int)(0.10 * (rcClient.right - rcClient.left));
hwndPB = CreateWindowEx(0,
PROGRESS_CLASS ,
TEXT("Progess Bar"),
WS_CHILD | WS_VISIBLE ,
rcClient.left + iSpacing,
(int)((rcClient.bottom - rcClient.top)/2 - iSpacing),///2),
rcClient.right - 2 * iSpacing,
iSpacing,
g_hwndMain2,
NULL,
hInstance,
NULL);
/*h1 = CreateWindowEx(0,
PROGRESS_CLASS ,
TEXT("Progess Bar"),
WS_CHILD | WS_VISIBLE ,
rcClient.left + iSpacing,
(int)((rcClient.bottom - rcClient.top)/2 - iSpacing),///2),
rcClient.right - 2 * iSpacing,
iSpacing,
g_hwndMain,
NULL,
hInstance,
NULL);*/
hC2 = CreateWindowEx (WS_EX_CLIENTEDGE, TEXT ("edit"),
TEXT (""), WS_VISIBLE | WS_CHILD | ES_MULTILINE
|WS_VSCROLL ,//| WS_DISABLED,
0, 0, 100, 100, g_hwndMain, (HMENU)ID_COMPONTXT,
hInstance, NULL);
/*MessageBox(hwndPB,
NULL,TEXT ("Fra"), MB_OKCANCEL);*/
//Display the progress bar.
ShowWindow(g_hwndMain2, iCmdShow);
UpdateWindow(g_hwndMain2);
//Display the progress bar.
ShowWindow(g_hwndMain, iCmdShow);
UpdateWindow(g_hwndMain);
if(!h1)
{
MessageBox(g_hwndMain, TEXT("Unable to create the progress bar"),
TEXT("Progress Bar"), MB_OK);
return FALSE;
}
// Set the range and increment of the progress bar.
SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0,200));
SendMessage(hwndPB, PBM_SETSTEP, 2, 0);//MAKEWPARAM(2, 0), 0
// Send data to the progress bar to make it advance.
for(i=0 ; i < 100 ; i++)
{
SendMessage(hwndPB, PBM_STEPIT, 0, 0);
Sleep(10);
}
// Set the range and increment of the progress bar.
SendMessage(h1, PBM_SETRANGE, 0, MAKELPARAM(0,200));
SendMessage(h1, PBM_SETSTEP, 2, 0);//MAKEWPARAM(2, 0), 0
// Send data to the progress bar to make it advance.
for(i=0 ; i < 100 ; i++)
{
SendMessage(h1, PBM_STEPIT, 0, 0);
Sleep(10);
}
DestroyWindow (g_hwndMain2);
DestroyWindow (g_hwndMain);
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
// Insert code here to load the accelerator table.
// hAccel = LoadAccelerators (...);
while (GetMessage (&msg, NULL, 0, 0))
{
if (!TranslateAccelerator (
g_hwndMain, // Handle to the destination window
hAccel, // Handle to the accelerator table
&msg)) // Address of the message data
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
return msg.wParam;
}