📄 mainfrm.cpp
字号:
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
m_statusBar.Create(WS_CHILD|WS_BORDER|WS_VISIBLE|CCS_BOTTOM,CRect(0,0,0,0),this,105);
int width[2] = {200,200};
CString string2 = "StatusBar2";
m_statusBar.SetParts(2,width);
m_statusBar.SetText(m_lpMsg,0,0);
m_statusBar.SetText(string2,1,SBT_NOBORDERS);
/* if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
m_wndStatusBar.SetPaneText(1,m_lpMsg,TRUE);
CRect rect;
m_wndStatusBar.GetItemRect(2,&rect);
// m_wndStatusBar.SetPaneText(2,"wo",TRUE);
if(!m_wndStatusBar.m_Progress.Create(WS_CHILD|WS_VISIBLE|PBS_SMOOTH,rect,&m_wndStatusBar,ID_INDICATOR_PROCESSION))
{
TRACE0("Failed to create status bar\n");
return -1;
}*/
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
// TODO: Add a menu item that will toggle the visibility of the // dialog bar named "My Dialog Bar": // 1. In ResourceView, open the menu resource that is used by // the CMainFrame class // 2. Select the View submenu // 3. Double-click on the blank item at the bottom of the submenu // 4. Assign the new item an ID: CG_ID_VIEW_MYDIALOGBAR // 5. Assign the item a Caption: My Dialog Bar // TODO: Change the value of CG_ID_VIEW_MYDIALOGBAR to an appropriate value: // 1. Open the file resource.h // CG: The following block was inserted by the 'Dialog Bar' component { // Initialize dialog bar m_wndMyDialogBar if (!m_wndMyDialogBar.Create(this, CG_IDD_MYDIALOGBAR, CBRS_LEFT | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_HIDE_INPLACE, CG_ID_VIEW_MYDIALOGBAR)) { TRACE0("Failed to create dialog bar m_wndMyDialogBar\n"); return -1; // fail to create } m_wndMyDialogBar.EnableDocking(CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT); EnableDocking(CBRS_ALIGN_ANY); DockControlBar(&m_wndMyDialogBar); }
m_wndTempBar.SubclassDlgItem(IDC_LIST1,&m_wndMyDialogBar); ///将列表控件与工具栏联系起来
m_wndTempBar.SetItems(ItemInfo,sizeof(ItemInfo)/sizeof(mTempItems));
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style=WS_OVERLAPPED | WS_SYSMENU | WS_BORDER|WS_MAXIMIZEBOX |WS_MINIMIZEBOX |WS_MAXIMIZE;
cs.cy = ::GetSystemMetrics(SM_CYSCREEN) ;
cs.cx = ::GetSystemMetrics(SM_CXSCREEN) ;
cs.y = 0;
cs.x = 0;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
int CMainFrame::Tofile(HBITMAP hbitmap, LPCSTR lpfilename)
{
HDC hdc; //设备描述表
int ibits;
WORD wbitcount; //当前显示分辨率下每个像素所占字节数,即每个象素的位数
//位图中每个像素所占字节数,定义调色板大小,位图中像素字节大小,位图文件大小 ,写入文件字节数
DWORD dwpalettesize=0, dwbmbitssize, dwdibsize, dwwritten;
BITMAP bitmap; //位图属性结构
BITMAPFILEHEADER bmfhdr; //位图文件头结构
BITMAPINFOHEADER bi; //位图信息头结构
LPBITMAPINFOHEADER lpbi; //指向位图信息头结构,以指针的形式
//定义文件,分配内存句柄,调色板句柄
HANDLE fh, hdib, hpal,holdpal=NULL;
//计算位图文件每个像素所占字节数
hdc = CreateDC("display",NULL,NULL,NULL);
ibits = GetDeviceCaps(hdc, BITSPIXEL) * GetDeviceCaps(hdc, PLANES);
DeleteDC(hdc);
if (ibits <= 1)
wbitcount = 1; //双色
else if (ibits <= 4)
wbitcount = 4; //16色
else if (ibits <= 8)
wbitcount = 8; //256色
else if (ibits <= 16)
wbitcount = 16; //真彩色
else if (ibits <= 24)
wbitcount = 24;
else
wbitcount = 32;
//计算调色板大小
if (wbitcount <= 8)
dwpalettesize = (1 << wbitcount) * sizeof(RGBQUAD);
//设置位图信息头结构
GetObject(hbitmap, sizeof(BITMAP), (LPSTR)&bitmap);
bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = bitmap.bmWidth;
bi.biHeight = bitmap.bmHeight;
bi.biPlanes = 1;
bi.biBitCount = wbitcount;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
////计算位图数据占用的字节数/////////////////////////////////////////////////////////////////
dwbmbitssize = ((bitmap.bmWidth * wbitcount+31)/32)* 4 * bitmap.bmHeight ;
//为位图内容分配内存
hdib = GlobalAlloc(GHND,dwbmbitssize + dwpalettesize +
sizeof(BITMAPINFOHEADER));
lpbi = (LPBITMAPINFOHEADER)GlobalLock(hdib);
*lpbi = bi;
// 处理调色板
hpal = GetStockObject(DEFAULT_PALETTE);
if (hpal)
{
hdc = ::GetDC(NULL);
holdpal = SelectPalette(hdc, (HPALETTE)hpal, false);
RealizePalette(hdc);
}
// 获取该调色板下新的像素值
GetDIBits(hdc, hbitmap, 0, (UINT) bitmap.bmHeight,(LPSTR)lpbi +
sizeof(BITMAPINFOHEADER)+dwpalettesize,(BITMAPINFO*)lpbi, DIB_RGB_COLORS);
//恢复调色板
if (holdpal)
{
SelectPalette(hdc, (HPALETTE)holdpal, true);
RealizePalette(hdc);
::ReleaseDC(NULL, hdc);
}
//创建位图文件
fh = CreateFile(lpfilename, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL|
FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (fh == INVALID_HANDLE_VALUE)
return false;
// 设置位图文件头
bmfhdr.bfType = 0x4d42; // "bm"
dwdibsize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)+
dwpalettesize + dwbmbitssize;
bmfhdr.bfSize = dwdibsize;
bmfhdr.bfReserved1 = 0;
bmfhdr.bfReserved2 = 0;
bmfhdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) +
(DWORD)sizeof(BITMAPINFOHEADER)+ dwpalettesize; //位图文件的数据离文件头的偏移量
// 写入位图文件头
WriteFile(fh, (LPSTR)&bmfhdr, sizeof(BITMAPFILEHEADER), &dwwritten, NULL);
// 写入位图文件其余内容
WriteFile(fh, (LPSTR)lpbi, dwdibsize, &dwwritten, NULL);
//清除
GlobalUnlock(hdib);
GlobalFree(hdib);
CloseHandle(fh);
return true;
}
HBITMAP CMainFrame::Copybitmap(LPRECT lprect)
{
HDC hscrdc, hmemdc;
// 屏幕和内存设备描述表
HBITMAP hbitmap, holdbitmap;
// 位图句柄
int nx, ny, nx2, ny2;
// 选定区域坐标
int nwidth, nheight;
// 位图宽度和高度
int xscrn, yscrn;
// 屏幕分辨率
// 确保选定区域不为空矩形
if (IsRectEmpty(lprect))
return NULL;
//为屏幕创建设备描述表
hscrdc = CreateDC("display", NULL, NULL, NULL);
//为屏幕设备描述表创建兼容的内存设备描述表
hmemdc = CreateCompatibleDC(hscrdc);
// 获得选定区域坐标
nx = lprect->left;
ny = lprect->top;
nx2 = lprect->right;
ny2 = lprect->bottom;
// 获得屏幕分辨率
xscrn = GetDeviceCaps(hscrdc, HORZRES);
yscrn = GetDeviceCaps(hscrdc, VERTRES);
//确保选定区域是可见的
if (nx < 0)
nx = 0;
if (ny < 0)
ny = 0;
if (nx2 > xscrn)
nx2 = xscrn;
if (ny2 > yscrn)
ny2 = yscrn;
nwidth = nx2 - nx;
nheight = ny2 - ny;
// 创建一个与屏幕设备描述表兼容的位图
hbitmap = CreateCompatibleBitmap(hscrdc, nwidth, nheight);
// 把新位图选到内存设备描述表中
holdbitmap = (HBITMAP)SelectObject(hmemdc, hbitmap);
// 把屏幕设备描述表拷贝到内存设备描述表中
BitBlt(hmemdc, 0, 0, nwidth, nheight,hscrdc, nx, ny, SRCCOPY);
//得到屏幕位图的句柄
hbitmap = (HBITMAP)SelectObject(hmemdc, holdbitmap);
//清除
DeleteDC(hscrdc);
DeleteDC(hmemdc);
// 返回位图句柄
return hbitmap;
}
///////////记时处理,解压一个文件需要的时间/////////////////////////////////////////////////////////////////////
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
static int nCount = 0;
m_statusBar.GetProgressCtrl().SetRange(1,m_nRange);
m_statusBar.GetProgressCtrl().StepIt();
CFile lpFile(mFileName[nCount],CFile::modeRead);
m_Dealiase.Dealiase(&lpFile);
if (++nCount == m_nRange)
{
nCount = 0;
KillTimer(2);
// AfxMessageBox("处理结束");
m_statusBar.GetProgressCtrl().SetPos(0);
m_statusBar.SetText(m_lpMsg,0,0);
}
CFrameWnd::OnTimer(nIDEvent);
}
void CMainFrame::OnButtonFang()
{
// TODO: Add your command handler code here
if(!m_bFang)
{
WinExec(".\\Project1.exe",SW_SHOW);
}
m_bFang=TRUE;
}
void CMainFrame::OnUpdateButtonFang(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(0);
m_bFang=FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -