홈
태그
미디어로그
위치로그
방명록
분류 전체보기
(112)
0x01 Notice
(11)
diary
(8)
0x02 Tips
(7)
iOS
(5)
Facebook
(2)
Twitter
(0)
0x03 Thinks
(4)
0x04 Security
(14)
news
(10)
web
(0)
mobile
(0)
system
(1)
forensic
(0)
vulnerabilities
(3)
0x05 Programming
(76)
C / C++
(12)
Java
(5)
Object -C
(3)
API / MFC
(11)
Unix/Linux
(6)
Socket Programing
(6)
Kelnel Programing
(6)
iPhone Programing
(19)
Android Programing
(5)
Web Programming
(2)
ABOUT ME
-
트위터
인스타그램
Today
-
Yesterday
-
Total
-
::j0ker's Lab::
::j0ker's Lab::
메뉴
검색
컨텐츠 검색
블로그 내 검색
[API] 비트맵 적용 숫자퍼즐
0x05 Programming/API / MFC
2009. 11. 2. 17:47
#include <stdafx.h> #include "resource.h" //비트맵을 사용할 수 있게 해주는 핸들 extern HINSTANCE hInst; //해당 hInst변수를 연결 HBITMAP g_hMyBitmap; //리소스 연결 HDC g_hMyDC; //dc에 연결 (이걸로 화면 출력ㅇㅇ) int g_data[3][3]= { {1,2,3}, {4,5,6}, {7,8,9} }; void MyIni(HWND hWnd, WPARAM wParam, LPARAM lParam) { HDC hdc; hdc = GetDC(hWnd); //화면제어권 획득 g_hMyDC = CreateCompatibleDC(hdc); //DC(제어권)에 호환되는 것을 만든다 //리소스에 있는 비트맵을 로드 g_hMyBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1)); //초기화 과정 SelectObject(g_hMyDC, g_hMyBitmap); //제어권 변환 ReleaseDC(hWnd, hdc); } void MyPaint(HWND hWnd, WPARAM wParam, LPARAM lParam, HDC hdc) { int x, y; int xpos, ypos; char temp[10]; // BitBlt(hdc, 0, 0, 150, 150, g_hMyDC, 0, 0, SRCCOPY); for(y=0;y<3;y++) { for(x=0;x<3;x++) { xpos=x*50; ypos=y*50; Rectangle(hdc, xpos, ypos, xpos+50, ypos+50); if(9 != g_data[y][x]) { int xx; int yy; wsprintf(temp, "%d", g_data[y][x]); TextOut(hdc, xpos+20, ypos+20, temp, strlen(temp)); xx=((g_data[y][x]-1)%3)*50; yy=((g_data[y][x]-1)/3)*50; BitBlt(hdc, xpos, ypos, 50-2, 50-2, g_hMyDC, xx, yy, SRCCOPY); } } } StretchBlt(hdc, 160, 0, 50, 50, g_hMyDC, 0, 0, 150, 150, SRCCOPY); //미리보기 } int CanMove(int sx, int sy, int dx, int dy) { if(sx < 0 || sy < 0 || dx < 0 || dy < 0) { return -1; } if(2 < sx || 2 < sy || 2 < dx || 2 < dy) { return -1; } if(9 == g_data[dy][dx]) { g_data[dy][dx] = g_data[sy][sx]; g_data[sy][sx] = 9; return 0; } else { return -1; } return 0; } void MyMouse(HWND hWnd, WPARAM wParam, LPARAM lParam) { int x, y; x=LOWORD(lParam)/50; y=HIWORD(lParam)/50; if(0 == CanMove(x, y, x-1, y)) { InvalidateRect(hWnd, NULL, TRUE); } else if(0 == CanMove(x, y, x+1, y)) { InvalidateRect(hWnd, NULL, TRUE); } else if(0 == CanMove(x, y, x, y-1)) { InvalidateRect(hWnd, NULL, TRUE); } else if(0 == CanMove(x, y, x, y+1)) { InvalidateRect(hWnd, NULL, TRUE); } }
공유하기
게시글 관리
::j0ker's Lab::
저작자표시
관련글
관련글 더보기
[MFC] 다른클래스에서 메인 다이얼로그의 포인터 얻어오기 (dialog based)
[API] 11.13 수업
[API] 늑대의 침공 기본형
[API]늑대의 침공 가상키보드 적용 [미완성]
티스토리툴바