前田稔(Maeda Minoru)の超初心者のプログラム入門
ファイル名 | 説明 |
---|---|
HDC.cpp | HDC を取得 |
#include <windows.h> #pragma comment(lib, "user32.lib") #pragma comment(lib, "gdi32.lib") |
FormClass() { form = gcnew Form(); Paint += gcnew PaintEventHandler(this, &FormClass::MyHandler); } |
void MyHandler(Object^ sender, PaintEventArgs^ e) { MessageBox::Show("MyHandler","check"); Graphics^ g = e->Graphics; System::Drawing::Graphics^ g = e->Graphics; g->DrawLine(gcnew Pen(Color::Red),10,50,260,50); g->DrawLine(gcnew Pen(Color::Green,10),10,150,260,150); } |
void MyHandler(Object^ sender, PaintEventArgs^ e) { HDC hdc = (HDC)(e->Graphics->GetHdc().ToInt32()); ::Rectangle(hdc,50,30,200,80); e->Graphics->ReleaseHdc((System::IntPtr)hdc); } |
void MyHandler(Object^ sender, PaintEventArgs^ e) { HWND hWnd = (HWND)this->Handle.ToInt32(); HDC hdc; hdc= ::GetDC(hWnd); for(int i=20; i<220; i++) { ::SetPixel(hdc,i,20,RGB(255,0,0)); ::SetPixel(hdc,i,40,RGB(0,0,255)); ::SetPixel(hdc,i,41,RGB(0,0,255)); ::SetPixel(hdc,i,42,RGB(0,0,255)); } ::ReleaseDC(hWnd,hdc); } |