创建MFC项目时,选择用ribbon
然后可以把CMFCRibbonStatusBar m_wndStatusBar改成public,或者写个method返回这个变量,以便从view类陪脊锋中获取m_wndStatusBar
再就是view类中添加mousemove的消息处理函数。。。然后这个函数差芦晌不多这样:
int nOffsetX = GetScrollPos(SB_HORZ)int nOffsetY = GetScrollPos(SB_VERT)
CPoint pt(0, 0)
pt.x = point.x + nOffsetX
pt.y = point.y + nOffsetY
CString strTmp
strTmp.Format(_T("%4d, %4d"), pt.x, pt.y)
CMainFrame *pFrame=(CMainFrame *)AfxGetMainWnd()
CRect rect(500,5,600,15) //calculate according
//the coord string length if wish
//pFrame->野拆m_wndStatusBar.GetElement(0)->SetText(strTmp)
//pFrame->m_wndStatusBar.GetElement(0)->SetRect(rect)
pFrame->m_wndStatusBar.GetExElement(0)->SetText(strTmp)
pFrame->m_wndStatusBar.GetExElement(0)->SetRect(rect)
pFrame->m_wndStatusBar.Invalidate()
1、首先按下win+R组合键败游打开运行窗口,输入control,点击确定。
2、确定后进入控制面板,点击”卸载程序“按钮。
3、然后进入到”卸载或更改程序“界面后,找到”visual studio 2015“选项,右键点击,选择”更改“。
4、在d出察行销的”Visual Studio“窗口中,点击”跳过“,忽略更新。
5、然后在下方,点击”修改“按钮。
6、最后在功能选项卡中,带正勾选需要添加的功能,点击”下一步“后即可在安装之后,为vs2015添加功能。
#include <windows.h>#include <windowsx.h>
#include <commctrl.h>
#include <tchar.h>
#define WINDOW_CLASS_NAME _T("WINCLASS1")
LRESULT CALLBACK WindowProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
PAINTSTRUCT ps
HDC hdc
switch(msg)
{
case WM_CREATE:
{
return(0)
}
break
case WM_PAINT:
{
hdc=BeginPaint(hwnd,&ps)
EndPaint(hwnd,&ps)
return(0)
}
break
case WM_DESTROY:
{
PostQuitMessage(0)
return(0)
}
break
default:
return( DefWindowProc( hwnd, msg, wparam, lparam ))
}
}
HWND DoCreateStatusBar(HWND hwndParent,//主窗口句柄
int nStatusID, //状态栏标识符
HINSTANCE hinst,//应用程序实例
int nParts //状态栏分为的份数
)
{
HWND hwndStatus
RECT rcClient
HLOCAL hloc
LPINT lpParts
int i, nWidth
//加载动态连接库
InitCommonControls()
//创建状态栏
hwndStatus = CreateWindowEx(
0,
STATUSCLASSNAME,
(LPCTSTR) NULL,
SBARS_SIZEGRIP |
WS_CHILD | WS_VISIBLE,
0, 0, 0, 0,
hwndParent,
(HMENU) nStatusID,
hinst,
NULL)
GetClientRect(hwndParent, &rcClient)
hloc = LocalAlloc(LHND, sizeof(int) * nParts)
lpParts = (int*)LocalLock(hloc)
//计算状态栏中每部分的宽度
nWidth = rcClient.right / nParts
for (i = 0i <nPartsi++)
{
lpParts[i] = nWidth
nWidth += nWidth
}
//把状态栏分为几部分
SendMessage(hwndStatus, SB_SETPARTS, (WPARAM) nParts,
(LPARAM) lpParts)
LocalUnlock(hloc)
LocalFree(hloc)
//返回状态栏的句柄
return hwndStatus
}
int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hprevinstance,LPSTR lpcmdline,int ncmdshow)
{
WNDCLASSEX winclass
HWNDhwnd
MSG msg
winclass.cbSize =sizeof(WNDCLASSEX)
winclass.style =CS_DBLCLKS|CS_OWNDC|CS_HREDRAW|CS_VREDRAW
winclass.lpfnWndProc=WindowProc
winclass.cbClsExtra =0
winclass.cbWndExtra =0
winclass.hInstance =hinstance
winclass.hIcon =LoadIcon(NULL,IDI_APPLICATION)
winclass.hCursor =LoadCursor(NULL,IDC_ARROW)
winclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH)
winclass.lpszMenuName =NULL
winclass.lpszClassName=WINDOW_CLASS_NAME
winclass.hIconSm =LoadIcon(NULL,IDI_APPLICATION)
if(!RegisterClassEx(&winclass))
return(0)
if(!(hwnd=CreateWindowEx(NULL,
WINDOW_CLASS_NAME,
_T("Basic Window"),
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
0,0,
400,400,
NULL,
NULL,
hinstance,
NULL)))
return(0)
DoCreateStatusBar(hwnd,60105,hinstance,4)
ShowWindow(hwnd, SW_SHOWDEFAULT)
UpdateWindow(hwnd)
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg)
DispatchMessage(&msg)
}
return(msg.wParam)
}
用windows api创建状态栏
项目,属性,链接器,输入,附加依赖项把comctl32.lib加进去。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)