Gui.rar

  • shangue
    了解作者
  • Visual C++
    开发工具
  • 4MB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 5
    下载次数
  • 2010-03-20 17:14
    上传日期
GUI练习代码,很精髓,强力推荐,与大家共享
Gui.rar
  • Gui
  • Debug
  • GUIPushButton.cpp
    0B
  • Gui.vcproj.zhangyue-PC.Administrator.user
    1.4KB
  • Gui.sln
    870B
  • GUIDialog.h
    4.1KB
  • Gui.suo
    47KB
  • Gui.ncb
    12.9MB
  • Gui.vcproj.F2686B2A88344A8.Administrator.user
    1.4KB
  • resource.h
    446B
  • Gui.aps
    17.2KB
  • vssver2.scc
    515B
  • IGuiManager.h
    1.9KB
  • Ui.bmp
    256.1KB
  • GUIStatic.h
    343B
  • GUIPushButton.h
    1.8KB
  • mssccprj.scc
    387B
  • IGUIElement.h
    5.9KB
  • Gui.vcproj.5792BF7E74944B4.Administrator.user
    1.4KB
  • Gui.vcproj
    4.5KB
  • GUIEdit.h
    862B
  • UIEvent.h
    958B
  • GuiTest.cpp
    6KB
  • Gui.exe
    168KB
  • Gui.rc
    1.4KB
  • back.bmp
    1.4MB
  • Gui.vcproj.ZHANGLITONG.Administrator.user
    1.4KB
内容介绍
#include <windows.h> #include <tchar.h> #include <stdio.h> #include <stdlib.h> #pragma comment(lib,"MSImg32.lib") #include "IGUIElement.h" #include "IGuiManager.h" #include "GUIPushButton.h" #include "GUIStatic.h" #include "GUIEdit.h" #include "GUIDialog.h" TCHAR* g_pStrClass = _T("AlphaBlend"); TCHAR* g_pStrTitile = _T("GUI"); bool TestClose(UIMessage& pClose) { MessageBox(NULL,0,0,0); return true; } bool DoubleClose(UIMessage& pClose) { MessageBox(NULL,_T("dsdsad"),0,0); return true; } class CDBBuffer { public: CDBBuffer(HDC hDC,int iWidth,int iHeight) { m_hDC = hDC; m_iWidth = iWidth; m_iHeight = iHeight; m_hMemDC = ::CreateCompatibleDC(hDC); m_hBmp = ::CreateCompatibleBitmap(hDC,iWidth,iHeight); SelectObject(m_hMemDC,m_hBmp); } ~CDBBuffer() { BitBlt(m_hDC,0,0,m_iWidth,m_iHeight,m_hMemDC,0,0,SRCCOPY); if (m_hMemDC != NULL) { DeleteDC(m_hMemDC); } if (m_hBmp != NULL) { DeleteObject(m_hBmp); } } inline operator HDC() { return m_hMemDC; } inline operator HBITMAP() { return m_hBmp; } private: HDC m_hDC; HDC m_hMemDC; HBITMAP m_hBmp; int m_iWidth; int m_iHeight; }; IGUIElement* g_pDlg = NULL; IGUIElement* g_pDlg1 = NULL; LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HBITMAP s_hBkbmp = NULL; static HDC s_hBkDC = NULL; static HBITMAP s_hAlphaBmp = NULL; static HDC s_hAplhaDC = NULL; UIMessage uiMsg; uiMsg.hWnd = hWnd; uiMsg.dwMessage = message; uiMsg.lParam = lParam; uiMsg.wParam = wParam; uiMsg.dwTime = GetTickCount(); GetCursorPos(&uiMsg.point); ScreenToClient(hWnd,&uiMsg.point); IGuiManager::Instance().DoMessage(&uiMsg);//消息响应 switch (message) { case WM_CREATE: { HDC hWndDC = GetDC(hWnd); s_hBkbmp = (HBITMAP)LoadImage(NULL,_T("back.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE); s_hBkDC = CreateCompatibleDC(hWndDC); SelectObject(s_hBkDC,s_hBkbmp); s_hAlphaBmp = (HBITMAP)LoadImage(NULL,_T("Ui.bmp"),IMAGE_BITMAP,0,0,LR_LOADFROMFILE); s_hAplhaDC = CreateCompatibleDC(hWndDC); SelectObject(s_hAplhaDC,s_hAlphaBmp); ReleaseDC(hWnd,hWndDC); IGuiManager::Instance().RegisterClass(_T("Button"),CGUIPushButton::Instance); IGuiManager::Instance().RegisterClass(_T("Static"),CGUIStatic::Instance); IGuiManager::Instance().RegisterClass(_T("Edit"),CGUIEdit::Instance); IGuiManager::Instance().RegisterClass(_T("Dialog"),CGUIDialog::Instance); g_pDlg = IGuiManager::Instance().CreateWindows(_T("Dialog"),_T("1"),NULL,s_hAplhaDC); g_pDlg1 = IGuiManager::Instance().CreateWindows(_T("Dialog"),_T("2"),NULL,s_hAplhaDC); IGUIElement* pCloseBtn = IGuiManager::Instance().CreateWindows(_T("Button"),_T("Close"),g_pDlg,s_hAplhaDC); IGUIElement* pCloseBtn1 = IGuiManager::Instance().CreateWindows(_T("Button"),_T("Close1"),g_pDlg,s_hAplhaDC); IGUIElement* pText = IGuiManager::Instance().CreateWindows(_T("Static"),_T("UserName:"),g_pDlg,s_hAplhaDC); IGUIElement* pEdit = IGuiManager::Instance().CreateWindows(_T("Edit"),_T("Edit:"),g_pDlg,s_hAplhaDC); RECT temp; SetRect(&temp,100,100,160,130); pCloseBtn->MoveWindow(temp); SetRect(&temp,150,150,210,180); pCloseBtn1->MoveWindow(temp); SetRect(&temp,50,50,100,80); pText->MoveWindow(temp); pText->SetWindowText(_T("用户名:")); SetRect(&temp,110,45,250,70); pEdit->MoveWindow(temp); RECT test; SetRect(&test,50,0,500,300); g_pDlg->MoveWindow(test); g_pDlg->SetWindowText(_T("测试对话框")); SetRect(&test,100,0,300,300); g_pDlg1->MoveWindow(test); SetTimer(hWnd,1,30,NULL); } break; case WM_PAINT: { PAINTSTRUCT ps; HDC hdc; hdc = BeginPaint(hWnd, &ps); { RECT rect; GetClientRect(hWnd,&rect); int iWidth = rect.right - rect.left; int iHeight = rect.bottom - rect.top; CDBBuffer memDC(hdc,iWidth,iHeight); BitBlt(memDC,0,0,800,600,s_hBkDC,0,0,SRCCOPY); IRender::Instance().m_hDC = memDC; g_pDlg1->Draw(&IRender::Instance()); g_pDlg->Draw(&IRender::Instance()); IGuiManager::Instance().DoIdel(&uiMsg);//消息响应 } EndPaint(hWnd, &ps); } break; case WM_KEYDOWN: { char szBuf[1024]; static int iCnt = 0; sprintf(szBuf,"Keydowns %d \n",iCnt++); OutputDebugStringA(szBuf); } break; case WM_MOUSEMOVE: { } break; case WM_TIMER: { InvalidateRect(hWnd,NULL,FALSE); } break; case WM_DESTROY: if (s_hBkDC) { DeleteDC(s_hBkDC); } if (s_hAplhaDC) { DeleteDC(s_hAplhaDC); } if (s_hAlphaBmp) { DeleteObject(s_hAlphaBmp); } if (s_hAlphaBmp) { DeleteObject(s_hAlphaBmp); } PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW |CS_DBLCLKS | CS_GLOBALCLASS; wcex.lpfnWndProc = WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = NULL; wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = g_pStrClass; wcex.hIconSm = NULL; return RegisterClassEx(&wcex); } int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { MSG msg; MyRegisterClass(hInstance); HWND hWnd = CreateWindow(g_pStrClass, g_pStrTitile, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int) msg.wParam; }
评论
    相关推荐