#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] = { { 0xE0, 0x04, 0x01, 0x00, 0x38, 0xBE, 0x76, 0x99 }, { 0xE0, 0x04, 0x01, 0x00, 0x03, 0x1D, 0xB2, 0xDA } };
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, 100, 100, 1300, 700, NULL, (HMENU)NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow);
while (GetMessage(&Message, 0, 0, 0)) { 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, 600, 0, 100, 25, 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, 0, 0, 500, 750, MemDC, 0, 0, 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; } |