Study - Programming/C#2007. 8. 29. 01:30

using System;
using System.Threading;

public class ThreadExam1
{
    public static void Print1()
    {
        Console.WriteLine("첫 번째 Thread **");
    }

    public void Print2()
    {
        Console.WriteLine("두 번째 Thread **");
    }

    public static void Main()
    {
        Thread thread = new Thread(new ThreadStart(Print1));
        thread.Start();
        thread = new Thread(new ThreadStart((new ThreadExam1()).Print2));
        thread.Start();

        Console.WriteLine("세 번째 Thread");
    }
}


솔직히 말해 모르겠다 이거 뭐하는건지.. 스레드의 정의 자체는 알겠는데 이게 어떤 의미인지를 잘 모르겠다;; 일단 델리게이트 부분부터 다시 봐서 이 코드가 어떻게 돌아가는지부터 다시 공부해 봐야지..

Posted by 머리
Study - Programming/C/C++2007. 8. 29. 01:23
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
 HDC hdc;
 PAINTSTRUCT ps;
 int i;
 switch (iMessage)
 {
 case WM_CREATE:
  SetTimer(hWnd,1,50,NULL);
  return 0;
 case WM_TIMER:
  hdc = GetDC(hWnd);
  for(i = 0 ;i <1000; i++)
  {
   SetPixel(hdc,rand()%500,rand()%400,RGB(rand()%256,rand()%256,rand()%256));
  }
  return 0;
 case WM_LBUTTONDOWN:
  hdc = GetDC(hWnd);
  Ellipse(hdc,LOWORD(lParam)-10,HIWORD(lParam)-10,LOWORD(lParam)+10,HIWORD(lParam)+10);
  ReleaseDC(hWnd,hdc);
  return 0;
 case WM_PAINT:
  hdc=BeginPaint(hWnd,&ps);
  EndPaint(hWnd,&ps);
  return 0;
 case WM_DESTROY:
  PostQuitMessage(0);
  return 0;
 }
 return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}
Posted by 머리
Study - Programming/C/C++2007. 8. 29. 01:19

LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
 HDC hdc;
 PAINTSTRUCT ps;
 static BOOL isDown = FALSE;

 static int oldx;
 static int oldy;

 switch (iMessage)
 {
 case WM_LBUTTONDOWN:
  oldx = LOWORD(lParam);
  oldy = HIWORD(lParam);
  isDown = TRUE;
  return 0;
 case WM_LBUTTONUP:
  isDown = FALSE;
  return 0;
 case WM_MOUSEMOVE:
  if(isDown == TRUE)
  {
   hdc = GetDC(hWnd);
   MoveTo!Ex(hdc,oldx,oldy,NULL);
   oldx = LOWORD(lParam);
   oldy = HIWORD(lParam);
   LineTo(hdc,oldx,oldy);
   ReleaseDC(hWnd,hdc);
  }
  return 0;
 case WM_PAINT:
  hdc=BeginPaint(hWnd,&ps);
  EndPaint(hWnd,&ps);
  return 0;
 case WM_DESTROY:
  PostQuitMessage(0);
  return 0;
 }
 return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}


별것 없다. 마우스로 드로잉 하는 예제


우선 WM_LBUTTONDOWN 메세지가 호출되면 oldx,oldy에 좌표가 저장되고, WM_MOUSEMOVE메세지에서 마우스가 움직일때마다 좌표를 읽는다. 그래서 oldx,oldy에서 마우스 위치까지 선을 그려내면 된다.


Posted by 머리