|
take a look:
<br />
#include <stdio.h><br />
#include <windows.h> <br />
#pragma comment(lib, "user32.lib")<br />
<br />
HINSTANCE hInst; <br />
TCHAR szTitle[] = "timer sample"; <br />
TCHAR szWindowClass[] = "timersampleapp"; <br />
int nCountDown = 0;<br />
<br />
<br />
BOOL InitInstance(HINSTANCE, int); <br />
void ErrorExit(LPTSTR lpszFunction); <br />
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); <br />
<br />
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) <br />
{ <br />
UNREFERENCED_PARAMETER(hPrevInstance); <br />
UNREFERENCED_PARAMETER(lpCmdLine); <br />
<br />
MSG msg; <br />
WNDCLASSEX wcex; <br />
<br />
wcex.cbSize = sizeof(WNDCLASSEX); <br />
wcex.style = CS_HREDRAW | CS_VREDRAW; <br />
wcex.lpfnWndProc = WndProc; <br />
wcex.cbClsExtra = 0; <br />
wcex.cbWndExtra = 0; <br />
wcex.hInstance = hInstance; <br />
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION); <br />
wcex.hCursor = LoadCursor(NULL, IDC_ARROW); <br />
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); <br />
wcex.lpszMenuName = NULL; <br />
wcex.lpszClassName = szWindowClass; <br />
wcex.hIconSm = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(5), IMAGE_ICON, <br />
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR); <br />
<br />
if (RegisterClassEx(&wcex) == 0) <br />
{ <br />
ErrorExit("RegisterClassEx"); <br />
return FALSE; <br />
} <br />
<br />
<br />
if (!InitInstance (hInstance, nCmdShow)) <br />
{ <br />
ErrorExit("InitInstance"); <br />
return FALSE; <br />
} <br />
<br />
while (GetMessage(&msg, NULL, 0, 0)) <br />
{ <br />
TranslateMessage(&msg); <br />
DispatchMessage(&msg); <br />
} <br />
<br />
return (int) msg.wParam; <br />
} <br />
<br />
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) <br />
{ <br />
HWND hWnd; <br />
hInst = hInstance; <br />
<br />
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, <br />
CW_USEDEFAULT, 0, 640, 480, NULL, NULL, hInstance, NULL); <br />
<br />
if (!hWnd) <br />
{ <br />
return FALSE; <br />
} <br />
<br />
nCountDown = 60;<br />
SetTimer(hWnd, 1, 1000, (TIMERPROC) NULL);<br />
<br />
ShowWindow(hWnd, nCmdShow); <br />
UpdateWindow(hWnd); <br />
<br />
return TRUE; <br />
} <br />
<br />
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) <br />
{ <br />
PAINTSTRUCT ps; <br />
HDC hdc; <br />
<br />
switch (message) <br />
{ <br />
case WM_TIMER:<br />
<br />
--nCountDown;<br />
if(nCountDown == 0) <br />
KillTimer(hWnd, 1);<br />
else<br />
{<br />
TCHAR msg[20] = {0};<br />
sprintf(msg, "%d", nCountDown);<br />
SetWindowText(hWnd, msg);<br />
}<br />
<br />
break;<br />
case WM_PAINT: <br />
hdc = BeginPaint(hWnd, &ps); <br />
EndPaint(hWnd, &ps); <br />
break; <br />
case WM_DESTROY: <br />
PostQuitMessage(0); <br />
break; <br />
default: <br />
return DefWindowProc(hWnd, message, wParam, lParam); <br />
} <br />
return 0; <br />
} <br />
<br />
void ErrorExit(LPTSTR lpszFunction) <br />
{ <br />
TCHAR szBuf[80]; <br />
LPVOID lpMsgBuf; <br />
DWORD dw = GetLastError(); <br />
<br />
FormatMessage( <br />
FORMAT_MESSAGE_ALLOCATE_BUFFER | <br />
FORMAT_MESSAGE_FROM_SYSTEM, <br />
NULL, <br />
dw, <br />
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), <br />
(LPTSTR) &lpMsgBuf, <br />
0, NULL ); <br />
<br />
wsprintf(szBuf, <br />
"%s failed with error %d: %s", <br />
lpszFunction, dw, lpMsgBuf); <br />
<br />
MessageBox(NULL, szBuf, "Error", MB_OK); <br />
LocalFree(lpMsgBuf); <br />
} <br />
|
|
|
|
|
This is not the recommended way of doing a countdown using timers. The correct approach is to use the current time to do the countdown.
For instance when the countdown should start the current time is: 04:00:00.
If you want a 1 minute countdown you set the End time to 04:01:00.
Then you set up a timer with the interval set to 1000ms. In the WM_TIMER handler you get the current time and calculates the time remaining.
The reason that it is wrong to decrement by 1 sec each time the WM_TIMER handler get called is that there is no guarantee that the handler will be handled after 1sec. Only guarantee is that it will not happen before 1 sec. Might not be that big deal in this case, but it is good habbit to do it correct way!
|
|
|
|
|
i have two modes in my application - ONLINE, OFFLINE
WHen i run my program in DEBUG MODE and change my application from ONLINE to OFFLINE mode i get an error-
" THE EXCEPTION BREAKPOINT"
ABreak point has been reached.
(0x80000003) occured in the application at location 0x7c901230
But when running in RELEASE MODE , its running fine..
why is it so
Proud To Be an Indian
|
|
|
|
|
vivekphlp wrote: ABreak point has been reached.
And what does call stack tell you ?
Prasad
MS MVP - VC++
|
|
|
|
|
What happens when you set a breakpoint in the routine that handles the changing from ONLINE to OFFLINE, and single-step from that point?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
THe stack says - NTDLL! 7c901230() here the error comes
When i put breakpoint it comes to a function call and then a error msg pops out User Exception at xxxxxxx.
Proud To Be an Indian
|
|
|
|
|
vivekphlp wrote: When i put breakpoint it comes to a function call and then a error msg pops out User Exception at xxxxxxx.
So are you going to tell us what that function call is?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
its a user defined function ....
Proud To Be an Indian
|
|
|
|
|
hi,everyone
I'm failed to install vc6.0
an error occured while I'm installing vc6.0:
error messagebox title: error while configuring ODBC drivers
error information: odbc's sqlInstallDriverManager failed.
who help me?
|
|
|
|
|
If you do not need that specific driver, just opt to not install it.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks for your help,but I need it.
It seems no solution to this problem...
Finally I had to reinstall windows...
|
|
|
|
|
aren372 wrote: Finally I had to reinstall windows...
So you're up and running then?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Hi All
i have to create a service and this service should run for evry user on a work station but there must be one user who will stop this serice apart from admin(At first time only admin of the system can use this service and once i assign a normal user as admin of this service this then only this can start and stop this service)..
i am using createservice to creat a service. can i have some idea how will i achive this requirment
Thanks in advance
RYK
|
|
|
|
|
What about?
if (!bAdminRights)
return;
//...the function itselfs
at the beggining of every function that should be called only with admin permissions.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
|
|
|
|
|
Hi, everyone!
I meet a strange problem. The application I'm developing has a parent window and a popup dialog. I wrote a class encapsulate a SOCKET and declare a varriable of it in the parent window. When some data were received, a message will be sent to parent window. Then when the dialog is popupped, I use a pointer of the class and let it point to the varriable in the parent class. After that, I assign the dialog's HWND to the class. So the message will be sent to the dialog as I think. But the fact is the class can't work when the dialog displayed at all! I think declareing a new varriable will cost too many CPU's time because the class generate a new thread. So I hope someone could be kind to tell me how to resolve this problem without declare a new varriable. Thanks!
|
|
|
|
|
Hi Pal,
Seems very difficult to understand the problem you are facing... please describe more clearly.
Regards,
Jijo.
________________________________
Yesterday is history,
Tomorrow is a mystery,
But today is a present.
|
|
|
|
|
The essential of my problem is that what time is approprate to assign a handle of a dialog to a varriable. In InitDialog() or in WM_CREATE processing function? If the time is wrong, the message can't be received.
|
|
|
|
|
whiteclouds wrote: When some data were received, a message will be sent to parent window
By who?
whiteclouds wrote: But the fact is the class can't work when the dialog displayed at all!
Is this a modal dialog?
whiteclouds wrote: I think declareing a new varriable will cost too many CPU's time because the class generate a new thread.
??? Who/what/where/why is another thread being created?
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Maybe I can resolve this problem by other way. If I success, I'll tell everyone answered.
|
|
|
|
|
Hi guys, I have the second question about template. I encountered it during my studying.
for example, I have a template class both in .h & .cpp files as follow:
1:
2: template < class T >
3: class TTEST
4: {
5: public:
6: struct TS
7: {
8: int i ;
9: } ;
10: public:
11: TS* test1() ;
12: } ;
13:
14: #include "a.h"
15: template < class T >
16: TS* TTEST < T >::test1()
17: {
18: return NULL;
19: }
But I got a compiler error at line 16 while building it. I know there is something wrong with the " TS* ", but I don't know how to fix it. Could an y one help me ? thx !
|
|
|
|
|
Try to replace the function definition (.cpp file) with:
template < class T >
TTEST < T >::TS * TTEST < T >::test1()
{
return NULL;
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Hi, CPallini. I have tried this way before, and failed with a similar error, in vc.
|
|
|
|
|
Strange, it works fine on my system (VS6).
Are you sure the sintax was the same?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Yuwen Zhou wrote: I have tried this way before, and failed with a similar error, in vc.
Then you must've made a type-o. Simply qualifying TS is all that's needed.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|