单机版游戏的设计与实现 第7页
6.3 KUIObject模块的实现
把字符串写入到UI的指定控件中主要用SetWindowText实现。
BOOL KUIObject::SetItemText(int nID, LPCSTR lpText)
{
HWND hItem = ::GetDlgItem(m_hWnd, nID); //跟据ID值得到控件的句柄
if(NULL == hItem)
{
return FALSE;
}
return ::SetWindowText(hItem, lpText);
}
把一个矩阵区域变成无效区,以便窗口重画
BOOL KUIObject::InvalidateSpace(RECT* rect)
{
BOOL isDefault = FALSE;
if (NULL == rect)
{
rect = new RECT;
::GetClientRect(m_hWnd, rect);
isDefault = TRUE;
}
::InvalidateRect(m_hWnd, rect, FALSE);
if (isDefault)
{
delete rect;
}
return TRUE;
}
设置窗口句柄
BOOL KUIObject::SetHWnd(HWND hWnd)
{
m_hWnd = hWnd;
return TRUE;
}
设置窗口标题
BOOL KUIObject::SetWndTitle(char* szTitle)
{
return ::SetWindowText(m_hWnd, szTitle);
}
把窗口移动到屏幕中心,并设置其大小
BOOL KUIObject::SetWindowCenter(int nWndWidth, int nWndHeight)
{
int nScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
int nScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
int nWndX = nScreenWidth / 2 - nWndWidth / 2;
int nWndY = nScreenHeight / 2 - nWndHeight / 2;
::MoveWindow(m_hWnd, nWndX, nWndY, nWndWidth, nWndHeight, TRUE);
return TRUE;
}
所有继承于本类的类,都可以登录这个全消息处理函数
LRESULT KUIObject::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return OnInited(hWnd, wParam, lParam);
case WM_CREATE:
return OnCreate(hWnd, wParam, lParam);
case WM_COMMAND:
return CmdProc(wParam, lParam);
case WM_MOUSEMOVE:
return OnMouseMove(wParam, lParam);
case WM_LBUTTONUP:
return OnLButtonUp(wParam, lParam);
case WM_LBUTTONDOWN:
return OnLButtonDown(wParam, lParam);
case WM_PAINT:
return OnPaint(wParam, lParam);
case WM_DESTROY:
return OnDestory(wParam, lParam);
default:
return OnDefWndProc(hWnd, message, wParam, lParam);
}
return FALSE;
}
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] 下一页
单机版游戏的设计与实现 第7页下载如图片无法显示或论文不完整,请联系qq752018766