MDI框架TabPane面板类的C++封装

MDI框架TabPane面板类的C++封装

把Tab控件做成一个MDI框架的边窗面板支持一条边的虚移动。

坐标的转换比较烦,搞得头都大了。

运行效果如图。

主要程序

XTabPane.h

#pragma once#include "xwnd.h"#define XTABPANE_ISIDE_TOP                0x01#define XTABPANE_ISIDE_BOTTOM        0x02#define XTABPANE_ISIDE_LEFT                0x04#define XTABPANE_ISIDE_RIGHT            0x08class CXTabPane :    public CXWnd{public:    CXTabPane(void);    ~CXTabPane(void);XDECLARE_DYNCREATE(CXTabPane)public:    HWND        m_hTab;    HWND        CreateTab (HWND hWndParent);            CXWnd* m_pMain;     HWND m_hMainFrame;    HWND m_hMainClient;    virtual BOOL PreCreateWindow(WNDCLASSEX &cs);    virtual int OnDestroy(HWND, UINT, WPARAM, LPARAM);    int OnCreate(HWND, UINT, WPARAM, LPARAM);    int OnSize(HWND, UINT, WPARAM, LPARAM);    int OnClose(HWND, UINT, WPARAM, LPARAM);    int OnNotify(HWND, UINT, WPARAM, LPARAM);    int OnTimer(HWND, UINT, WPARAM, LPARAM);    int OnLBDown(HWND, UINT, WPARAM, LPARAM);    int OnLBUp(HWND, UINT, WPARAM, LPARAM);    int OnMouseMove(HWND, UINT, WPARAM, LPARAM);    HDC m_hdc_mem;    HBITMAP m_hBitmap_mem;    int m_xPos, m_yPos;        int m_iMove;    int m_iSide;       //top, bottom,left, right  1,2,4,8    int InsertPage(TCHAR * tTitle, int iPos,int iImage, HWND hWndPage);    int SetCurTab(int iItem);    int DrawMoveBar(HDC hdc, int left, int top, int right, int bottom);    XDECLARE_MESSAGE_MAP()};

XTabPane.cpp

#include "StdAfx.h"#include "XTabPane.h"XIMPLEMENT_DYNCREATE(CXTabPane, CXWnd)    XBEGIN_MESSAGE_MAP(CXTabPane, CXWnd)    XON_MESSAGE(WM_CREATE, OnCreate)    XON_MESSAGE(WM_SIZE, OnSize)    XON_MESSAGE(WM_CLOSE, OnClose)    XON_MESSAGE(WM_NOTIFY, OnNotify)    XON_MESSAGE(WM_TIMER, OnTimer)    XON_MESSAGE(WM_LBUTTONDOWN, OnLBDown)    XON_MESSAGE(WM_LBUTTONUP, OnLBUp)    XON_MESSAGE(WM_MOUSEMOVE, OnMouseMove)XEND_MESSAGE_MAP()CXTabPane::CXTabPane(){    wcscpy_s(szWindowClass,_T("XTabPane"));                                // The title bar text    wcscpy_s(szTitle,_T("XTabPane"));    m_iMove = 0;}CXTabPane::~CXTabPane(void){}HWND CXTabPane::CreateTab (HWND hWndParent) {    HWND hWndTab;         InitCommonControls();           hWndTab = CreateWindow(WC_TABCONTROL, NULL,         WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE|TCS_BOTTOM,  //TCS_BOTTOM        0, 0, 0,0,         hWndParent, (HMENU)IDM_VIEW_Tab1, m_hInst, NULL);     if (hWndTab == NULL)    {         return NULL;     }    HIMAGELIST hImageList;    hImageList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK,  15, 15);             //size 16x16  X15     for(unsigned int i = 0 ; i < 15; i++)    {        HICON  hIcon = LoadIcon(m_hInst, MAKEINTRESOURCE(IDI_ICON1 + i));        ImageList_AddIcon(hImageList, hIcon);        DestroyIcon(hIcon);    }    SendMessage(hWndTab, TCM_SETIMAGELIST, 0, (LPARAM)hImageList);
return hWndTab; }BOOL CXTabPane::PreCreateWindow(WNDCLASSEX &cs) { cs.style &= ~CS_HREDRAW; // OnSize 没必要刷新 cs.style &= ~CS_VREDRAW; return TRUE;}int CXTabPane::OnCreate(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ long style; style = GetWindowLong(hWnd,GWL_STYLE); // unsize style &= ~WS_THICKFRAME; SetWindowLong(hWnd, GWL_STYLE,style ); m_hTab = CreateTab(hWnd); return 1;}int CXTabPane::InsertPage(TCHAR * tTitle, int iPos,int iImage, HWND hWndPage){ TCITEM tie; tie.mask = TCIF_TEXT | TCIF_IMAGE|TCIF_PARAM; tie.iImage = iImage; tie.pszText = tTitle; tie.lParam = (LPARAM)hWndPage; if(TabCtrl_InsertItem(m_hTab, iPos, &tie) == -1) { return -1; } RECT rt; int sel = TabCtrl_GetCurSel(m_hTab); GetClientRect(m_hTab, &rt); TabCtrl_AdjustRect(m_hTab, FALSE, &rt); MoveWindow((HWND) tie.lParam, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE); return 1;}int CXTabPane::SetCurTab( int iItem) //for hide other page{ int i; int iItemCount; TCITEM tie; iItemCount = TabCtrl_GetItemCount(m_hTab); if(iItemCount < 0) return -1; if(iItem > iItemCount) iItem = 0; tie.mask = TCIF_PARAM; for( i = 0; i< iItemCount; i++) { if(TabCtrl_GetItem(m_hTab, i, &tie) == -1) { return -1; } if(i == iItem) { ShowWindow((HWND) tie.lParam, SW_SHOW); } else { ShowWindow((HWND) tie.lParam, SW_HIDE); } } TabCtrl_SetCurSel(m_hTab, iItem); return 1;}int CXTabPane::OnTimer(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ return 1;}int CXTabPane::OnSize(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ int cxClient,cyClient; RECT rt; int iItem; int iItemCount; TCITEM tie; cxClient = LOWORD (lParam); cyClient = HIWORD (lParam); switch(m_iSide) { case 1: //top MoveWindow(m_hTab, 0, 0, cxClient, cyClient-6, TRUE); break; case 2: //down MoveWindow(m_hTab, 0, 6, cxClient, cyClient-6, TRUE); break; case 4: //left MoveWindow(m_hTab, 0, 0, cxClient-6, cyClient, TRUE); break; case 8: //right MoveWindow(m_hTab, 6, 0, cxClient-6, cyClient, TRUE); break; default: // unsize MoveWindow(m_hTab, 0, 0, cxClient, cyClient, TRUE); } iItem = TabCtrl_GetCurSel(m_hTab); if(iItem <0 ) { return CXWnd::OnSize( hWnd, message, wParam, lParam); } GetClientRect(m_hTab, &rt); //NEED TabCtrl_AdjustRect(m_hTab, FALSE, &rt); // Get Page iItemCount = TabCtrl_GetItemCount(m_hTab); tie.mask = TCIF_PARAM; for (iItem = 0; iItem< iItemCount; iItem++) { TabCtrl_GetItem(m_hTab, iItem, &tie); MoveWindow((HWND) tie.lParam, rt.left, rt.top, rt.right-rt.left, rt.bottom-rt.top, TRUE); } return CXWnd::OnSize( hWnd, message, wParam, lParam);}int CXTabPane::OnNotify(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ TCITEM tie; int iItem; RECT rt; LPNMHDR lphr = (LPNMHDR)lParam; if (wParam ==IDM_VIEW_Tab1) { switch (lphr->code) { case TCN_SELCHANGING: iItem = TabCtrl_GetCurSel(m_hTab); tie.mask = TCIF_PARAM; TabCtrl_GetItem(m_hTab, iItem, &tie); ShowWindow((HWND) tie.lParam, SW_HIDE); break; case TCN_SELCHANGE: iItem = TabCtrl_GetCurSel(m_hTab); tie.mask = TCIF_PARAM; TabCtrl_GetItem(m_hTab, iItem, &tie); ShowWindow((HWND) tie.lParam, SW_SHOW); break; } } return ::DefWindowProc(hWnd, message, wParam, lParam); }int CXTabPane::OnClose(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ return 0;}int CXTabPane::OnDestroy(HWND, UINT, WPARAM, LPARAM){ m_hWnd = NULL; //closeall no OnClose, only OnDestroy, this is virtual return 1;}int CXTabPane::DrawMoveBar(HDC hdc, int left, int top, int right, int bottom){ POINT pt; MoveToEx(hdc, left, top,&pt); LineTo(hdc, right, top); LineTo(hdc, right, bottom); LineTo(hdc, left, bottom); LineTo(hdc, left, top); MoveToEx(hdc, (left + right)/2, top,&pt); LineTo(hdc, (left + right)/2, bottom); MoveToEx(hdc, left, (top+bottom)/2,&pt); LineTo(hdc, right, (top+bottom)/2); return 1;}int CXTabPane::OnLBDown(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ HWND hWndFrame; HDC hdc_Frame; RECT rt; POINT pt; int iWidth; int iHigh; int iTop; int iLeft; hWndFrame = GetParent(hWnd); //frame hdc_Frame = GetDC(hWndFrame); GetWindowRect(hWnd, &rt); iWidth = rt.right - rt.left; iHigh = rt.bottom - rt.top; iTop = rt.top; iLeft = rt.left; SetCapture(hWnd); switch(m_iSide) { case XTABPANE_ISIDE_TOP: SetCursor(LoadCursor(NULL, IDC_SIZENS)); break; case XTABPANE_ISIDE_BOTTOM: SetCursor(LoadCursor(NULL, IDC_SIZENS)); pt.x= rt.left; pt.y = rt.top; ScreenToClient(hWndFrame, &pt); // 窗口右上角的屏幕坐标,转换为框架Client坐标 iTop = pt.y; //保存绘图点, iLeft = pt.x; //保存绘图点, m_hBitmap_mem = CreateCompatibleBitmap(hdc_Frame, iWidth, 6); //allot the space app break; case XTABPANE_ISIDE_LEFT: SetCursor(LoadCursor(NULL, IDC_SIZEWE)); //need pt.x= rt.right; pt.y = rt.top; ScreenToClient(hWndFrame, &pt); // 窗口右上角的屏幕坐标,转换为框架Client坐标 iTop = pt.y; //保存绘图点, m_hBitmap_mem = CreateCompatibleBitmap(hdc_Frame, 6, iHigh); //allot the space app break; case XTABPANE_ISIDE_RIGHT: SetCursor(LoadCursor(NULL, IDC_SIZEWE)); //need pt.x= rt.left; pt.y = rt.top; ScreenToClient(hWndFrame, &pt); // 窗口左上角的屏幕坐标,转换为框架Client坐标 iTop = pt.y; //保存绘图点, m_hBitmap_mem = CreateCompatibleBitmap(hdc_Frame, 6, iHigh); //allot the space app break; default: break; } m_hdc_mem = CreateCompatibleDC(hdc_Frame); SelectObject(m_hdc_mem, m_hBitmap_mem); GetCursorPos(&pt); //Screen Position ScreenToClient(hWndFrame, &pt); // Frame Position m_yPos = pt.y; m_xPos = pt.x; //save the Frame Positon GetClientRect(hWndFrame, &rt); switch(m_iSide) { case XTABPANE_ISIDE_TOP: case XTABPANE_ISIDE_BOTTOM: BitBlt(m_hdc_mem,0,0,iWidth,6, hdc_Frame, iLeft, m_yPos -3, SRCCOPY); //save DrawMoveBar(hdc_Frame, iLeft, m_yPos-2, iLeft+iWidth, m_yPos+2); break; case XTABPANE_ISIDE_LEFT: case XTABPANE_ISIDE_RIGHT: BitBlt(m_hdc_mem,0,0, 6, iHigh, hdc_Frame, m_xPos -3, iTop, SRCCOPY); //save DrawMoveBar(hdc_Frame, m_xPos-2, iTop,m_xPos+2, iTop+iHigh); break; default: break; } m_iMove =1; ReleaseDC(hWndFrame, hdc_Frame); return 1;}int CXTabPane::OnMouseMove(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ HWND hWndFrame; HDC hdc_Frame; RECT rt; POINT pt; int Mouse_y; int iWidth; int Mouse_x; int iHigh; int iTop; int iLeft; Mouse_y = HIWORD(lParam); Mouse_x = LOWORD(lParam); //Plane Position GetClientRect(hWnd, &rt); switch(m_iSide) { case XTABPANE_ISIDE_TOP: if((rt.bottom-Mouse_y)<6) SetCursor(LoadCursor(NULL, IDC_SIZENS)); break; case XTABPANE_ISIDE_BOTTOM: if(Mouse_y < 6) SetCursor(LoadCursor(NULL, IDC_SIZENS)); break; case XTABPANE_ISIDE_LEFT: if((rt.right -Mouse_x)<6) SetCursor(LoadCursor(NULL, IDC_SIZEWE)); break; case XTABPANE_ISIDE_RIGHT: if(Mouse_x< 6) SetCursor(LoadCursor(NULL, IDC_SIZEWE)); break; default: break; } if(m_iMove ==0) // no Click capture { return 0; } SetCapture(hWnd); GetWindowRect(hWnd, &rt); iWidth = rt.right - rt.left; iHigh = rt.bottom - rt.top; iTop = rt.top; iLeft = rt.left; hWndFrame = GetParent(hWnd); hdc_Frame = GetDC(hWndFrame); //Frame DC switch(m_iSide) { case XTABPANE_ISIDE_TOP: if((rt.bottom-Mouse_y)<6) SetCursor(LoadCursor(NULL, IDC_SIZENS)); break; case XTABPANE_ISIDE_BOTTOM: pt.x= rt.left; pt.y = rt.top; ScreenToClient(hWndFrame, &pt); // 窗口右上角的屏幕坐标,转换为框架Client坐标 iTop = pt.y; //保存绘图点, iLeft = pt.x; BitBlt(hdc_Frame, iLeft, m_yPos - 3, iWidth, 6, m_hdc_mem, 0, 0, SRCCOPY); // restore yPos is old break; case XTABPANE_ISIDE_LEFT: pt.x= rt.right; pt.y = rt.top; ScreenToClient(hWndFrame, &pt); // 窗口右上角的屏幕坐标,转换为框架Client坐标 iTop = pt.y; //保存绘图点, BitBlt(hdc_Frame, m_xPos -3, iTop, 6, iHigh, m_hdc_mem, 0, 0, SRCCOPY); // restore yPos is old break; case XTABPANE_ISIDE_RIGHT: pt.x= rt.left; pt.y = rt.top; ScreenToClient(hWndFrame, &pt); // 窗口左上角的屏幕坐标,转换为框架Client坐标 iTop = pt.y; //保存绘图点, BitBlt(hdc_Frame, m_xPos -3, iTop, 6, iHigh, m_hdc_mem, 0, 0, SRCCOPY); // restore yPos is old break; default: break; } GetCursorPos(&pt); //Screen Position ScreenToClient(hWndFrame, &pt); // Frame Position m_yPos = pt.y; m_xPos = pt.x; //save the Frame Positon switch(m_iSide) { case XTABPANE_ISIDE_TOP: case XTABPANE_ISIDE_BOTTOM: BitBlt(m_hdc_mem, 0,0,iWidth,6, hdc_Frame,iLeft,m_yPos-3, SRCCOPY); //save Frame yPos is new DrawMoveBar(hdc_Frame, iLeft, m_yPos-2, iLeft+iWidth, m_yPos+2); break; case XTABPANE_ISIDE_LEFT: case XTABPANE_ISIDE_RIGHT: BitBlt(m_hdc_mem,0,0, 6, iHigh, hdc_Frame, m_xPos -3, iTop, SRCCOPY); //save Frame xPos is new DrawMoveBar(hdc_Frame, m_xPos-2, iTop,m_xPos+2, iTop+iHigh); break; default: break; } ReleaseDC(hWndFrame,hdc_Frame); return 1;}int CXTabPane::OnLBUp(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ HWND hWndFrame; HDC hdc_Frame; RECT rt; POINT pt; int Mouse_x; int Mouse_y; int iWidth; int iHigh; int iTop; int iLeft; hWndFrame = GetParent(hWnd); //frame hdc_Frame = GetDC(hWndFrame); GetWindowRect(hWnd, &rt); iWidth = rt.right - rt.left; iHigh = rt.bottom - rt.top; iTop = rt.top; iLeft = rt.left; ReleaseCapture(); m_iMove =0; switch(m_iSide) { case XTABPANE_ISIDE_TOP: if((rt.bottom-Mouse_y)<6) SetCursor(LoadCursor(NULL, IDC_SIZENS)); break; case XTABPANE_ISIDE_BOTTOM: pt.x= rt.left; pt.y = rt.top; ScreenToClient(hWndFrame, &pt); // 窗口右上角的屏幕坐标,转换为框架Client坐标 iTop = pt.y; //保存绘图点, iLeft = pt.x; BitBlt(hdc_Frame, iLeft, m_yPos - 3, iWidth, 6, m_hdc_mem, 0, 0, SRCCOPY); // restore yPos is old SendMessage(hWndFrame,WM_COMMAND, IDM_WM_RESIZE, (LPARAM) m_yPos); pt.x= rt.left; pt.y = rt.bottom; ScreenToClient(hWndFrame, &pt); MoveWindow(hWnd, pt.x, m_yPos, iWidth, pt.y-m_yPos, TRUE); //Client 没变,需要OnSize设置Client SendMessage(hWndFrame,WM_COMMAND, IDM_WM_REALIGN, 0); //重排窗口 break; case XTABPANE_ISIDE_LEFT: pt.x= rt.right; pt.y = rt.top; ScreenToClient(hWndFrame, &pt); // 窗口右上角的屏幕坐标,转换为框架Client坐标 iTop = pt.y; //保存绘图点, BitBlt(hdc_Frame, m_xPos -3, iTop, 6, iHigh, m_hdc_mem, 0, 0, SRCCOPY); // restore yPos is old pt.x= rt.left; pt.y = rt.top; ScreenToClient(hWndFrame, &pt); MoveWindow(hWnd, pt.x, pt.y, m_xPos - pt.x, iHigh, TRUE); //Client 没变,需要OnSize设置Client SendMessage(hWndFrame,WM_COMMAND, IDM_WM_REALIGN, 0); //重排窗口 break; case XTABPANE_ISIDE_RIGHT: pt.x= rt.left; pt.y = rt.top; ScreenToClient(hWndFrame, &pt); // 窗口左上角的屏幕坐标,转换为框架Client坐标 iTop = pt.y; //保存绘图点, BitBlt(hdc_Frame, m_xPos -3, iTop, 6, iHigh, m_hdc_mem, 0, 0, SRCCOPY); // restore yPos is old pt.x= rt.right; pt.y = rt.top; ScreenToClient(hWndFrame, &pt); MoveWindow(hWnd, m_xPos, pt.y, pt.x - m_xPos, iHigh, TRUE); //Client 没变,需要OnSize设置Client SendMessage(hWndFrame,WM_COMMAND, IDM_WM_REALIGN, 0); //重排窗口 break; default: break; } ReleaseDC(hWndFrame,hdc_Frame); DeleteDC(m_hdc_mem); DeleteObject(m_hBitmap_mem); return 1;}

在框架中使用面板类:

XMDIFrameEx.h

#pragma once#include "xwnd.h"#include "stdio.h"#include "xmdiframe.h"#include "XTabPane.h"#include "PrjTree.h"#include "MsgBox.h"#include "StrBox.h"#include "Report.h"class CXMDIFrameEx :    public CXMDIFrame{public:    CXMDIFrameEx(void);    ~CXMDIFrameEx(void);    XDECLARE_DYNCREATE(CXMDIFrameEx)public:    HWND        m_hStatusBar;    HWND        m_hWndToolBar;    HWND        m_hWndToolBarWork;    HWND        m_hWndComboBox;    HWND        m_hWndReBar;    HWND        m_hWndPB;     int         m_StatusBarHight;    int         m_ToolBarHight;        HWND CreateMainToolbar(HWND hWnd);    HWND CreateToolbarWork(HWND hWnd);    HWND CreateToolbarCombo(HWND hWnd);    HWND CreateComboBox(HWND hWnd);    HWND CreateMainStatusbar(HWND hWnd);    HWND CreateRebar(HWND hwndOwner);        int OnNotify(HWND, UINT, WPARAM, LPARAM);    int OnReAlign(HWND, UINT, WPARAM, LPARAM);        int OnCreate(HWND, UINT, WPARAM, LPARAM);    int OnSize(HWND, UINT, WPARAM, LPARAM);    int OnAbout(HWND, UINT, WPARAM, LPARAM);    int OnTest2(HWND, UINT, WPARAM, LPARAM);    virtual int OnTest1(HWND, UINT, WPARAM, LPARAM);     int Test();     RECT        m_rtAreaClient;  //xgz for panel     HDC hdc_mem;     HBITMAP hBitmap_mem;     int xPos, yPos;         int m_BottomPanelHight;     int m_PLeftWidth;     int m_PRightWidth;      CXTabPane* m_pTabPaneLeft;      CXTabPane* m_pTabPaneRight;      CXTabPane* m_pTabPaneBottom;      CPrjTree*  m_pPrjTree;       CPrjTree*  m_pPrjTree2;       CMsgBox*  m_pMsg;       CStrBox*  m_pStrBox;       CReport*  m_pReport;        XDECLARE_MESSAGE_MAP()};

XMDIFrameEx.cpp

#include "StdAfx.h"#include "XMDIFrameEx.h"#include "XMDIView.h"XIMPLEMENT_DYNCREATE(CXMDIFrameEx, CXMDIFrame)XBEGIN_MESSAGE_MAP(CXMDIFrameEx, CXMDIFrame)    XON_MESSAGE(WM_CREATE, OnCreate)    XON_MESSAGE(WM_SIZE, OnSize)    XON_MESSAGE(WM_NOTIFY, OnNotify)    XON_COMMAND(IDM_ABOUT,  OnAbout)    XON_COMMAND(IDM_FILE_NEWHELLO,  OnNew)    XON_COMMAND(IDM_TEST_TEST2,  OnTest2)    XON_COMMAND(IDM_TEST_TEST1,  OnTest1)    XON_COMMAND(IDM_WM_REALIGN,  OnSize)XEND_MESSAGE_MAP()CXMDIFrameEx::CXMDIFrameEx(void){    wcscpy_s(szWindowClass,_T("XMDIFrameEx"));                        // The title bar text    wcscpy_s(szTitle,_T("XMDIFrameEx"));                                    // The title bar text    m_hWnd = NULL;    m_hWndClient = NULL;   //xgz  important for msg loop            m_pTabPaneLeft = new CXTabPane();    m_pTabPaneRight = new CXTabPane();    m_pTabPaneBottom = new CXTabPane();    m_pPrjTree = new CPrjTree();    m_pPrjTree2 = new CPrjTree();    m_pMsg = new CMsgBox();     m_pStrBox = new CStrBox();     m_pReport = new CReport(); }CXMDIFrameEx::~CXMDIFrameEx(void){    delete m_pPrjTree;    delete m_pPrjTree2;    delete m_pMsg;    delete m_pStrBox;    delete m_pReport;        delete m_pTabPaneLeft;    delete m_pTabPaneRight;    delete m_pTabPaneBottom;}HWND CXMDIFrameEx::CreateMainStatusbar(HWND hWnd){    int Rightend[3];    RECT rt;    GetClientRect(hWnd,&rt);        HWND hWndStatusBar = CreateWindowEx(0,     STATUSCLASSNAME,  _T(""),        WS_CHILD |WS_VISIBLE|SBS_SIZEGRIP,        0, 0, 0, 0,        hWnd,        (HMENU)IDC_MAINSTATUSBAR,        m_hInst,        NULL);    if(!hWndStatusBar)        return NULL;    Rightend[0] = rt.right/2;    Rightend[1] = rt.right*3/4;    Rightend[2] = rt.right;    //set statusbar to three segment    SendMessage(hWndStatusBar,SB_SETPARTS,(WPARAM)3,(LPARAM)Rightend);    MoveWindow(hWndStatusBar, 0,  0, 0, 0,TRUE);     //TextOut in statusbar    SendMessage(hWndStatusBar, SB_SETTEXT, 0, (long)TEXT("Status 0"));    SendMessage(hWndStatusBar, SB_SETTEXT, 1, (long)TEXT("========test====="));    SendMessage(hWndStatusBar, SB_SETTEXT, 2, (long)TEXT("Step 2"));     HWND hWndStatic = CreateWindow(TEXT("static"),NULL,        WS_CHILD|WS_BORDER|WS_VISIBLE|ES_CENTER,        0,0,0,0,        hWndStatusBar, (HMENU) 0, m_hInst, NULL);    MoveWindow(hWndStatic,100,5,90,20,TRUE);        SetWindowText(hWndStatic, _T("Static"));    HWND hWndEdit = CreateWindow(TEXT("edit"),NULL,        WS_CHILD|WS_BORDER|WS_VISIBLE,        0,0,0,0,        hWndStatusBar, (HMENU) 0, m_hInst, NULL);        MoveWindow(hWndEdit,200,5,90,20,TRUE);        m_hWndPB = CreateWindowEx( 0,PROGRESS_CLASS,NULL,                        WS_CHILD | WS_VISIBLE,                        0,0,0,0,            //位置和大小在WM_SIZE中设置                       hWndStatusBar,                     (HMENU)0,  m_hInst,   NULL);    MoveWindow(m_hWndPB,300, 5,90,20,TRUE);             SendMessage( m_hWndPB, PBM_SETRANGE,   (WPARAM)0, (LPARAM)(MAKELPARAM(0,100)) );//设置进度条的范围    SendMessage( m_hWndPB, PBM_DELTAPOS,   (WPARAM) 50, (LPARAM)0 );//设置进度条的位置    return hWndStatusBar;}HWND CXMDIFrameEx::CreateMainToolbar(HWND hWnd){    TBBUTTON tbButton[] = {        { STD_FILENEW,  IDM_FILE_NEWHELLO, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { STD_FILEOPEN, IDM_TEST_TEST2, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { STD_FILESAVE, IDM_TEST_TEST1, TBSTATE_ENABLED , TBSTYLE_BUTTON , 0L, 0},        { STD_HELP, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, -1},        { STD_FIND, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { STD_UNDO, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { STD_REDOW, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, -1},        { STD_COPY, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { STD_PASTE, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { STD_CUT, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { STD_DELETE, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { STD_FILESAVE, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { STD_PROPERTIES, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { STD_FIND, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { STD_REPLACE, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { STD_PRINT, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { STD_FILESAVE, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { STD_FILESAVE, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { STD_PRINTPRE, IDM_EXIT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0}    };        HINSTANCE hLib = (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE); //It can be other DLL,here same as m_hInst            HWND hWndToolbar = CreateWindowEx(0,     TOOLBARCLASSNAME,    _T(""),        TBSTYLE_FLAT|WS_CHILD |WS_VISIBLE|TBSTYLE_TOOLTIPS |CCS_NORESIZE| CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_NOPARENTALIGN, //for rebar         0,0, 0,0,        hWnd,    (HMENU) IDC_MAINTOOLSBAR,    m_hInst, NULL);        if(!hWndToolbar)        return NULL;    SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);    SendMessage(hWndToolbar, TB_SETEXTENDEDSTYLE, 0, (LPARAM)(DWORD)(TBSTYLE_EX_DRAWDDARROWS));    TBADDBITMAP tbBitmap1;    tbBitmap1.hInst = HINST_COMMCTRL;    tbBitmap1.nID = IDB_STD_SMALL_COLOR;    SendMessage(hWndToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbBitmap1);        SendMessage(hWndToolbar, TB_SETBITMAPSIZE, 0, (LPARAM)MAKELONG(16, 16)); //size 16x16    SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0);    SendMessage(hWndToolbar, TB_ADDBUTTONS, 15, (LONG) &tbButton);   //add 6 button        return hWndToolbar;}HWND CXMDIFrameEx::CreateToolbarWork(HWND hWnd){    TBBUTTON tbButton[] = {        { 7,  IDM_FILE_NEWHELLO, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { 8, IDM_TEST_TEST2, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { 9, IDM_TEST_TEST1, TBSTATE_ENABLED , TBSTYLE_BUTTON , 0L, 0},        { 10, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, -1},        { 4, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { 5, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { 6, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, -1},        { 7, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { 8, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { 9, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},        { 10, IDM_EXIT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0}    };        HINSTANCE hLib = (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE); //It can be other DLL,here same as m_hInst    HWND hWndToolbar = CreateWindowEx(0,     TOOLBARCLASSNAME,    _T(""),        TBSTYLE_FLAT|WS_CHILD |WS_VISIBLE|TBSTYLE_TOOLTIPS |CCS_NORESIZE| CCS_ADJUSTABLE|CCS_NODIVIDER|CCS_NOPARENTALIGN, //for rebar         0,0, 0,0,        hWnd,    (HMENU) IDC_TOOLSBARWORK,    m_hInst, NULL);    if(!hWndToolbar)        return NULL;    SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);    SendMessage(hWndToolbar, TB_SETEXTENDEDSTYLE, 0, (LPARAM)(DWORD)(TBSTYLE_EX_DRAWDDARROWS));        HIMAGELIST hImageList=ImageList_Create(16,16,ILC_COLOR16,1,10);        HBITMAP hBitMap=LoadBitmap(m_hInst,MAKEINTRESOURCE(IDB_BITMAP1));        ImageList_Add(hImageList,hBitMap,NULL);        DeleteObject(hBitMap);        SendMessage(hWndToolbar, TB_SETIMAGELIST, 0, (LPARAM)hImageList);    SendMessage(hWndToolbar, TB_SETBITMAPSIZE, 0, (LPARAM)MAKELONG(16, 16)); //size 16x16    SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0);    SendMessage(hWndToolbar, TB_ADDBUTTONS, 4, (LONG) &tbButton);   //add 4 button
return hWndToolbar;}HWND CXMDIFrameEx::CreateComboBox(HWND hWnd){ HWND hwndCombo; TCHAR *szStrings[] = {_T("Default"), _T("Random"), _T("Repeat")}; // Create the combo box and add it to the toolbar. hwndCombo = CreateWindowEx (0L, // no extended styles _T("COMBOBOX"), // class name _T(""), // default text WS_CHILD | WS_BORDER | WS_VISIBLE | CBS_HASSTRINGS | CBS_DROPDOWN, // styles and defaults 0, 0, 0, 250, // only list size, position no need in rebar hWnd, (HMENU)IDM_COMBO, m_hInst, NULL); if (hwndCombo) { // Add strings to the combo box. for (int idx = 0; idx < sizeof szStrings / sizeof szStrings[0]; idx++) SendMessage (hwndCombo, CB_INSERTSTRING, (WPARAM)(-1), (LPARAM)szStrings[idx]); } MoveWindow(hwndCombo, 0, 200, 200, 20, TRUE); //strange return hwndCombo;}HWND CXMDIFrameEx::CreateRebar(HWND hwndOwner){ REBARINFO rbi; REBARBANDINFO rbBand; RECT rc; HWND hwndTB, hwndRB, hwndCB; DWORD dwBtnSize; //InitCommonControls(); hwndRB = CreateWindowEx(WS_EX_TOOLWINDOW, REBARCLASSNAME, NULL, WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|WS_CLIPCHILDREN | CCS_NODIVIDER , 0,0,0,0, hwndOwner, NULL, m_hInst, NULL); if(!hwndRB) return NULL; // Initialize and send the REBARINFO structure. rbi.cbSize = sizeof(REBARINFO); // Required when using this rbi.fMask = 0; rbi.himl = (HIMAGELIST)NULL; if(!SendMessage(hwndRB, RB_SETBARINFO, 0, (LPARAM)&rbi)) return NULL; // Initialize structure members that both bands will share. rbBand.cbSize = sizeof(REBARBANDINFO); // Required rbBand.fMask = RBBIM_COLORS | RBBIM_TEXT | RBBIM_BACKGROUND |RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE |RBBIM_SIZE ; rbBand.fStyle = RBBS_CHILDEDGE | RBBS_FIXEDBMP | RBBS_GRIPPERALWAYS; //| RBBS_FIXEDSIZE|RBBS_BREAK; rbBand.hbmBack = NULL; //rbBand.hbmBack = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP2)); //backpicture rbBand.fMask = RBBIM_SIZE | RBBIM_STYLE| RBBIM_CHILD |RBBIM_CHILDSIZE| RBBIM_TEXT |RBBIM_COLORS; dwBtnSize = (DWORD) SendMessage(m_hWndToolBar, TB_GETBUTTONSIZE, 0,0); // Set values unique to the band with the toolbar. rbBand.lpText = _T("TB"); rbBand.hwndChild = m_hWndToolBar; rbBand.cxMinChild = 100; rbBand.cyMinChild = HIWORD(dwBtnSize); rbBand.cx = 500; rbBand.clrFore = RGB(250,250,250); rbBand.clrBack = RGB(0,0,200); rbBand.fMask = rbBand.fMask & ~RBBIM_COLORS &~ RBBIM_TEXT ; //no need bk color and TEXT SendMessage(hwndRB, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand); // Add the band that has the toolbar. rbBand.hwndChild = m_hWndToolBarWork; rbBand.cxMinChild = 200; rbBand.cyMinChild = 20; //rbBand.cyChild = 50; rbBand.cx = 200; rbBand.clrFore = RGB(250,250,0); rbBand.clrBack = RGB(100,0,0); rbBand.fStyle = rbBand.fStyle |RBBS_FIXEDSIZE; //fixed on right rbBand.lpText = _T("RUN"); rbBand.fMask = rbBand.fMask | RBBIM_TEXT ; // add TEXT SendMessage(hwndRB, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand); hwndCB = CreateWindow(_T("Button"),_T("Button"), BS_PUSHBUTTON|WS_CHILD, 0,0,50,20, hwndOwner, NULL,m_hInst,NULL); // Set values unique to the band with the combo box. GetWindowRect(hwndCB, &rc); rbBand.lpText = _T("Bu1"); rbBand.hwndChild = hwndCB; rbBand.cxMinChild = 100; rbBand.cyMinChild = rc.bottom - rc.top; rbBand.cx = 100; SendMessage(hwndRB, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand); return (hwndRB);}int CXMDIFrameEx::OnCreate(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ CLIENTCREATESTRUCT clientcreate; clientcreate.hWindowMenu = m_hMenuWindow; clientcreate.idFirstChild = IDM_FIRSTCHILD; //xgz key for active star m_hWndClient = CreateWindow(TEXT("MDICLIENT"), NULL, WS_CHILD|WS_CLIPCHILDREN |WS_VISIBLE, 0,0,0,0, m_hWnd, (HMENU) 1, m_hInst, (PSTR) &clientcreate); m_hWndToolBar = CreateMainToolbar(hWnd); m_hWndToolBarWork = CreateToolbarWork(hWnd); m_hWndComboBox = CreateComboBox(m_hWndToolBarWork); MoveWindow(m_hWndComboBox, 100, 0, 100, 20, TRUE); //strange m_hWndReBar = CreateRebar(hWnd); m_hStatusBar = CreateMainStatusbar(hWnd); m_pTabPaneBottom->m_pMain = this; m_pTabPaneBottom->m_iSide = XTABPANE_ISIDE_BOTTOM; m_pTabPaneBottom->Create(m_hInst, m_hWnd, SW_SHOW); m_BottomPanelHight = 200; // changed before MoveWindow(m_pTabPaneBottom->m_hWnd, 0, 0, 100, m_BottomPanelHight, TRUE); //strange m_pTabPaneLeft->m_pMain = this; m_pTabPaneLeft->m_iSide = XTABPANE_ISIDE_LEFT; m_pTabPaneLeft->Create(m_hInst, m_hWnd, SW_SHOW); m_PLeftWidth = 200; // changed before MoveWindow(m_pTabPaneLeft->m_hWnd, 0, 30, m_PLeftWidth, 100, TRUE); //strange m_pTabPaneRight->m_pMain = this; m_pTabPaneRight->m_iSide = XTABPANE_ISIDE_RIGHT; m_pTabPaneRight->Create(m_hInst, m_hWnd, SW_SHOW); m_PRightWidth = 200; // changed before MoveWindow(m_pTabPaneRight->m_hWnd, m_PRightWidth, 30, m_PRightWidth,100, TRUE); //strange m_pPrjTree->m_pMainFrame = this; m_pPrjTree->Create(m_hInst, m_pTabPaneLeft->m_hTab); m_pTabPaneLeft->InsertPage(_T("PRJ"),0, 10, m_pPrjTree->m_hWnd); m_pPrjTree2->m_pMainFrame = this; m_pPrjTree2->Create(m_hInst, m_pTabPaneLeft->m_hTab); m_pTabPaneLeft->InsertPage(_T("PRJ2"),1, 11, m_pPrjTree2->m_hWnd); m_pTabPaneLeft->SetCurTab(0); m_pMsg->m_pMainFrame = this; m_pMsg->Create(m_hInst, m_pTabPaneBottom->m_hTab); m_pTabPaneBottom->InsertPage(_T("MSG"),0, 3, m_pMsg->m_hWnd); m_pStrBox->m_pMainFrame = this; m_pStrBox->Create(m_hInst, m_pTabPaneBottom->m_hTab); m_pTabPaneBottom->InsertPage(_T("STR"),1, 4, m_pStrBox->m_hWnd); m_pTabPaneBottom->SetCurTab(0); m_pReport->m_pMainFrame = this; m_pReport->Create(m_hInst, m_pTabPaneRight->m_hTab); m_pTabPaneRight->InsertPage(_T("Stock"),0, 4, m_pReport->m_hWnd); m_pTabPaneRight->SetCurTab(0); Init(); return 0;}int CXMDIFrameEx::OnSize(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ return OnReAlign(hWnd, message, wParam, lParam); //return DefFrameProc(hWnd, m_hWndClient, message, wParam, lParam);}int CXMDIFrameEx::OnReAlign(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ RECT rt, rtClient; int iRebarHight; int iStatusHight; int iPBottomHight; int iPLeftWidth; int iPRightWidth; GetClientRect(hWnd, &rtClient); //frame client size not m_client size GetClientRect(hWnd, &m_rtAreaClient); // the Client work area; GetWindowRect(m_hWndReBar, &rt); //rebar on the top iRebarHight = rt.bottom - rt.top; m_rtAreaClient.top += iRebarHight; GetWindowRect(m_hStatusBar, &rt); //statusbar on the bottom iStatusHight = rt.bottom - rt.top; m_rtAreaClient.bottom -= iStatusHight; GetWindowRect(m_pTabPaneBottom->m_hWnd, &rt); //Bottom on the bottom iPBottomHight = rt.bottom - rt.top; m_rtAreaClient.bottom -= iPBottomHight; GetWindowRect(m_pTabPaneLeft->m_hWnd, &rt); //left iPLeftWidth = rt.right-rt.left; m_rtAreaClient.left +=iPLeftWidth; GetWindowRect(m_pTabPaneRight->m_hWnd, &rt); //right iPRightWidth = rt.right-rt.left; m_rtAreaClient.right -= iPRightWidth; MoveWindow(m_hStatusBar, 0, 0, 0, 0,TRUE); MoveWindow(m_hWndReBar, 0, 0, 0, 0,TRUE); MoveWindow(m_pTabPaneBottom->m_hWnd, 0, m_rtAreaClient.bottom, //+6, // for split rtClient.right-rtClient.top, iPBottomHight , TRUE); MoveWindow(m_pTabPaneLeft->m_hWnd, 0, m_rtAreaClient.top, iPLeftWidth, m_rtAreaClient.bottom-m_rtAreaClient.top , TRUE); MoveWindow(m_pTabPaneRight->m_hWnd, m_rtAreaClient.right, m_rtAreaClient.top, iPRightWidth, m_rtAreaClient.bottom-m_rtAreaClient.top, TRUE); MoveWindow(m_hWndClient, m_rtAreaClient.left,m_rtAreaClient.top,m_rtAreaClient.right-m_rtAreaClient.left,m_rtAreaClient.bottom-m_rtAreaClient.top,TRUE); return 1;}int CXMDIFrameEx::Test(){ PRINT(_T("\r\n CXMDIFrameEx::Test()")); return 1;}int CXMDIFrameEx::OnTest1(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ PRINT(_T("\r\n CXMDIFrameEx::OnTest1")); Test(); return 1;}int CXMDIFrameEx::OnTest2(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ OnReAlign( hWnd, message, wParam, lParam); return 1;}int CXMDIFrameEx::OnAbout(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ MessageBox(hWnd, _T("Frame"),_T("About"),MB_OK); return 0;}int CXMDIFrameEx::OnNotify(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ RECT rtBar; LPNMHDR lphr = (LPNMHDR)lParam; if (lphr->hwndFrom == m_hWndReBar) { switch (lphr->code) { case RBN_AUTOSIZE: PRINT(_T("\r\n RBN_AUTOSIZE")); break; case RBN_ENDDRAG: PRINT(_T("\r\n RBN_ENDDRAG")); break; case RBN_LAYOUTCHANGED: GetWindowRect(m_hWndReBar, &rtBar); PRINT(_T("\r\n Lay(ltrb)=%d,%d,%d,%d"),rtBar.left,rtBar.top,rtBar.right,rtBar.bottom); OnReAlign(hWnd, message, wParam, lParam); break; default: break; } } // return 0; return DefMDIChildProc(hWnd, message, wParam, lParam);}

免责声明:本网信息来自于互联网,目的在于传递更多信息,并不代表本网赞同其观点。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,并请自行核实相关内容。本站不承担此类作品侵权行为的直接责任及连带责任。如若本网有任何内容侵犯您的权益,请及时联系我们,本站将会在24小时内处理完毕。
相关文章
返回顶部