티스토리 뷰

카테고리 없음

api실습예제

문정환 2008. 6. 2. 14:35

// 원이 이동하는 프로그램///
//엔터를 누를시 스타트//
//스페이스를 누를시 정지//
// 이동시 X,Y좌료를 출력//
#include <windows.h>

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
LPCTSTR lpszClass=TEXT("First");

int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance
                  ,LPSTR lpszCmdParam,int nCmdShow)
{
        HWND hWnd;
        MSG Message;
        WNDCLASS WndClass;
        g_hInst=hInstance;
        WndClass.cbClsExtra=0;
        WndClass.cbWndExtra=0;
        WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
        WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
        WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
        WndClass.hInstance=hInstance;
        WndClass.lpfnWndProc=WndProc;
        WndClass.lpszClassName=lpszClass;
        WndClass.lpszMenuName=NULL;
        WndClass.style=CS_HREDRAW | CS_VREDRAW;
        RegisterClass(&WndClass);
        hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW,
                CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,700,
                NULL,(HMENU)NULL,hInstance,NULL);
        ShowWindow(hWnd,nCmdShow);
        while (GetMessage(&Message,NULL,0,0)) {
                TranslateMessage(&Message);
                DispatchMessage(&Message);
        }
        return (int)Message.wParam;
}
#define START 1;
#define STOP 2;
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
    HDC hdc;
 PAINTSTRUCT ps;
    static int x=0,y=50,v=300,z=500;
 //static int nx1=0,xy1=40,nx2=20,ny2=60;
 RECT rt={100,600,100,700};
 static TCHAR Tvew[128];
 HPEN hpen;
 static select;
 switch (iMessage) {
        case WM_KEYDOWN:
  switch(wParam)
  {
  case VK_RETURN:
  SetTimer(hWnd,1,10,NULL);
  SendMessage(hWnd,WM_TIMER,1,0);
  select=START;
  break;
  case VK_SPACE:
  KillTimer(hWnd,1);
  break;
  }
  case WM_TIMER:
   InvalidateRect(hWnd,NULL,TRUE);
  UpdateWindow(hWnd);
  wsprintf(Tvew,TEXT("%d %d %d %d"),x,v,y,z);
  switch(select)
  {
  case 1:
  x+=5;
  y+=5;
  if(y==700)
  {
  select=2;
  }
  break;
  case 2:
  x-=5;
  y-=5;
  if(x==0)
  {
  select=2;
  }
  break;
  }
  return 0;
  case WM_PAINT:
  hdc=BeginPaint(hWnd,&ps);
  hpen=CreatePen(PS_SOLID,2,RGB(255,0,0));
  SelectObject(hdc,hpen);
  TextOut(hdc,10,10,Tvew,lstrlen(Tvew));
  Ellipse(hdc,x,300,y,350);
  EndPaint(hWnd,&ps);
  break;
  case WM_DESTROY:
   PostQuitMessage(0);
                return 0;
        }
        return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함