导航
  • 主页
  • VC综合技术
  • 互联网技术
  • MFC AppLauncher
  • .NET 技术
  • 界面
  • 进程
  • 算法
  • 硬件/系统
  • 数据库
  • VC++技术资源

在status bar中建立一个track bar,移动track bar的游标,如何在main window中截获消息?

mikemao 2002-07-31 06:00:55
用win32 API实现。
...全文
29 点赞 收藏 4
写回复
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
mikemao 2002-08-27
谢谢各位的提示,下面给出SDK的实现方法,结帖。
HINSTANCE g_hInst;// The current instance
HWND g_hwndMain;//Main frame handle
HWND g_hwndST;// The status bar handle
HWND g_hwndTrack;//The trackbar handle
LONG g_OldStatusProc;
LRESULT CALLBACK StatusProc(HWND , UINT , WPARAM, LPARAM);

......
//Create a trackbar
g_hwndTrack = CreateWindowEx(0,TRACKBAR_CLASS,"Trackbar Control",WS_CHILD | WS_VISIBLE | TBS_AUTOTICKS,130, 3,120, 15,g_hwndST,NULL,g_hInst,NULL);
// min. & max. positions
SendMessage(g_hwndTrack, TBM_SETRANGE, (WPARAM) TRUE,(LPARAM) MAKELONG(0, 20));
// new page size
SendMessage(g_hwndTrack, TBM_SETPAGESIZE, 0, (LPARAM) 1);
// redraw
SendMessage(g_hwndTrack, TBM_SETPOS, (WPARAM) TRUE,(LPARAM) 0);
SetFocus(g_hwndTrack);

g_OldStatusProc=GetWindowLong(g_hwndST,GWL_WNDPROC);
SetWindowLong(g_hwndST,GWL_WNDPROC,(long)StatusProc);
......

LRESULT CALLBACK StatusProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
CallWindowProc((WNDPROC)g_OldStatusProc,hWnd,message, wParam, lParam);
switch (message)
{
case WM_HSCROLL:
SendMessage(g_hwndMain,message,wParam,lParam);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
回复
mikemao 2002-08-01
就是无法捕获才问的。如果把track bar建在main window中就没有问题,建在status bar中就捕获不到,status bar的parent是main window。
回复
蒋晟 2002-08-01
HOWTO: How to Place Scroll Bars on an Object Derived from CControlBar

Q132081


--------------------------------------------------------------------------------
The information in this article applies to:

The Microsoft Foundation Classes (MFC), used with:
Microsoft Visual C++ for Windows, 16-bit edition, versions 1.0, 1.5, 1.51, 1.52
Microsoft Visual C++, 32-bit Editions, versions 1.0, 2.0, 2.1, 4.0, 4.1


SUMMARY
When you place scroll bars on an object derived from CControlBar, such as CDialogBar, the window messages must be handled in a special way as described in this article.

How to Handle the Scroll Messages in the Derived Class
There are two ways to handle the scroll messages in the derived class:


Handle the processing of messages in the derived class.

-or-


Redirect the message to the parent view or frame window object and handle the actual processing in the parent window object.


The following sample code shows how to handle the scroll messages using both methods. The debug build of this program prints a TRACE message in the debug window in response to messages from a horizontal scroll bar on the CMyDlgBar IDD_DIALOG1. To run it, build the code, press the F5 function key, click the scroll bar, and look for the TRACE message in the output window.
Sample Code
The following code shows the modifications made to the code generated by ClassWizard for the derived class CMyDlgBar.


The handler for the messages for the scroll bar with ID IDC_SCROLLBAR1 is in the derived class.

///////////////////////////////////////////////////////////
// mydlgbar.cpp : implementation file
//
...
void CMyDlgBar::OnHScroll( UINT nSBCode,
UINT nPos,
CScrollBar* pScrollBar)
{
// Add code for processing WM_HSCROLL messages:
if (pScrollBar != NULL && pScrollBar->GetDlgCtrlID() == IDC_SCROLLBAR1)

{
TRACE0( "Received message from scroll bar : IDC_SCROLLBAR1\n");
}

CDialogBar::OnHScroll(nSBCode, nPos, pScrollBar);
}



In this method, the code in OnHScroll shown above is moved to the OnHScroll of the parent window object and the handler routes the message to the parent Frame or View object.

///////////////////////////////////////////////////////////
// mydlgbar.cpp : implementation file
//
...
void CMyDlgBar::OnHScroll(UINT nSBCode,
UINT nPos,
CScrollBar* pScrollBar)
{
// Actual code to handle this message is in the parent
// frame or view object. Send the message to that object.
#ifdef _WIN32
GetOwner()->SendMessage(WM_HSCROLL,
(WPARAM)MAKELONG((WORD)nSBCode,(WORD)nPos),
(LPARAM)pScrollBar->m_hWnd);
#else
GetOwner()->SendMessage(WM_HSCROLL,
(WPARAM)mSBCode,
(LPARAM)MAKELONG(nPos, pScrollBar->m_hWnd));
#endif
CDialogBar::OnHScroll(nSBCode, nPos, pScrollBar);
}


回复
蒋晟 2002-07-31
捕获WM_xSCROLL
回复
发动态
发帖子
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……