シンプルな CLR-Windows フォーム アプリケーションを作成しようとしています。ボタンのあるウィンドウが表示されます。ボタンをクリックするとすぐに、開いているウィンドウの 1 つが非表示になります。これを実現するために、ShowWindow(00050214, false ); を呼び出しています。ここで、00050214 は非表示にしているウィンドウのハンドルです。
しかし、それはエラーを出しています:
Error 1 error C3861: 'ShowWindow': identifier not found c:\users\afnan
\documents \visual studio 2010\projects\winformtest\winformtest\Form1.h 80
上記の関数をどのように使用しているかを確認するには、以下の .h ファイルの最後の行を参照してください。
WinformTest.cpp : メイン プロジェクト ファイル。
#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;
}
ここに.hファイルがあります
#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 );
}
};
}
アップデート
windows.h を form.h ファイルに入れ、ShowWindow((HWND)0x00050214, SW_HIDE); を使用しました。しかし、今私は得ています:
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
ハンドルの付け方は?spy++ ツールを使用してこのハンドルを取得しました。また、数字で表されたハンドルに対応するキャプションも表示されます。私の場合、対応するハンドルは次の とおりです。 WinformTest - Microsoft Visual Studio