ShowWindow alternatives

2.1k views Asked by At

Obviously I can't terminate a given process, when its main window is hidden ("minimized to tray"). So I tried showing the window again in the other processes' FormClosing handler. Didn't work either.

Now I want to use ShowWindow

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

which unfortunately yields

error LNK2028: Nicht aufgelöstes Token (0A000072) ""extern "C" int __stdcall ShowWindow(struct HWND__ *,int)" (?ShowWindow@@$$J18YGHPAUHWND__@@H@Z)", auf das in Funktion ""private: void __clrcall lidarctrl::Form1::Form1_FormClosing(class System::Object ^,class System::Windows::Forms::FormClosingEventArgs ^)" (?Form1_FormClosing@Form1@lidarctrl@@$$FA$AAMXP$AAVObject@System@@P$AAVFormClosingEventArgs@Forms@Windows@4@@Z)" verwiesen wird.
error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""extern "C" int __stdcall ShowWindow(struct HWND__ *,int)" (?ShowWindow@@$$J18YGHPAUHWND__@@H@Z)" in Funktion ""private: void __clrcall lidarctrl::Form1::Form1_FormClosing(class System::Object ^,class System::Windows::Forms::FormClosingEventArgs ^)" (?Form1_FormClosing@Form1@lidarctrl@@$$FA$AAMXP$AAVObject@System@@P$AAVFormClosingEventArgs@Forms@Windows@4@@Z)".

Sorry - German errors; don't know how to change the compiler's locale.

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

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

I appreciate any hints on which header to include, library to load.

I am using Microsoft Visual C++ 2010 Express; the project is a plain Windows Forms Application.

Thank you!

2

There are 2 answers

0
Roman Ryltsov On

In a project created from standard Windows Forms Application template, there are no standard/default libraries linked that are normally included on native projects. And you need to add them explicitly, in project settings or in code. Where you include <windows.h>, add #pragma as shown below:

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

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

This will link your missing ShowWindow.

1
MSalters On

You're probably not using C++ and Win32. Then you would write

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