2012-10-16 44 views
0

很顯然,當主窗口隱藏時(「最小化爲托盤」),我無法終止給定的進程。所以我嘗試在其他進程的FormClosing處理程序中再次顯示窗口。也沒有工作。ShowWindow alternatives

現在我想使用的ShowWindow

IntPtr Handle = Gateway->MainWindowHandle; 
ShowWindow((HWND)Handle.ToPointer(), SW_SHOWDEFAULT); 

不幸產生

error LNK2028: Nicht aufgelöstes Token (0A000072) ""extern "C" int __stdcall ShowWindow(struct HWND__ *,int)" ([email protected]@[email protected]@[email protected])", auf das in Funktion ""private: void __clrcall lidarctrl::Form1::Form1_FormClosing(class System::Object ^,class System::Windows::Forms::FormClosingEventArgs ^)" ([email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@@Z)" verwiesen wird. 
error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" int __stdcall ShowWindow(struct HWND__ *,int)" ([email protected]@[email protected]@[email protected])" in Funktion ""private: void __clrcall lidarctrl::Form1::Form1_FormClosing(class System::Object ^,class System::Windows::Forms::FormClosingEventArgs ^)" ([email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@@Z)". 

對不起 - 德國的錯誤;不知道如何改變編譯器的語言環境。

Non resolved Token...in function...referenced by...

Reference to non-resolved extern symbol...in function...

我明白任何提示在其頭部以包括,庫加載。

我正在使用Microsoft Visual C++ 2010 Express;該項目是一個普通的Windows窗體應用程序。

謝謝!

+1

您可以使用隱藏/最小化/任何其他窗口終止進程。也許你需要從解釋什麼阻止你這樣做開始。 –

+0

同意Roman;只需發送一個「WM_CLOSE」消息給隱藏的應用程序。 – MSalters

+0

我正在使用'GetProcessesByName'來獲取我的其他進程(_gateway_)。 '網關 - > CloseMainWindow(); Gateway-> WaitForExit(100);'只有當主窗口可見時才殺死它。否則,另一個進程只是繼續運行。 –

回答

0

您可能沒有使用C++和Win32。然後你會寫

#include <windows.h> 
//... 
{ 
    //... 
    HWND Handle = Gateway->MainWindowHandle; // Gateway probably is your class. 
    ShowWindow(Handle, SW_SHOWDEFAULT); 
} 
+0

就像我說的,這是一個Microsoft Visual C++ 2010 Express Windows窗體應用程序項目。如果我沒有弄錯,那應該是C++/CLI。 (仍是C++ noob。)所以ShowWindow是一個Win32函數;問題是如何在我的項目中使用它,這不是香草Win32。 –

1

在從標準的Windows創建的項目窗體應用程序模板,但是也有一些通常包括在本地項目鏈接沒有標準/默認庫。你需要在項目設置或代碼中明確地添加它們。當你包括<windows.h>,如下圖所示添加#pragma

#define WIN32_LEAN_AND_MEAN 
#include <windows.h> 

#pragma comment(lib, "user32.lib") // <<--- Add Me 

這會將你失蹤ShowWindow