![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#51 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
I've played with sleep, but it flashes that ugly console window each time the sleep command runs (five times). Maybe I will just run a small loop, and kill some CPU processes, it isn't going to hurt anything to do it that way. The problem I am having now is getting some text to be displayed during the actuall delete/stepping part of the code. Is this possible outside of the
case WM_PAINT: Thanks, -BB98
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
|
|
#52 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 816
Rep Power: 4
![]() |
sleep shouldn't flash a console window, what function were you using?
You can cause your window to repaint straight away by calling the UpdateWindow function. This will invoke your WM_PAINT handler. Its a bit hard to know where in the code you should put this, you haven't posted any code in a week. What does you code look like now? |
|
|
|
|
|
#53 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
updated code...
/*
* A basic Win32 program that will
*
* delete any locked Advantage
*
* Screens from the local system.
*/
#include <windows.h>
#include <string.h>
#include <iostream>
#include <commctrl.h>
#include <cstdlib>
int Result;
// This is the window function for the main window. Whenever a message is
// dispatched using DispatchMessage (or sent with SendMessage) this function
// gets called with the contents of the message.
LRESULT CALLBACK
MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
// The window handle for buttons.
static HWND hwndfinish = 0;
static int cx, cy;// Height and width of Finish button.
static HWND hwndrcvr = 0;
static int rx, ry;// Height and width of Recover button.
static HWND hwndPB;
HDC hdc;// A device context used for drawing
PAINTSTRUCT ps;// Also used during window drawing
RECT rc;// A rectangle used during drawing
// Perform processing based on what kind of message we got.
InitCommonControls();
switch (nMsg)
{
case WM_CREATE:
{
// The window is being created. Create our button
// window now.
TEXTMETRIC tm;
// Use the system fixed font size to choosea nice button size.
hdc = GetDC (hwnd);
SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
GetTextMetrics (hdc, &tm);
cx = tm.tmAveCharWidth * 15;
cy = (tm.tmHeight + tm.tmExternalLeading) * 2;
rx = tm.tmAveCharWidth * 25;
ry = (tm.tmHeight + tm.tmExternalLeading) * 2;
ReleaseDC (hwnd, hdc);
// Now create the button
hwndfinish = CreateWindow (
"button", // Builtin button class
"- Finish -",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
325, 450, cx, cy,
hwnd, // Parent is this window.
(HMENU) 1, // Control ID: 1
((LPCREATESTRUCT) lParam)->hInstance,
NULL);
//Now create the button
hwndrcvr = CreateWindow (
"button", // Builtin button class
"Start Recovery",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
280, 160, rx, ry,
hwnd, // Parent is this window.
(HMENU) 2, // Control ID: 2
((LPCREATESTRUCT) lParam)->hInstance,
NULL);
// Create Progress Bar
SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
SendMessage(hwndPB, PBM_SETSTEP, (WPARAM) 20, 0);
hwndPB = CreateWindowEx(
0,
PROGRESS_CLASS, // class name
(LPSTR) NULL,
WS_CHILD | WS_VISIBLE, // Style
50, // Initial x
400, // Initial y
660, // Initial x size
20, // Initial y size
hwnd, // Parent is this window.
(HMENU) 0,
((LPCREATESTRUCT) lParam)->hInstance,// this program instance
NULL // creation parameters
);
return 0;
break;
}
case WM_DESTROY:
// The window is being destroyed, close the application
// (the child button gets destroyed automatically).
PostQuitMessage (0);
return 0;
break;
case WM_PAINT:
// The window needs to be painted (redrawn).
hdc = BeginPaint (hwnd, &ps);
GetClientRect (hwnd, &rc);
// Draw directions at top of screen
SetTextColor(hdc, RGB(200,220,255)); SetBkColor(hdc, RGB(125,125,125));
rc.top = rc.top + 5;
DrawText (hdc, "-=| Advantage Screen Recovery |=-", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
SetTextColor(hdc, RGB(255,255,255)); SetBkColor(hdc, RGB(125,125,125));
rc.top = rc.top + 18;
DrawText (hdc, "If you are getting a warning message saying your printers are not configured", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
rc.top = rc.top + 18;
DrawText (hdc, "for this workstation, please run this program now. Also you should run it if", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
rc.top = rc.top + 18;
DrawText (hdc, "your first Advantage window to open is anything other than ABCS1.", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
rc.top = rc.top + 25;
SetTextColor(hdc, RGB(255,0,0)); SetBkColor(hdc, RGB(0,0,0));
DrawText (hdc, "**NOTICE** Close all Advantage windows before continuing!**", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
rc.top = rc.top + 15;
DrawText (hdc, "If not, unexpected behavior may result.", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
SetTextColor(hdc, RGB(255,255,255)); SetBkColor(hdc, RGB(125,125,125));
rc.top = rc.top + 25;
DrawText (hdc, "To Continue, click the Start Recovery button.", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
EndPaint (hwnd, &ps);
return 0;
break;
case WM_COMMAND:
// Check the control ID, notification code and
// control handle to see if this is a button click
// message from the child button.
if (LOWORD(wParam) == 1 &&
HIWORD(wParam) == BN_CLICKED &&
(HWND) lParam == hwndfinish)
{
// Finish button was clicked. Close the window.
DestroyWindow (hwnd);
}
else
{
if (LOWORD(wParam) == 2 &&
HIWORD(wParam) == BN_CLICKED &&
(HWND) lParam == hwndrcvr)
{
// Recover button was clicked. Delete files and step progress bar.
SetTextColor(hdc, RGB(255,255,255)); SetBkColor(hdc, RGB(125,125,125));
GetClientRect (hwnd, &rc);
int time;
/********************************************************/
if( remove( "C:\\AdWin\\scr1" ) == -1 )
{
rc.top = rc.top + 300;
DrawText(hdc, "Screen 1 was not locked.", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
SendMessage(hwndPB, PBM_DELTAPOS, 20, 0); //step progress bar
for(time = 100000000; time > 0;time --); //pause program
}
else
{
rc.top = rc.top + 300;
DrawText(hdc, "Screen 1 was Successfully Recovered.", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
SendMessage(hwndPB, PBM_DELTAPOS, 20, 0); //step progress bar
for(time = 100000000; time > 0;time --); //pause program
}
/********************************************************/
if( remove( "C:\\AdWin\\scr2" ) == -1 )
{
rc.top = rc.top + 20;
DrawText(hdc, "Screen 2 was not locked.", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
SendMessage(hwndPB, PBM_DELTAPOS, 20, 0); //step progress bar
for(time = 100000000; time > 0;time --); //pause program
}
else
{
rc.top = rc.top + 20;
DrawText(hdc, "Screen 2 was Successfully Recovered.", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
SendMessage(hwndPB, PBM_DELTAPOS, 20, 0); //step progress bar
for(time = 100000000; time > 0;time --); //pause program
}
/********************************************************/
if( remove( "C:\\AdWin\\scr3" ) == -1 )
{
rc.top = rc.top + 20;
DrawText(hdc, "Screen 3 was not locked.", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
SendMessage(hwndPB, PBM_DELTAPOS, 20, 0); //step progress bar
for(time = 100000000; time > 0;time --); //pause program
}
else
{
rc.top = rc.top + 20;
DrawText(hdc, "Screen 3 was Successfully Recovered.", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
SendMessage(hwndPB, PBM_DELTAPOS, 20, 0); //step progress bar
for(time = 100000000; time > 0;time --); //pause program
}
/********************************************************/
if( remove( "C:\\AdWin\\scr4" ) == -1 )
{
rc.top = rc.top + 20;
DrawText(hdc, "Screen 4 was not locked.", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
SendMessage(hwndPB, PBM_DELTAPOS, 20, 0); //step progress bar
for(time = 100000000; time > 0;time --); //pause program
}
else
{
rc.top = rc.top + 20;
DrawText(hdc, "Screen 4 was Successfully Recovered.", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
SendMessage(hwndPB, PBM_DELTAPOS, 20, 0); //step progress bar
for(time = 100000000; time > 0;time --); //pause program
}
/********************************************************/
if( remove( "C:\\AdWin\\scr5" ) == -1 )
{
rc.top = rc.top + 20;
DrawText(hdc, "Screen 5 was not locked.", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
SendMessage(hwndPB, PBM_DELTAPOS, 20, 0); //step progress bar
for(time = 100000000; time > 0;time --); //pause program
}
else
{
rc.top = rc.top + 20;
DrawText(hdc, "Screen 5 was Successfully Recovered.", -1, &rc,
DT_SINGLELINE | DT_CENTER | DT_TOP);
SendMessage(hwndPB, PBM_DELTAPOS, 20, 0); //step progress bar
for(time = 100000000; time > 0;time --); //pause program
}
/********************************************************/
}
return 0;
break;
}
}
// If can't handle a message completely, hand it to the system
// provided default window function.
return DefWindowProc (hwnd, nMsg, wParam, lParam);
}
int STDCALL
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
HWND hwndMain; // Handle for the main window.
MSG msg; // A Win32 message structure.
WNDCLASSEX wndclass; // A window class structure.
char*szMainWndClass = "WinTestWin"; // The name of the main window class
// First, create a window class for our main window.
// Initialize the entire structure to zero.
memset (&wndclass, 0, sizeof(WNDCLASSEX));
// This class is called WinTestWin
wndclass.lpszClassName = szMainWndClass;
// cbSize gives the size of the structure for extensibility.
wndclass.cbSize = sizeof(WNDCLASSEX);
// All windows of this class redraw when resized.
wndclass.style = CS_HREDRAW | CS_VREDRAW;
// All windows of this class use the MainWndProc window function.
wndclass.lpfnWndProc = MainWndProc;
// This class is used with the current program instance.
wndclass.hInstance = hInst;
// Use standard application icon and arrow cursor provided by the OS
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
// Color the background gray
wndclass.hbrBackground = (HBRUSH) GetStockObject (GRAY_BRUSH);
// Now register the window class for use.
RegisterClassEx (&wndclass);
// Create our main window using that window class.
hwndMain = CreateWindow (
szMainWndClass, // Class name
"Advantage Screen Recovery 3.0", // Caption
WS_OVERLAPPEDWINDOW, // Style
CW_USEDEFAULT, // Initial x (use default)
CW_USEDEFAULT, // Initial y (use default)
770, // Initial x size (use default)
525, // Initial y size (use default)
NULL, // No parent window
NULL, // No menu
hInst, // This program instance
NULL // Creation parameters
);
// Display the window which was just created.
ShowWindow (hwndMain, nShow);
UpdateWindow (hwndMain);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
__________________
Learning to use C++ and loving every minute of it. |
|
|
|
|
|
#54 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 816
Rep Power: 4
![]() |
Here are some problems:
1. I hope that the posting swalllowed your indenting and your program doesn't actually look like that 2. The code SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
SendMessage(hwndPB, PBM_SETSTEP, (WPARAM) 20, 0);3. In your WM_COMMAND section you are using an hdc that hasn't been set yet. Note that the hdc variable is used and set in the WM_PAINT case, but this is during a different call of your MainWndProc (your MainWndProc is called anew for each message). This means you are trying to draw lines on an uninitialised DC which at best will do nothing, at worst will crash your program (or your machine). I added hdc = GetDC(hwnd); ReleaseDC(hwnd, hdc); 4. Instead of your timing loops use Sleep(1000); As a side note, you might find it easier if you split up your MainWndProc into separate functions and called them from a simple case statement. This would make it more obvious that the different message handlers can't share variables unless they are global. |
|
|
|
|
|
#55 |
|
Professional Programmer
|
Just wondering, what is Advantage?
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
#56 |
|
Hobbyist Programmer
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4
![]() |
The Dark, I greatly appreciate your help. You have been a tremendious help to me. The progress bar does work properly. Thanks for the sleep command, for some reason before when I tried it, I got a compiler error, maybe I typed it wrong...
prm753, Advantage is out Point of Sale system. Thanks to everyone that posted. Program is finished and working properly. -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 | |
|
|