|
sulabh_expert@rediffmail.com wrote: error C2065: 'IDD_MONITORVW' : undeclared identifier
Hope IDD_MONITORVW is your CFormView drived class resource ID.
If so, make sure u included 'Resource.h' before you include the class header file of CFormView derived class
Do your Duty and Don't expect the Result
|
|
|
|
|
Hi all,
How can I intercept the close event of a console window?
Many thanx
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r My Blog: ^_^
|
|
|
|
|
use this
<br />
int main()<br />
{<br />
<br />
<br />
getchar();
return 0;<br />
}<br />
the window dont close until you push 'Enter'.
|
|
|
|
|
|
try this:
<br />
#include <stdio.h><br />
<br />
#include <Windows.h.>
<br />
void main( void )<br />
{ <br />
char buffer[81]; <br />
int i, ch; <br />
<br />
printf( "Enter a line: " ); <br />
<br />
for( i = 0; (i < 80) && ((ch = getchar()) != EOF) && (ch != '\n'); i++ )<br />
buffer[i] = (char)ch; <br />
buffer[i] = '\0'; <br />
printf( "%s\n", buffer );<br />
<br />
Sleep(7000);<br />
}<br />
if you wont to hold infinite time write Sleep(INFINITE);
to see more search Sleep in MSDN.
|
|
|
|
|
|
|
I think he develops a console application and wants to be 'notified' in some way when the user clicks on the close button of this console window.
|
|
|
|
|
You are probably right, since he hasn't answered my post.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
This code leaks HANDLE s: the hProcess and hThread members of the PROCESS_INFORMATION structure need to be closed with CloseHandle if the call to CreateProcess succeeds (and you don't want to use them). Closing the HANDLE s will not close the process. Also your wait is a busy wait; this is a bad thing in a multitasking OS. You should use the WaitForSingleObject API instead. Try code like this:
#include "stdafx.h"
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
STARTUPINFO si = {0};
si.cb = sizeof(si);
PROCESS_INFORMATION pi;
BOOL bOK = CreateProcess(
"C:\\Windows\\Notepad.exe",
NULL,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi
);
if (bOK)
{
CloseHandle(pi.hThread);
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
MessageBox(NULL, "Notepad has closed", NULL, MB_OK);
}
return 0;
}
This will launch notepad (if you installed windows to "C:\") and wait for it to finish without spinning in a loop and wasting CPU cycles. It will not leak any HANDLE s.
Steve
|
|
|
|
|
You need to use the SetConsoleCtrlHandler API.
Steve
|
|
|
|
|
|
Use HandlerRoutine and SetConsoleCtrlHandler .
Following is example from MSDN ,
#include <windows.h>
#include <stdio.h>
BOOL CtrlHandler( DWORD fdwCtrlType )
{
switch( fdwCtrlType )
{
case CTRL_C_EVENT:
printf( "Ctrl-C event\n\n" );
Beep( 750, 300 );
return( TRUE );
case CTRL_CLOSE_EVENT:
Beep( 600, 200 );
printf( "Ctrl-Close event\n\n" );
return( TRUE );
case CTRL_BREAK_EVENT:
Beep( 900, 200 );
printf( "Ctrl-Break event\n\n" );
return FALSE;
case CTRL_LOGOFF_EVENT:
Beep( 1000, 200 );
printf( "Ctrl-Logoff event\n\n" );
return FALSE;
case CTRL_SHUTDOWN_EVENT:
Beep( 750, 500 );
printf( "Ctrl-Shutdown event\n\n" );
return FALSE;
default:
return FALSE;
}
}
void main( void )
{
if( SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE ) )
{
printf( "\nThe Control Handler is installed.\n" );
printf( "\n -- Now try pressing Ctrl+C or Ctrl+Break, or" );
printf( "\n try logging off or closing the console...\n" );
printf( "\n(...waiting in a loop for events...)\n\n" );
while( 1 ){ }
}
else
printf( "\nERROR: Could not set control handler");
}
|
|
|
|
|
There is a caveat that should be mentioned here; the CtrlHandler callback is executed in a different thread. That means that if you're calling CRT function from both threads (like printf ) the multithreaded CRT library should be used, for example. Synchronisation primitives may also be needed in some cases.
Steve
|
|
|
|
|
Yes, true. Its just a demontration from MSDN , need to consider threading issue while actual coding.
|
|
|
|
|
|
Programm3r wrote: and the code snippet
Mention not. Its from MSDN . I find it while looking for these functions.
|
|
|
|
|
hi
I have pencile cursor in my application.
I want to bottom-left corner of cursor to point current point in my window.
how can i do this?
Thanks,
Rushiraj
|
|
|
|
|
rushiraj.jhala wrote: I want to bottom-left corner of cursor to point current point in my window.
Can u be more clear please?
If you want to change the mouse cursor, then handle WM_SETCURSOR message
Do your Duty and Don't expect the Result
|
|
|
|
|
Hi,
I have change my cursor with SETCURSOR but In normal case where top left corner of cursor
gives you the position of cursor in your application window (where your cursor points e.g.(100,100)).
In This case i have pencil cursor so i want it to give me point where niddle of my pencil tool points not the top-left corner of my pencile tool.
You can see in any drawing application suppose in mspaint when you have rectange tool selected it starts deawing form top left corner of cursor but when you have pencile tool it will not set pixel at top left corner but the point wher niddle of pencil tool points.
Thanks,
Rushiraj
|
|
|
|
|
Probably you need to change the hot spot in your cursor to whatever point that you want. You can do this using the resource editor.
I hope this helps
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
hi,
ya thats what i want.
Thanks a lot.
Rushiraj.
|
|
|
|
|
Did u find out solution?..
I didn't know where to set the hot spot in resource editor...
If anybody knows, pls reply...
Do your Duty and Don't expect the Result
|
|
|
|
|
You can go to the resource view and then open the cursor file. Check for the hot spot option in the toolbar and select it and point to some location in the cursor design file. The next time you run the application the hot spot would be the point that you set. For example in windows the hot spot is the top point of the arrow cursor
Rate this message if it helps...
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
yeah its really helped me...
I didn't know abt this tool..
Do your Duty and Don't expect the Result
|
|
|
|