hi i want to know how to find wether one particular exe is running or not.if it running how to kill that exe in win32 application. please help me to do this.
i used that but it is not working properly.is their any other way to do the same.what i done is finding the window if it exsist just destroy the window but it is not working.give me the solution for this please.
what i done is in main i just created one window.and then in main i am calling the one procedure in that procedure in paint case i am scrolling some text in the banner.what i want is if first time i run the code the banner should display next time if i give different arguments the old instance should be deleted or the new value whatever i pass in the command line should be updated in the same banner.i think it is working correctly .in main it is creating window and in the procedure it is just finding the window and destroying.bat what i need is first time when i run it should display the window and next time when i execute the same code it should find wether the window exist or not if the window is their just close or destroy the window and create the new window. code is like this Code: INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { //string1.Format("%-0s",lpCmdLine); MSG Msg; WndCls.cbSize = sizeof(WndCls); WndCls.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW; WndCls.lpfnWndProc = WindProcedure; WndCls.cbClsExtra = 0; WndCls.cbWndExtra = 0; WndCls.hInstance = hInstance; WndCls.hIcon = LoadIcon(NULL, IDI_APPLICATION); WndCls.hCursor = LoadCursor(NULL, IDC_ARROW); WndCls.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); WndCls.lpszMenuName = NULL; WndCls.lpszClassName = szAppName; WndCls.hIconSm = LoadIcon(hInstance, IDI_APPLICATION); RegisterClassEx(&WndCls); CreateWindowEx(WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST | WS_EX_NOACTIVATE | WS_EX_TRANSPARENT, szAppName, "GDI Accessories and Tools", WS_POPUPWINDOW | WS_VISIBLE, 0, 720, 1500, 20, hwnd, NULL, hInstance, NULL); } if (g_SingleInstanceObj.IsAnotherInstanceRunning()) { exit (1); } while( GetMessage(&Msg, NULL, 0, 0) ) { TranslateMessage(&Msg); DispatchMessage( &Msg); } return static_cast<int>(Msg.wParam); } LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { HDC hDC; PAINTSTRUCT Ps; int a; switch(Msg) { case WM_PAINT: szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); if( NULL == szArglist ) { wprintf(L"CommandLineToArgvW failed\n"); return 0; } if(FindWindow(szAppName,"GDI Accessories and Tools")!=NULL) { AfxMessageBox("The"); CloseWindow(hWnd); DestroyWindow(hWnd); } ifstream myfile7; myfile7.open ("C:\\cmd.txt"); //sText="EOD has not been started yet"; if(myfile7.is_open()) { while (! myfile7.eof() ) { string pline=""; getline (myfile7,pline); pre_lines+=(pline+"\n"); } } myfile7.close(); for( i=1; i<nArgs; i++) { string1=(CString)szArglist[i]; /* if ((CString)szArglist[i]=="0") { string2=string2-(CString)szArglist[i-1]; } else*/ string2=string2+" "+string1; /*if((CString)szArglist[2]=="0" && (CString)szArglist[4]=="0") { exit(1); }*/ } CString str=pre_lines.c_str(); string3=str+" "+string2; ofstream myfile4; myfile4.open("C:\\banner.txt"); if (myfile4.is_open()) { myfile4 << string(string2); } myfile4.close(); do { hDC = BeginPaint(hWnd, &Ps); //TextOut(hDC, 10, 1,"Priority 1 Incidents:",21); /* Color(11000000); SolidBrush( Color &color ); Graphics* g = button1->CreateGraphics(); Pen* myPen = new Pen(Color::Red); myPen->Width = 5;*/ for(a=1;a<1000;a++) { TextOut(hDC, 10, 1,"Priority 1 Incidents:",21); TextOut(hDC, a+150, 1,string2,string2.GetLength()); //g->DrawLine(myPen, 1, 1, 45, 65); EndPaint(hWnd, &Ps); Sleep(10); //how fast the text should scroll } }while(!NULL); break; } case WM_DESTROY: PostQuitMessage(WM_QUIT); break; default: return DefWindowProc(hWnd, Msg, wParam, lParam); } return 0; }
Just don't put all your code and say I have done this. Have the code which is relevant. Also learn to use the code block when you have code in the posts.
ok . sorry for the mistake. what i done is in main i just created one window.and then in main i am calling the one procedure in that procedure in paint case i am scrolling some text in the banner.what i want is if first time i run the code the banner should display next time if i give different arguments the old instance should be deleted or the new value whatever i pass in the command line should be updated in the same banner.i think it is working correctly .in main it is creating window and in the procedure it is just finding the window and destroying.bat what i need is first time when i run it should display the window and next time when i execute the same code it should find wether the window exist or not if the window is their just close or destroy the window and create the new window. Code: LRESULT CALLBACK WindProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { switch(Msg) { case WM_PAINT: if(FindWindow(szAppName,"GDI Accessories and Tools")!=NULL) { AfxMessageBox("The"); CloseWindow(hWnd); DestroyWindow(hWnd); } ..................... }
You have made big mistake. You have not used the hWnd returned by the FindWindow but have used the hWnd of the current application. Also you don't need to be doing that in WM_PAINT and I have told that before as well how to do this using some message like send a user message to the new exe where it kills itself.
thanks shabbir.i corrected the code.but now while executing the old window is not at all closing i mean to say the new value whatever i am passing is not updating in the diffrent window.i coded just like this.is it ok if i do like this.please give the solution for this as early as possible. Code: Hwnd = FindWindow("GDISuite","GDI Accessories and Tools"); if(Hwnd!= NULL) { UpdateWindow(hwnd); //stroyWindow(Hwnd); //xMessageBox("Window Destryoed"); //CloseWindow(hwnd); //ExitProcess(0); }