'Pocket PC SDK'에 해당되는 글 1건

  1. 2006/09/21 hancem Pocket PC SDK API를 이용한 원도우 생성

MFC 마법사를 이용한 원도우 생성은 불필요한 코드를 생성한다.

따라서 Pocket PC SDK의 API를 이용한 원도우 생성방법에 대하여 알아보자.

파일은 크게 헤더파일과 소스파일로 나누었다.

1. HelloCE.h
#define dim(x) (sizeof(x) / sizeof(x[0]))

struct decodeUINT {
UINT Code;
LRESULT (*Fxn)(HWND, UINT, WPARAM, LPARAM);
};

// 함수 선언
HWND InitInstance(HINSTANCE, LPWSTR, int);
int TermInstance(HINSTANCE, int);


// 원도우 프로시저
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);

// 메시지 헨들러
LRESULT DoPaintMain(HWND, UINT, WPARAM, LPARAM);
LRESULT DoDestoryMain(HWND, UINT, WPARAM, LPARAM);


2. HelloCE.cpp
#include <windows.h>

#include "HelloCE.h"

//
// 전역 데이터
//
const TCHAR szAppName[] = TEXT("HelloCE");
HINSTANCE hInst;

const struct decodeUINT MainMessage[] = {
WM_PAINT, DoPaintMain,
WM_DESTROY, DoDestoryMain
};

//
// 프로그램 시작점
//
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) {

MSG msg;
int rc = 0;
HWND hwndMain;

hwndMain = InitInstance(hInstance, lpCmdLine, nShowCmd);
if (hwndMain== 0) return 0x10;

while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return TermInstance(hInstance, msg.wParam);
}


//
// 인스턴스 초기화
//
HWND InitInstance(HINSTANCE hInstance, LPWSTR lpCmdLine, int nShowCmd) {
WNDCLASS wc;
HWND hWnd;

hInst = hInstance;

#if defined(WIN32_PLATFORM_PSPC)
// Pocket PC인 경우 단 하나의 인스턴스만 실행하게 함.
hWnd = FindWindow(szAppName, NULL);
if (hWnd) {
  SetForegroundWindow((HWND)(((DWORD)hWnd) | 0x01));
  return 0;
}
#endif

// 주 원도우 클래스 등록
wc.style = 0;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = NULL;
wc.cbWndExtra = NULL;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = szAppName;

if (RegisterClass(&wc) == 0) return 0;

hWnd = CreateWindow(szAppName,
TEXT("HelloCE"),
WS_VISIBLE | WS_CAPTION | WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);

if (!IsWindow(hWnd)) return 0;

ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);

return hWnd;

}

//
// 프로그램 소거
int TermInstance(HINSTANCE hInstance, int nDefRC) {
return nDefRC;
}

//
// 주 원도우 콜백 함수
//
LRESULT CALLBACK MainWndProc(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {

int i;

for (i=0; i<dim(MainMessage); i++) {
if (wMsg == MainMessage[i].Code) return (*MainMessage[i].Fxn)(hWnd, wMsg, wParam, lParam);
}

return DefWindowProc(hWnd, wMsg, wParam, lParam);

}

//
// WM_PAINT 메시지 처리
//
LRESULT DoPaintMain(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {

PAINTSTRUCT ps;
RECT rect;
HDC hdc;

GetClientRect(hWnd, &rect);

hdc = BeginPaint(hWnd, &ps);
DrawText (hdc, TEXT("Hello Windown CE"), -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

EndPaint(hWnd, &ps);
return 0;
}

//
// WM_DESTORY 메시지 처리
//
LRESULT DoDestoryMain(HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam) {
PostQuitMessage(0);
return 0;
}

2006/09/21 14:23 2006/09/21 14:23