|
Stephen Hewitt wrote: The Original Poster.
If Toxct found this OP he will definity advice you . I have found him going on advicing and shouting not to use short cuts.( even 'u' for 'you' )
I dont know what the OP decided. But I think it worked for him. May be he have to redesign the application.
|
|
|
|
|
Naveen.R wrote: But I think it worked for him.
That's one of the things which makes advising someone to use TerminateProcess so dangerous: it will seem to work initially but could introduce hard to diagnose and reproduce bugs.
Steve
|
|
|
|
|
Thank you for the information.;)
Now I think that I need to find another way to solve the problem....
I think that the better way is to use SendMessage() to send WM_CLOSE to that window.... But I'm not so expert on handles and SDK basic functions. So I'm still searching a way to get the HWND of the other process window, starting from the info getted from ShellExecute[EX]() or CreateProcess().
Can you help me?
Russell
|
|
|
|
|
_Russell_ wrote: So I'm still searching a way to get the HWND of the other process window...
See here.
"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
|
|
|
|
|
If you want to stop any application....you can write a code in batch file...using the batch file you can run or stop any application from internal or externally....
|
|
|
|
|
And what about the name of the command to stop the application? (are we both talking about MS-DOS?)
Thank you
Russell
|
|
|
|
|
Why you dont send
WM_CLOSE<c code=""> to it. <br />
<br />
<div class="ForumSig"><div style="padding: 0; margin: 0; background-color: rgba(170, 214, 255, 1); text-align: center; font-family: Arial; font-weight: bold; font-style: italic; font-size: 9pt"><br />
<div style="color: rgba(255, 255, 255, 1); width: 300px"><br />
<hr width="250" size="7">WhiteSky<hr width="220" size="7"></div></div></div>
|
|
|
|
|
I was trying to follow what Doc Lobster suggest, it was my original way to solve the problem....but I haven't understand the way to know the handle of the application window to pass it to SendMessage(...) .
Any example will be very nice. Thanks
Russell
|
|
|
|
|
That is the problem:
SHELLEXECUTEINFO ShellExecuteInfo;
ShellExecuteInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShellExecuteInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShellExecuteInfo.hwnd = NULL;
ShellExecuteInfo.lpVerb = NULL;
ShellExecuteInfo.lpFile = "notepad.exe";
ShellExecuteInfo.lpParameters = "";
ShellExecuteInfo.lpDirectory = NULL;
ShellExecuteInfo.nShow = SW_SHOW;
ShellExecuteInfo.hInstApp = NULL;
ShellExecuteEx(&ShellExecuteInfo);
Sleep(10000);
::SendMessage(ShellExecuteInfo.hwnd, WM_CLOSE, NULL, NULL);
It doesn't' work...
Russell
|
|
|
|
|
You can also use of CreateProcess it return a Handle to your program.
|
|
|
|
|
A way is when your program is running you use of FindWindow for get a handle to that window and then send wm_close with SendMessage
|
|
|
|
|
need to save my output ( dataval10,dataval20,dataval30) in a file everytime
i press a key. Right now they are being written in a file continuously.
i thik i have to use the case WM_KEYDOWN ... but not sure how to fit it in my code
& how to get the output written to a file when the button was pressed... Help will be super !!!!!!
[code]
// **********************************************************************/
/* Include files */
#include <windows.h> /* Compiler's include files's */
#include <string.h>
#include <stdio.h>
#include "..\cbw.h" /* Universal Library's include file */
#define BOARD_NUM 1 /* Number of A/D board as defined with InstaCal */
#define ADRANGE BIP10VOLTS /* A/D voltage range */
#define TIMER_NUM 1 /* Windows timer used by this program */
HWND hWndMain; /* handle for main window */
LONG FAR PASCAL MainMessageHandler (HWND, UINT, WPARAM, LPARAM);
int PASCAL
WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR CmdLine, int nCmdShow)
{
MSG msg; /* MSG structure to pass to windows proc */
WNDCLASS wndclass;
char *AppName; /* Name for the window */
cbErrHandling (PRINTALL, STOPALL); /* Set library's error handling */
CmdLine = NULL; /* Not used */
AppName = "WINCDEMO"; /* The name of this application */
if(!hPrevInstance)
{
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc= MainMessageHandler;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (hInstance, AppName);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = AppName;
wndclass.lpszClassName = AppName;
RegisterClass (&wndclass);
}
/* create application's Main window */
hWndMain = CreateWindow (AppName, /* Window class name */
"Sensor Output",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, /* Use default X, Y */
CW_USEDEFAULT, /* Use default X, Y */
GetSystemMetrics(SM_CXSIZE) * 12, /* x - fit text */
GetSystemMetrics(SM_CYSIZE) * 10, /* y - fit text */
NULL, /* Parent window's handle */
NULL, /* Default to Class Menu */
hInstance, /* Instance of window */
NULL); /* Create struct for WM_CREATE */
if (hWndMain == NULL)
{
MessageBox(NULL, "Could not create window in WinMain", NULL, MB_ICONEXCLAMATION);
return (1);
}
ShowWindow(hWndMain, nCmdShow); /* Display main window */
UpdateWindow(hWndMain);
// /* Start a 500ms timer to update display */
if(!SetTimer(hWndMain, TIMER_NUM, 50, NULL))
{
MessageBox(NULL, "Error starting Windows timer", NULL, MB_OK |
MB_ICONEXCLAMATION);
return (1);
}
while(GetMessage(&msg, NULL, 0, 0,PM_REMOVE)) /* Main message loop */
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnregisterClass (AppName, hInstance);
return (msg.wParam);
}
LONG FAR PASCAL
MainMessageHandler(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
HDC hDC; /* handle for the display device */
PAINTSTRUCT ps; /* holds PAINT information */
TEXTMETRIC tm; /* holds TEXT information */
static HRGN hRgn; /* Rectangle region Handles */
static int CharWidth, CharHeight;
static unsigned short DataVal, DataVal1, DataVal2, DataVal3;
static unsigned long DataVal0, DataVal10, DataVal20, DataVal30;
int x, y;
static char OutString[5000], *str;
// float Voltage;
static double yn,mu;
double t = 10000;
FILE *fp;
fp = fopen("Data1.txt", "a");
switch (Message) /* Windows Message Loop */
{
case WM_CREATE:
hDC = GetDC(hWndMain); /* Get the device context for window */
GetTextMetrics(hDC, &tm); /* From context, get size of font */
CharWidth = tm.tmAveCharWidth;
CharHeight = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC(hWndMain, hDC);
hRgn = CreateRectRgn(0,0, CharWidth*30, CharHeight*12);
break;
case WM_TIMER: /* All Timer Events Processed Here */
InvalidateRgn(hWndMain, hRgn, FALSE); /* Force screen update */
break;
case WM_PAINT: /* Repaint client area of window */
hDC = BeginPaint(hWndMain, &ps);
x = CharWidth * 2; /* Position cursor within window */
y = CharHeight; /* One line down and 2 chars in */
str = " Output"; /* Print title */
TextOut(hDC, x, y, str, strlen (str));
y += CharHeight; /* Print current index */
cbAIn (BOARD_NUM, 0, ADRANGE, &DataVal);
cbAIn (BOARD_NUM, 1, ADRANGE, &DataVal1);
cbAIn (BOARD_NUM, 2, ADRANGE, &DataVal2);
cbAIn (BOARD_NUM, 3, ADRANGE, &DataVal3);
mu = t / ( t + 3 );
DataVal0 = (double)mu * ( (double)DataVal - (double)DataVal0 ) + DataVal0;
y += CharHeight*2; /* Print raw data value */
sprintf (OutString,"Sensor0 = %u ", DataVal0);
TextOut(hDC, x, y, OutString, strlen (OutString));
DataVal10 = (double)mu * ( (double)DataVal1 - (double)DataVal10 ) + DataVal10;
y += CharHeight*2; /* Print raw data value */
sprintf (OutString,"Sensor1 = %u ", DataVal10);
TextOut(hDC, x, y, OutString, strlen (OutString));
DataVal20 = (double)mu * ( (double)DataVal2 - (double)DataVal20 ) + DataVal20;
y += CharHeight*2; /* Print raw data value */
sprintf (OutString,"Sensor2 = %u ", DataVal20);
TextOut(hDC, x, y, OutString, strlen (OutString));
DataVal30 = (double)mu * ( (double)DataVal3 - (double)DataVal30 ) + DataVal30;
y += CharHeight*2; /* Print raw data value */
sprintf (OutString,"Sensor3 = %u ", DataVal30);
TextOut(hDC, x, y, OutString, strlen (OutString));
fprintf(fp,"%u %u %u %u \n",DataVal0,DataVal10,DataVal20,DataVal30);
fclose(fp);
// y += CharHeight; /* Convert raw A/D to volts and print */
// cbToEngUnits (BOARD_NUM,ADRANGE,DataVal,&Voltage);
// sprintf (OutString,"Voltage = %.2f ", Voltage);
// TextOut(hDC, x, y, OutString, strlen (OutString));
SetTextAlign(hDC, TA_LEFT | TA_TOP);
EndPaint(hWndMain, &ps);
break;
case WM_CLOSE: /* Close the window */
DestroyWindow(hWnd);
if (hWnd == hWndMain)
PostQuitMessage(0); /* Send message to Quit application */
break;
default:
return (DefWindowProc(hWnd, Message, wParam, lParam));
}
return (0l);
}
[/code]
|
|
|
|
|
If you need to save it when ONE key is pressed, yes, you must use the switch (nChar) case to check if the key pressed is the one you need. Then use your code as you have it (if it works good)
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?
|
|
|
|
|
|
Sorry if you thought I was laughing or pissing you off. I will help you as long as I can.
The first thing. Your programm is writting the output to a file continuosly because you have all the code in the loop of messages in the OnPaint. So it will be executed every time the window updates.
I don't know the structure of the OnKeyDown programming all as you make, but using win32 under VC++ the function is:
afx_msg void OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags );
You can switch the UINT nChar and look which is the key pressed (VK_RETURN, VK_ESC, VK_F1, VK_DELETE...) and call the function you want or execute the code you need.
I'm not sure if you can check (according to your code) the WM_KEYDOWN and take the parameters directly there. But you can try to emulate the function of MFC and when it is called then make the other switch to select the key.
Sorry if it doesn't help you very much. But at least you have an idea to continue looking for the solution.
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?
|
|
|
|
|
what is difference between win32 application and win32 console application.
Thanks&Regards
srinivasa phani kiran konakanchi
|
|
|
|
|
In a normal win32 application, the subsystem is windows where as in a win32 console application, the subsystem is Console.
create a project of type win32 console application and a win32 normal applications. Take the link tab in the project setting. In "Project option" edit box in that tab, look for the argument "subsystem".
It will be like /subsystem:windows for normal windows application and /subsystem:CONSOLE for console application.
for more details check MSDN[^]
|
|
|
|
|
Another difference is Win32 is more GUI (Grafic User Interface) oriented as the console (old ms-dos programms), altough it is possible to draw and so on. But both of win32 have Win-APIs support.
Note: I can be wrong and need a good explanation too :P But this is what I (at least now) think/know
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?
|
|
|
|
|
Dear all,
I design a chart view to show like in the link below:
http://www.photoupload.org/image/3798.jpeg
My solution is used an array that hold all points and used MoveTo() and LineTo() funtions to draw.
But I need line is more smooth than now and I want to ask about solution to do
I try to study http://www.codeproject.com/gdi/CTGraphics.asp but I didn't understand much!
Thanks
|
|
|
|
|
You can also use GDI+ to perform anti-aliasing.
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.
|
|
|
|
|
To draw the line in the screen you need at least one pixel, other thing is the meaning in size of that pixel (according to the MAPMODE).
Take a look with CreatePen and similars, you can configure the width, and selecting the object in the DC, you will use the configuration you need/want
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, I am using the fillowing code to open the file .
but dialog box could not appear .tell me where is problem
OPENFILENAME ofn; // common dialog box structure
char szFile[260]; // buffer for file name
HWND hwnd; // owner window
HANDLE hf; // file handle
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner =(HWND)NULL;
ofn.lpstrFile = szFile;
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn)==TRUE)
hf = CreateFile(ofn.lpstrFile, GENERIC_READ,0, (LPSECURITY_ATTRIBUTES) NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,(HANDLE) NULL);
MessageBox(NULL,TEXT("Press load Button"),TEXT("DEBUG"),NULL);
Trioum
|
|
|
|
|
Whats result when run this code?
OPENFILENAME ofn;
char szFile[260];
HWND hwnd;
HANDLE hf;
ZeroMemory(&ofn, sizeof(ofn ));
ofn.lStructSize = sizeof(ofn);;
ofn.hwndOwner =m_hWnd;
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn)==TRUE)
hf = CreateFile(ofn.lpstrFile, GENERIC_READ,0, (LPSECURITY_ATTRIBUTES) NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,(HANDLE) NULL);
|
|
|
|
|
thanks I have done it
Trioum
|
|
|
|
|
You're welcome.
|
|
|
|
|