TBool CBrowserPicWindow::DoKeyEventL(TInt aKeyCode)
{
	TBool keyResult = ETrue;

	if(iOpenComplete)
	{
		switch(aKeyCode)
		{
		case KKeyCodeUp:
		case KKeyCodeDown:
			
			break;
		case KKeyCodeLeft:
			DoPopUpMenuCommand(EPopUp);
			break;
		case KKeyCodeRight:
			DoPopUpMenuCommand(EPopNext);
			break;
		case KOKKey:	
			DoPopUpMenuCommand(EPopScreenShow);
			break;
		case KLeftSoftKey:
			InitPopUpMenu();
			break;
		case KRightSoftKey:
			if (iFullScreenShow)
			{
				iFullScreenShow=false;
				
				SetShowRect(iMainEngine.ScreenLayout().WhiteBackgroundRect());

				iIsNormalWindow=true;

				ShowTitleBar();

				iMainEngine.RequestDraw();
			} 
			else
			{
				GoBackToParentWindow();
			}
			break;
		case '4':
			DoPopUpMenuCommand(EPopUp);
			break;
		case '6':
			DoPopUpMenuCommand(EPopNext);
			break;
		case '0':
			DoPopUpMenuCommand(EPopScreenShow);
			break;
		default:
			keyResult = EFalse;
			break;
		}
	}
	return keyResult;
}
void CBrowserPicWindow::ConstructL()
{
	ChangeButton();

	((CControlFactory&)iMainEngine.ControlFactory()).SetParentWindow(this);
	
	iTitleBar=iMainEngine.ControlFactory().CreateDefaultTitleBarL(_L(""));

	iShowControlText=EFalse;

	//不允许弹出0*#界面
	iCanPopUpWindow=EFalse;

	SetShowRect(iMainEngine.ScreenLayout().WhiteBackgroundRect());
}
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
	static int width;
	static int height;
	static int open = 0;

	static TCHAR fullPath[MAX_PATH];
	static TCHAR fileName[MAX_PATH];
	static char u8FullPath[MAX_PATH];

	static RECT windowRect;
	static RECT deskRect;
	static HWND deskHwnd;

	static int fullScreen = 0;
	static long windowStyle;

	static SDL_Window *sdlWindow = 0;
	static SDL_Renderer *sdlRenderer = 0;
	static SDL_Surface *sdlSurface = 0;
	static SDL_Texture *sdlTexture = 0;
	static SDL_Rect sdlShowRect;	//窗口中显示图像的具体区域

	switch (message) {
	case WM_CREATE:
		sdlWindow = SDL_CreateWindowFrom(hwnd);
		sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
		sdlSurface = SDL_LoadBMP("PictureViewer.bmp");
		sdlTexture = SDL_CreateTextureFromSurface(sdlRenderer, sdlSurface);
		SDL_FreeSurface(sdlSurface);
		break;
	case WM_SIZE:
		if (open == 0) {
			SDL_RenderClear(sdlRenderer);
			SDL_RenderCopy(sdlRenderer, sdlTexture, 0, 0);
			SDL_RenderPresent(sdlRenderer);
		}
		else {
			sdlShowRect = SetShowRect(hwnd, width, height);
			SDL_RenderClear(sdlRenderer);
			SDL_RenderCopy(sdlRenderer, sdlTexture, 0, &sdlShowRect);
			SDL_RenderPresent(sdlRenderer);
		}
		break;
	case WM_LBUTTONDBLCLK:
		if (!fullScreen) {
			windowStyle = GetWindowLong(hwnd, GWL_STYLE);
			GetWindowRect(hwnd, &windowRect);
			deskHwnd = GetDesktopWindow();
			GetWindowRect(deskHwnd, &deskRect);
			SetWindowLong(hwnd, GWL_STYLE, WS_CHILD);
			SetWindowPos(hwnd, HWND_TOP, 0, 0, deskRect.right, deskRect.bottom, SWP_SHOWWINDOW);
			fullScreen = 1;
		}
		else {
			SetWindowLong(hwnd, GWL_STYLE, windowStyle);
			MoveWindow(hwnd, windowRect.left, windowRect.top, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, true);
			fullScreen = 0;
		}
		break;
	case WM_LBUTTONDOWN:
		open = 1;
		SDL_DestroyTexture(sdlTexture);
		if (!OpenFile(hwnd, fullPath, fileName,&sdlShowRect)) {
			return -1;
		}
		WideCharToMultiByte(CP_UTF8,0, fullPath,-1, u8FullPath, sizeof(u8FullPath),0,0);
		sdlSurface = IMG_Load(u8FullPath);
		width = sdlSurface->w;
		height = sdlSurface->h;
		sdlShowRect = SetShowRect(hwnd, width, height);
		sdlTexture = SDL_CreateTextureFromSurface(sdlRenderer, sdlSurface);
		SDL_FreeSurface(sdlSurface);
		SDL_RenderClear(sdlRenderer);
		SDL_RenderCopy(sdlRenderer, sdlTexture, 0, &sdlShowRect);
		SDL_RenderPresent(sdlRenderer);
		break;
	case WM_CLOSE:
		SDL_DestroyTexture(sdlTexture);
		SDL_DestroyRenderer(sdlRenderer);
		SDL_DestroyWindow(sdlWindow);
		DestroyWindow(hwnd);
		break;
	case WM_DESTROY:
		SDL_Quit();
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hwnd, message, wParam, lParam);
	}
	return 0;
}