TIPS/Programming

Visual C++ 2008 縺ォ繧医k繧ッ繝ェ繝繝励懊シ繝峨°繧峨ョ逕サ蜒丞叙蠕励し繝ウ繝励Ν繝励Ο繧ー繝ゥ繝

讎ら払

縺薙ョ繧「繝励Μ繧ア繝シ繧キ繝ァ繝ウ縺ッ縲〃isual C++ 2008 縺ァ繧ッ繝ェ繝繝励懊シ繝峨↓繧ウ繝斐シ縺輔l縺 逕サ蜒上r隱ュ縺ソ蜃コ縺吶◆繧√ョ繧オ繝ウ繝励Ν繝励Ο繧ー繝ゥ繝縺ァ縺吶

蝓コ譛ャ蜍穂ス懊サ讖溯ス

縺薙ョ繧オ繝ウ繝励Ν繝励Ο繧ー繝ゥ繝縺ッ縲∽ク玖ィ倥ョ讖溯ス繧呈戟縺」縺ヲ縺縺セ縺吶

  • 繧ッ繝ェ繝繝励懊シ繝峨↓繧ウ繝斐シ縺輔l縺溽判蜒上r蜿悶j霎シ縺ソ縲)peg繝輔ぃ繧、繝ォ縺ォ菫晏ュ倥@縺セ縺吶
  • 菫晏ュ倥ヵ繧。繧、繝ォ蜷阪r閾ェ蜍輔〒逕滓舌@縲騾」邯壹@縺ヲ逕サ蜒上r蜿悶j霎シ縺ソ縲)peg繝輔ぃ繧、繝ォ縺ォ菫晏ュ倥@縺セ縺吶
  • 繧ッ繝ェ繝繝励懊シ繝峨↓逕サ蜒上ヵ繧。繧、繝ォ縺後さ繝斐シ縺輔l縺溘%縺ィ繧定ェ蜍輔〒讀懃衍縺励∽ク願ィ伜虚菴懊r陦後>縺セ縺吶

謚陦

縺薙ョ繧オ繝ウ繝励Ν繝励Ο繧ー繝ゥ繝縺ッ縲∽ク玖ィ倥ョ繧医≧縺ェ謚陦鍋噪隕∫エ繧剃スソ逕ィ縺励※縺縺セ縺吶

  • Windows繝。繝繧サ繝シ繧ク蜿嶺ソ。
  • 繧ッ繝ェ繝繝励懊シ繝峨ン繝・繝シ繝ッ(ClipBoard Viewer)
  • 繝薙Η繝シ繝ッ繝√ぉ繧、繝ウ(Viewer Chain) 縲縲縲 荳願ィ倥ョ謚陦鍋噪隕∫エ縺ョ隱ャ譏弱ッ荳玖ィ倥ョ騾壹j縺ァ縺吶
  • 繧ッ繝ェ繝繝励懊シ繝峨↓繝繝シ繧ソ縺瑚イシ繧贋サ倥¢繧峨l縺溷エ蜷医√け繝ェ繝繝励懊シ繝峨ン繝・繝シ繝ッ繧医j縲仝M_DRAWCLIPBOARD繝。繝繧サ繝シ繧ク縺碁√i繧後※縺上k縲
  • 莉ョ諠ウ髢「謨ー(WndProc)繧偵が繝シ繝舌シ繝ゥ繧、繝峨@縺ヲ縲仝M_DRAWCLIPBOARD繝。繝繧サ繝シ繧ク繧貞女菫。
  • WM_DRAWCLIPBOARD繝。繝繧サ繝シ繧ク繧偵√ン繝・繝シ繝ッ繝√ぉ繧、繝ウ繧堤畑縺縺ヲ縲∵ャ。縺ョ繝√ぉ繧、繝ウ縺ォ逋サ骭イ縺輔l縺溘え繧」繝ウ繝峨え縺ォ霆「騾√☆繧九
    縲窶サシ代ン繝・繝シ繝ッ繝√ぉ繧、繝ウ(Viewer Chain)縺ィ縺ッ縲√け繝ェ繝繝励懊シ繝峨r蛻ゥ逕ィ縺吶k繧ヲ繧」繝ウ繝峨え縺ョ繝ェ繧ケ繝医〒縺吶
    縲窶サシ偵け繝ェ繝繝励懊シ繝峨r蛻ゥ逕ィ縺吶k蜷繧「繝励Μ繧ア繝シ繧キ繝ァ繝ウ縺ッ縲√◎繧後◇繧後′谺。縺ョ繝薙Η繝シ繝ッ繝√ぉ繧、繝ウ縺ォ逋サ骭イ縺輔l縺ヲ縺繧九え繧」繝ウ繝峨え縺ォWM_DRAWCLIPBOARD繝。繝繧サ繝シ繧ク繧定サ「騾√☆繧句ソ隕√′縺ゅj縺セ縺吶

蛻ゥ逕ィ譚。莉カ繝サ闡嶺ス懈ィゥ繝サ霆「霈峨↑縺ゥ縺ォ縺、縺縺ヲ

縺薙ョ繧オ繝ウ繝励Ν繧剃スソ縺荳翫〒縲∫音縺ォ蛻カ髯舌ッ縺斐*縺縺セ縺帙s縲ゅ%縺ョ繧ス繝輔ヨ繧剃スソ縺」縺滉コ九↓繧医k謳榊ョウ縺ェ縺ゥ縺ッ縲∽ス懆縺ッ荳蛻髢「遏・縺励∪縺帙s縺ョ縺ァ縲√#莠謇ソ縺上□縺輔>縲

縺薙ョ繧オ繝ウ繝励Ν繧剃スソ縺」縺ヲ菴輔i縺九ョ繧ス繝輔ヨ繧剃ス懊▲縺ヲ蜈ャ髢九@縺溘j縲∵・ュ蜍吶〒菴ソ逕ィ縺吶k縺薙→縺ォ繧ゅ→縺上↓蛻カ髯舌ッ縺斐*縺縺セ縺帙s縲ゅ◆縺縺励√◎縺ョ蝣エ蜷医ッ逶ク莠偵Μ繝ウ繧ッ縺ェ縺ゥ縺ァ邏ケ莉九@縺ヲ縺縺溘□縺代k縺ィ螫峨@縺縺ァ縺吶

螳溯。檎腸蠅(遘√′繝繧」繝舌ャ繧ー縺励※縺縺溽腸蠅縺ァ縺)

  • OS: WindowsXP SP3
  • 髢狗匱迺ー蠅シ Microsoft Visual C++ 2008 Express Edition

繝繧ヲ繝ウ繝ュ繝シ繝

荳玖ィ倥ョ繝輔ぃ繧、繝ォ繧偵ム繧ヲ繝ウ繝ュ繝シ繝峨@縺ヲ縺上□縺輔>縲 Visual C++ 2008 縺ョ繧オ繝ウ繝励Ν繝励Ο繧ク繧ァ繧ッ繝医r荳ク縺斐→ZIP縺励※縺縺セ縺吶ゅム繧ヲ繝ウ繝ュ繝シ繝牙セ後∬ァ」蜃阪@縺ヲ繧ス繝ェ繝・繝シ繧キ繝ァ繝ウ繝輔ぃ繧、繝ォ繧帝幕縺縺ヲ縺上□縺輔>縲

ClipBoardSample100.zip(19kB)

繧ス繝シ繧ケ繧ウ繝シ繝芽ェャ譏

荳玖ィ倥↓縲∽ク驛ィ縺ョ驥崎ヲ√↑繧ス繝シ繧ケ繧ウ繝シ繝峨r遉コ縺励∪縺吶

	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
				//繧ッ繝ェ繝繝励懊シ繝峨ン繝・繝ッ繝シ縺ォ逋サ骭イ縺励※縲∵ャ。縺ョ繧ヲ繧」繝ウ繝峨え縺ョ繝上Φ繝峨Ν繧貞セ励k縲
				 this->m_hWndNext = ::SetClipboardViewer(static_cast<HWND>(this->Handle.ToPointer()));
			 }
	private: System::Void Form1_FormClosed(System::Object^  sender, System::Windows::Forms::FormClosedEventArgs^  e) {
				//繧ッ繝ェ繝繝励懊シ繝峨メ繧ァ繧、繝ウ縺九i縲∬ェ蛻閾ェ霄ォ繧貞炎髯、縺吶k縲
				 ::ChangeClipboardChain(static_cast<HWND>(this->Handle.ToPointer()), this->m_hWndNext);
			 }
	public: virtual	System::Void WndProc(System::Windows::Forms::Message% m) override
			{//繝。繝繧サ繝シ繧ク繧貞女縺大叙繧九よィェ蜿悶jシ
				System::Windows::Forms::IDataObject	^data = System::Windows::Forms::Clipboard::GetDataObject();
				
				this->Form::WndProc(m);	//蜈縺ョ譁ケ繧ょヲ逅縺吶k縲
				//繧ッ繝ェ繝繝励懊シ繝蛾未騾」縺ョ繝。繝繧サ繝シ繧ク繧貞女縺大叙繧九
				switch(m.Msg)
				{
					//繧ッ繝ェ繝繝励懊シ繝峨↓繝繝シ繧ソ縺後さ繝斐シ縺輔l縺溘
					case WM_DRAWCLIPBOARD:
							SavePictureToFile();
							//谺。縺ョ繧ッ繝ェ繝繝励懊シ繝峨メ繧ァ繧、繝ウ縺ォ繝。繝繧サ繝シ繧ク繧定サ「騾√
							::SendMessage(this->m_hWndNext, m.Msg, m.WParam.ToInt32(), m.LParam.ToInt32());
						break;
					case WM_CHANGECBCHAIN:
							//繧ッ繝ェ繝繝励懊シ繝峨メ繧ァ繧、繝ウ縺悟、画峩縺輔l縺溘
							//蜑企勁縺輔l縺溘ョ縺瑚ェ蛻縺ョ谺。縺ョ繧ヲ繧」繝ウ繝峨え縺ェ繧峨√◎繧後r縺昴ョ谺。縺ョ繧ヲ繧」繝ウ繝峨え縺ョ繝上Φ繝峨Ν縺ァ荳頑嶌縺阪
							if(this->m_hWndNext == static_cast<HWND>(m.WParam.ToPointer())){
								this->m_hWndNext = static_cast<HWND>(m.LParam.ToPointer());
							}
							else if(this->m_hWndNext != NULL){
								::SendMessage(this->m_hWndNext, m.Msg, m.WParam.ToInt32(), m.LParam.ToInt32());
							}
							break;
				}
			}
	private: String^	GenerateSaveFileName(){
				 //譌・莉倥→迴セ蝨ィ譎ょ綾縺九i繝輔ぃ繧、繝ォ蜷阪r逕滓舌
				 DateTime^	dt = DateTime::Now;
				 return( dt->ToString("yyyyMMddHHmmss"));
			 }
	private: void	SavePictureToFile(){
				 //繧ッ繝ェ繝繝励懊シ繝峨°繧臥判蜒上r蜿門セ励@縲゛PEG蠖「蠑上〒菫晏ュ倥☆繧九
				 System::Windows::Forms::IDataObject	^data = System::Windows::Forms::Clipboard::GetDataObject();
				 //繧ッ繝ェ繝繝励懊シ繝牙縺ォ繝繝シ繧ソ縺後≠繧九°縺ゥ縺縺九
					 if(data->GetDataPresent(DataFormats::Bitmap) == true)
					 {					 
						 if( (checkFileNameAutoGenerate->Checked == true) || (textFileName->Text == "")){
							textFileName->Text = GenerateSaveFileName();
							}
						 //繧ッ繝ェ繝繝励懊シ繝峨°繧峨ョ繝シ繧ソ繧竪ET縺吶k縲
						 pictureShowPicture->Image = (Image^)data->GetData(DataFormats::Bitmap);
						 //繝輔か繝ォ繝縺ョ譛蠕後ョ譁蟄励r "\" 縺ォ縺吶k縲
						 if( textFolderDestination->Text[textFolderDestination->Text->Length - 1] != '\\'){
							textFolderDestination->Text = textFolderDestination->Text + "\\";
						 }
						 //JPEG蠖「蠑上〒菫晏ュ
						pictureShowPicture->Image->Save(textFolderDestination->Text + textFileName->Text + ".jpg");
					 }
			 }
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
					 SavePictureToFile();				
				 }
	private: System::Void button1_Click_1(System::Object^  sender, System::EventArgs^  e) {
					 folderBrowserDialog->ShowDialog(this);
					 if(folderBrowserDialog->SelectedPath != ""){
						 textFolderDestination->Text = folderBrowserDialog->SelectedPath;
					 }
				 }

繝医ャ繝   蟾ョ蛻 繝舌ャ繧ッ繧「繝繝 繝ェ繝ュ繝シ繝   荳隕ァ 蜊倩ェ樊、懃エ「 譛邨よ峩譁ー   繝倥Ν繝   譛邨よ峩譁ー縺ョRSS
Last-modified: 2009-05-23 (蝨) 16:06:36 (3012d)