I am trying to write a simple CLR-Windows Form Application. It will show a window having a button. As soon as you click the button, it will hide one of the open Windows. To achieve this I am calling ShowWindow(00050214, false );, where 00050214 is the handle of the Window I am hiding.
But it is giving error:
Error 1 error C3861: 'ShowWindow': identifier not found c:\users\afnan
\documents \visual studio 2010\projects\winformtest\winformtest\Form1.h 80
Please see the last lines of .h file given below, to see how I am using the above function.
WinformTest.cpp : main project file.
#include "stdafx.h"
#include "Form1.h"
#include"windows.h"
using namespace WinformTest;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}
Here is .h file
#pragma once
namespace WinformTest {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(91, 51);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this,
&Form1::button1_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
ShowWindow(00050214, false );
}
};
}
UPDATE
I have now put windows.h in form.h file, and used ShowWindow((HWND)0x00050214, SW_HIDE);
but now I am getting:
Error 1 error LNK2028: unresolved token (0A000011) "extern "C" int __stdcall
ShowWindow(struct HWND__ *,int)" (?ShowWindow@@$$J18YGHPAUHWND__@@H@Z) referenced in function
"private: void __clrcall WinformTest::Form1::button1_Click(class System::Object ^,class
System::EventArgs ^)"
(?button1_Click@Form1@WinformTest@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
C:\Users\Afnan\Documents\Visual Studio 2010\Projects\WinformTest\WinformTest\WinformTest.obj
Error 2 error LNK2019: unresolved external symbol "extern "C" int __stdcall
ShowWindow(struct HWND__ *,int)" (?ShowWindow@@$$J18YGHPAUHWND__@@H@Z) referenced in function
"private: void __clrcall WinformTest::Form1::button1_Click(class System::Object ^,class
System::EventArgs ^)"
(?button1_Click@Form1@WinformTest@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
C:\Users\Afnan\Documents\Visual Studio 2010\Projects\WinformTest\WinformTest\WinformTest.obj
Error 3 error LNK1120: 2 unresolved externals C:\Users\Afnan\Documents\Visual
Studio 2010\Projects\WinformTest\Debug\WinformTest.exe 1
How do put handle? I got this handle using spy++ tool. It also shows caption corresponding to the handle expressed in numbers. The corresponding handle in my case is: WinformTest – Microsoft Visual Studio
Your header file does not include
windows.hand so the symbolShowWindowis not known to it.The way you call
ShowWindowis also wrong. The second parameter is anintand you want to passSW_HIDE. And I bet that your window handle is actually a hex number.As an aside, I’m not sure why you put so much code in the header file. Normally you would declare the class in the header file and then define the implementation in the cpp file.