본문 바로가기
코스웨어/15년 스마트컨트롤러

20151211_박서연_일일업무보고서_RFID(4)

by 알 수 없는 사용자 2015. 12. 14.
728x90
반응형

2015-11-12


* RFID


#RFID 프로젝트

큰 주제

WINAPI를 사용해 RFID 카드 리더기로부터 UID를 읽어 들여서 해당하는 카드 마다 미리 등록된 이미지를 불러온다.


디테일

- 오류시 이미지 처리

- SCAN 버튼 작성


추가사항

- 타이머를 이용해서 SCAN 버튼 없이 SCAN하기

- 데이터를 미리 밀어넣지 않고 구조체화해서 파일화, DB화 등등 구조화 시키기( 연결리스트를 이용한 자료구조도 생각해 보기)

- 하나하나 완성할수록 디테일하게 하나하나 추가해 보기

- ATmeaga와 연동하여 도어락 만들어 보기


현재까지의 코드

 #include<windows.h>

 #include "smart.h"

 #include "resource.h"

#define IDB_BITMAP1                     101
 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        102
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1000
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif


#define ID_EDIT 100

#define XPOS 20
#define YPOS 20
#define XWIDTH 100
#define YWIDTH 25
#define GAP 5


typedef struct _stMsgMap
{
  UINT uiMsg;
  LRESULT(*FP)(WPARAM, LPARAM);
}stMsgMap;

LRESULT On_Create(WPARAM, LPARAM);
LRESULT On_Destroy(WPARAM, LPARAM);
LRESULT On_Paint(WPARAM, LPARAM);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

stMsgMap MsgMap[] = {
  { WM_PAINT, On_Paint },
  { WM_DESTROY, On_Destroy },
  { WM_CREATE, On_Create },
  { WM_NULL, 0 }
};

HWND hWnd;
HWND hHandle;
//UCHAR    *ucpData;  //동적 활당용
HINSTANCE  g_hInst;
LPSTR    lpszClass = (LPSTR)TEXT("Image View");

//static HBITMAP hbmScreen;
UCHAR ucaUDB[][8= {
  { 0xE00x040x010x000x380xBE, 0x760x99 },
  { 0xE00x040x010x000x030x1D, 0xB20xDA }
};

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, int nCmdShow)
{
  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)WndProc;
  WndClass.lpszClassName = (LPCWSTR)lpszClass;
  WndClass.lpszMenuName = NULL;
  WndClass.style = CS_HREDRAW | CS_VREDRAW;
  RegisterClass(&WndClass);

  hWnd = CreateWindow((LPCWSTR)lpszClass, (LPCWSTR)lpszClass, WS_OVERLAPPEDWINDOW,
    1001001300700, NULL, (HMENU)NULL, hInstance, NULL);
  ShowWindow(hWnd, nCmdShow);

  while (GetMessage(&Message, 000))
  {
    TranslateMessage(&Message);
    DispatchMessage(&Message);
  }
  return Message.wParam;
}

LRESULT CALLBACK WndProc(HWND hWpWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
  stMsgMap *stpMap = MsgMap;
  hWnd = hWpWnd;
  while (WM_NULL != (*stpMap).uiMsg)
  {
    if (iMessage == (*stpMap).uiMsg)
    {
      return (((*stpMap).FP)(wParam, lParam));
    }
    ++stpMap;
  }
  return(DefWindowProc(hWnd, iMessage, wParam, lParam));
}

LRESULT On_Create(WPARAM wParam, LPARAM lParam)
{
  //  HDC hdc; // 지역
  //  HDC memDC; // 지역
  //  PAINTSTRUCT ps;

  HANDLE hFile, hComm;   // 한번 읽고 닫기 때문에 static이 필요없음
  BOOL  bRet;
  DWORD  dwCnt;

  //bmp 파일 읽기
  hFile = CreateFile(TEXT("1.bmp"), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

  hFile = CreateWindow(TEXT("button"), TEXT("스캔"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
    600010025, hWnd, (HMENU)0, g_hInst, NULL);

  if (INVALID_HANDLE_VALUE == hFile)
  {
    MessageBox(hWnd, TEXT("CreateFile이 실패했습니다."), TEXT("Error."), MB_OK);
    PostQuitMessage(0);
    return 0;
  }


  hComm = CreateFile(TEXT("COM3")
    , GENERIC_READ | GENERIC_WRITE
    , 0
    , NULL
    , OPEN_EXISTING
    , FILE_ATTRIBUTE_NORMAL
    , 0);


  MessageBox(hWnd, TEXT("On_Create()가 성공적으로 수행 되었습니다."), TEXT("Button"), MB_OK);
  CloseHandle(hFile);

  return 0;
}


LRESULT On_Paint(WPARAM wParam, LPARAM lParam)  //화면에 그리는 역활만.
{
  HDC hdc;
  HDC MemDC;
  PAINTSTRUCT ps;
  static HBITMAP MyBitmap, OldBitmap;

  hdc = BeginPaint(hWnd, &ps);
  MemDC = CreateCompatibleDC(hdc);

  MyBitmap = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_BITMAP1));
  OldBitmap = (HBITMAP)SelectObject(MemDC, MyBitmap);
  BitBlt(hdc, 00500750, MemDC, 00, SRCCOPY);
  SelectObject(MemDC, OldBitmap);
  DeleteObject(MyBitmap);

  /*
  MyBitmap = LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_BITMAP2));
  OldBitmap = (HBITMAP)SelectObject(MemDC, MyBitmap);
  BitBlt(hdc, 510, 0, 730, 670, MemDC, 0, 0, SRCCOPY);
  SelectObject(MemDC, OldBitmap);
  DeleteObject(MyBitmap);
  */

  DeleteDC(MemDC);
  EndPaint(hWnd, &ps);

  return 0;
}

LRESULT On_Destroy(WPARAM wParam, LPARAM lParam)
{
  //  free(ucpData);
  PostQuitMessage(0);

  return 0;
}




728x90