www.pudn.com > PG20101.zip > MainWin.cpp


// 
//      ½d¨Òªº¥Dµøµ¡ 
// 
//		Copyright (c) 2000-2001 Chihiro.SAKAMOTO (HyperWorks) 
// 
#include "StdAfx.h" 
#include  
#include "Sample.h" 
#include "Window.h" 
#include "MainWin.h" 
#include "resource.h" 
 
// 
// ƒEƒC²£¥Íµøµ¡ªº«e¸m§@·~ 
// 
//	ƒXƒ^ƒC³]©w¼Ë¦¡»P¤j¤p 
// 
BOOL CMainWin::PreCreateWindow(CREATESTRUCT &cs) 
{ 
	cs.dwExStyle = WS_EX_CLIENTEDGE; 
	cs.style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; 
 
	// ƒN¨D¥Xµøµ¡¤j¤p 
	CRect	rect(0, 0, 640, 480); 
	::AdjustWindowRectEx(&rect, cs.style, TRUE, cs.dwExStyle); 
 
	int width = rect.Width(); 
	int height = rect.Height(); 
 
	// ¨D¥X¤u§@°Ï°ì¤j¤p 
	// ¤u§@°Ï¬O«ü°£¤F¡u¤u§@¦C¡v¥H¥~³¡¤À 
	// ªº¾ã­Óµe­± 
	CRect rcArea; 
	SystemParametersInfo(SPI_GETWORKAREA, NULL, &rcArea, NULL); 
 
	// ½Õ¾ã¬°²¾°Ê¨ì¤u§@°Ï°ìªº¥¿¤¤¥¡ 
	int	x = rcArea.left + (rcArea.Width() - width) / 2; 
	int	y = rcArea.top + (rcArea.Height() - height) / 2; 
 
	cs.x = x; 
	cs.y = y; 
	cs.cx = width; 
	cs.cy = height; 
	cs.lpszClass = "MainWindow"; 
 
	if (!Application->RegisterWndClass(cs.lpszClass, 
		CS_VREDRAW | CS_HREDRAW | CS_OWNDC, LoadCursor(NULL, IDC_ARROW), 
		(HBRUSH)::GetStockObject(BLACK_BRUSH), Application->LoadIcon(IDC_APPICON))) 
		return FALSE; 
	return TRUE; 
} 
 
// 
// °T®§³B²z 
// 
LRESULT CMainWin::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam) 
{ 
	switch (uMsg) { 
	  case WM_ERASEBKGND:		// ¥h­I´º 
		return FALSE;			// µL°Ê§@ 
 
	  default: 
		return CWindow::WindowProc(uMsg, wParam, lParam); 
	} 
	return 0L; 
} 
 
// 
// WM_CREATE ªº³B²z 
// 
BOOL CMainWin::OnCreate(CREATESTRUCT *cs) 
{ 
	LoadAccelTable(IDC_APPACCEL); 
 
	CFile	file("sample.bmp");	// ¶}±Ò½d¨ÒCG 
	if (!file || !ViewImage.LoadBMP(file)) { 
		MessageBox("µLªkŪ¨úCGÀÉ¡C"); 
		return FALSE; 
	} 
	return TRUE; 
} 
 
// 
// WM_PAINT ªº³B²z¡]­«·sø»s¡^ 
// 
void CMainWin::OnPaint() 
{ 
	CPaintDC	dc(this); 
 
	// Åã¥Ü 
	::SetDIBitsToDevice(dc, 0, 0, 
		ViewImage.Width(), ViewImage.Height(), 
		0, 0, 0, ViewImage.Height(), 
		ViewImage.GetBits(), 
		ViewImage.GetInfo(), 
		DIB_RGB_COLORS); 
} 
 
// 
// WM_COMMAND ªº³B²z¡]¿ï³æ³B²z¡^ 
// 
void CMainWin::OnCommand(UINT notifyCode, UINT id, HWND ctrl) 
{ 
	switch (id) { 
	  case ID_APP_EXIT:				// µ²§ô 
		SendMessage(WM_CLOSE); 
		break; 
 
	  default: 
		break; 
	} 
}