그중에 응용해서 사용한 소스는 밑에 부분입니다.
궁금하신거 있음 댓글 달아 주세요..ㅎ
// 디지털 시계
#include <windows.h>
#include "resource.h"
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
//-----------------------------------------------
static HBITMAP hBitmap;
static SYSTEMTIME st;
static RECT rc = { 0, 0, 108, 27 };
//----------------------------------------------
switch( msg )
{
case WM_NCRBUTTONUP:
{
HINSTANCE hInst = GetModuleHandle(0);
HMENU h1 = LoadMenu(hInst, MAKEINTRESOURCE(IDR_MENU1));
HMENU h2 = GetSubMenu(h1, 0);
POINT pt;
GetCursorPos(&pt); // 스크린 좌표 얻기..
// 팝업 메뉴..
int cmd = TrackPopupMenu(h2, TPM_LEFTBUTTON | TPM_RETURNCMD,
pt.x, pt.y, 0, hwnd, 0);
// 메뉴 처리..
if( cmd == IDM_FILE_EXIT)
SendMessage(hwnd, WM_CLOSE, 0, 0);
DestroyMenu(h1);
}
return 0;
case WM_TIMER:
if( wParam == 1)
{
GetLocalTime(&st);
InvalidateRect(hwnd, &rc, FALSE);
}
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HDC memDC = CreateCompatibleDC(hdc);
HBITMAP old = (HBITMAP)SelectObject(memDC, hBitmap);
SetViewportOrgEx(hdc, 2, 2, 0);
//
//
//---------------------------------------------
int t[8] = { st.wHour / 10, st.wHour % 10, 10,
st.wMinute / 10, st.wMinute % 10, 10,
st.wSecond / 10, st.wSecond %10 };
for( int i=0; i< 8; ++i) // 0
BitBlt(hdc, i*13, 0, 13, 23, // 0, 0, 13, 23
memDC, t[i]*13, 0, SRCCOPY);
//-----------------------------------------------
// t[0]*13,0
SelectObject(memDC, old);
DeleteDC(memDC);
EndPaint(hwnd, &ps);
}
return 0;
case WM_DESTROY:
//-------------------------
KillTimer(hwnd, 1);
DeleteObject(hBitmap);
//-------------------------
PostQuitMessage(0);
return 0;
case WM_CREATE:
{
// LoadBitmap : rc로 접근...
// LoadImage : 디렉토리/파일 명으로 접근..
hBitmap = (HBITMAP)LoadImage(0, ".\\resource\\Digit.bmp", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE);
// HINSTANCE hInst = ((LPCREATESTRUCT)lParam)->hInstance;
// hBitmap = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP2));
SetTimer(hwnd, 1, 1000, 0);
SendMessage(hwnd, WM_TIMER, 1,0);
// 윈도우 스타일 변경..
// Popup 만 주고 모든 속성 제거..
SetWindowLong(hwnd, GWL_STYLE, (LONG)WS_POPUP);
SetWindowPos(hwnd, 0, 0, 0, 108, 27,
SWP_NOMOVE | SWP_NOZORDER | SWP_DRAWFRAME);
}
return 0;
case WM_NCHITTEST:
return HTCAPTION;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd)
{
// 1. 윈도우 클래스 만들기
WNDCLASS wc;
wc.cbWndExtra = 0;
wc.cbClsExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hIcon = LoadIcon(0, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc; // DefWindowProc;
wc.lpszClassName = "First";
wc.lpszMenuName = 0;
wc.style = 0;
// 2. 등록(레지스트리에)
RegisterClass(&wc);
// 3. 윈도우 창 만들기
HWND hwnd = CreateWindowEx( 0, // WS_EX_TOPMOST
"first", // 클래스 명
"Hello", // 캡션바 내용
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT , 0, CW_USEDEFAULT, 0, // 초기 위치
0, 0, // 부모 윈도우 핸들, 메뉴 핸들
hInstance, // WinMain의 1번째 파라미터 (exe 주소)
0); // 생성 인자
// 4. 윈도우 보여주기
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
// 5. Message
MSG msg;
while( GetMessage( &msg, 0, 0, 0 ) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
// Bitmap _오목...클릭시에 검은 돌...
//이걸 이용해서 오목 만들수 있겠죠?
#define _WIN32_WINNT 0x500
#define WINVER 0x500
#include <windows.h>
#pragma comment( lib, "msimg32.lib") // TransparentBlt는 msimg32.lib안에 존재..
//-----------------------------------------------------------
static HBITMAP hPen, hWhite, hBlack;
enum { EMPTY = 1, BLACK = 2, WHITE = 3 };
char board[19][19] = { EMPTY };
//-----------------------------------------------------------
void DrawStone( HDC hdc, int x, int y, char stone)
{
HDC memDC = CreateCompatibleDC(hdc);
HBITMAP old;
if( stone == BLACK)
old = (HBITMAP)SelectObject(memDC, hBlack);
else
old = (HBITMAP)SelectObject(memDC, hWhite);
// BitBlt(hdc, x, y, 29, 29, memDC, 0, 0, SRCCOPY);
TransparentBlt(hdc, x, y, 29, 29, memDC, 0, 0, 29, 29, RGB(255, 0, 0));
SelectObject(memDC, old);
DeleteDC(memDC);
}
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch( msg )
{
case WM_LBUTTONDOWN:
{
// 1. 검은돌 차례인가?
// 2. 현재 좌표에 돌이 없는가? ( board 배열 확인 )
// 3. 돌을 그린다...
POINTS pt = MAKEPOINTS(lParam);
pt.x = (( pt.x) / 30 ) * 30 + 5;
pt.y = (( pt.y)/ 30 ) * 30 + 5;
HDC hdc = GetDC(hwnd);
// 돌을 화면상에 그리는 함수 구현
DrawStone(hdc, pt.x, pt.y, BLACK);
ReleaseDC(hwnd, hdc);
// 4. board 배열 수정
// 5. 이겼는가?
// 6. 흰돌차례가 되도록 변수 수정..
}
return 0;
case WM_CREATE:
{
hPen = (HBITMAP)LoadImage(0, "Pan.bmp", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE);
hBlack = (HBITMAP)LoadImage(0, "black.bmp", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE);
hWhite = (HBITMAP)LoadImage(0, "white.bmp", IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE);
//--------------------------------------------------------------
RECT r = { 0, 0, 610, 610 };
// 원하는 클라이언트의 크기로 설정...
AdjustWindowRect(&r,
GetWindowLong(hwnd, GWL_STYLE), FALSE);
int cx = r.right - r.left ;
int cy = r.bottom - r.top ;
MoveWindow(hwnd, 0, 0, cx, cy, TRUE);
}
//----------------------------------------------------
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HDC memDC = CreateCompatibleDC(hdc);
HBITMAP old = (HBITMAP)SelectObject(memDC, hPen);
BitBlt(hdc, 0, 0, 610, 610, memDC, 0, 0, SRCCOPY);
SelectObject(memDC, old);
DeleteDC(memDC);
EndPaint(hwnd , &ps);
}
return 0;
case WM_RBUTTONDOWN:
return 0;
case WM_DESTROY:
//---------------------------------
DeleteObject(hPen);
DeleteObject(hBlack);
//---------------------------------
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nShowCmd)
{
// 1. 윈도우 클래스 만들기
WNDCLASS wc;
wc.cbWndExtra = 0;
wc.cbClsExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hIcon = LoadIcon(0, IDI_APPLICATION);
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc; // DefWindowProc;
wc.lpszClassName = "First";
wc.lpszMenuName = 0;
wc.style = 0;
// 2. 등록(레지스트리에)
RegisterClass(&wc);
// 3. 윈도우 창 만들기
HWND hwnd = CreateWindowEx( 0, // WS_EX_TOPMOST
"first", // 클래스 명
"Hello", // 캡션바 내용
WS_OVERLAPPEDWINDOW,
0 , 0, 100, 100, // 초기 위치
0, 0, // 부모 윈도우 핸들, 메뉴 핸들
hInstance, // WinMain의 1번째 파라미터 (exe 주소)
0); // 생성 인자
// 4. 윈도우 보여주기
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
// 5. Message
MSG msg;
while( GetMessage( &msg, 0, 0, 0 ) )
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}