首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

工具栏提示有关问题(调了半天都没找出原因)

2012-03-08 
工具栏提示问题(调了半天都没找出原因)INT_PTRCALLBACKToolWndProc(HWNDhWnd,UINTuMsg,WPARAMwParam,LPARA

工具栏提示问题(调了半天都没找出原因)
INT_PTR   CALLBACK   ToolWndProc(HWND   hWnd,   UINT   uMsg,   WPARAM   wParam,   LPARAM   lParam);
LRESULT   CALLBACKToolBarProc   (HWND   hWnd,   UINT   uMessage,   WPARAM   wParam,LPARAM   lParam);  
WNDPROClpfnToolProc   =   NULL;  
#define   NUM_TIPS   6  
#define   ID_FIRST_TB   20060

ToolBarWnd::ToolBarWnd(MainWnd   *v)
{
m_pMainWnd=v;
m_hWnd   =NULL;
m_hToolBar=NULL;
m_hToolTip=NULL;
}

bool   ToolBarWnd::Create()
{
m_hWnd=CreateDialogParam((HINSTANCE)hModuleInstance,
  MAKEINTRESOURCE(IDD_TOOLBAR),
  m_pMainWnd-> GetHWND(),
  ToolWndProc,(long)this);

m_hToolBar=CreateToolBar(m_hWnd,false);
m_hToolTip=CreateToolTips(m_hToolBar);
CreateButtons(m_hToolBar);
return   true;
}


void   ToolBarWnd::Resize()
{
if(m_hToolBar==NULL)   return;
SendMessage(m_hToolBar,TB_AUTOSIZE,0,0);
ReSetToolTips();
}

HWND   ToolBarWnd::GetHWND()
{
return   m_hWnd;
}

char   *ToolBarWnd::GetTips(int   index)
{
char   *msg=   new   char[1024];
switch(index)
{
case   0:
ReadResource::Get(IDS_ADDMOVIE,msg,1024);//return   "Add   Movie ";
break;
case   1:
ReadResource::Get(IDS_NEWMOVIE,msg,1024);//return   "New   Movie ";
break;
case   2:
ReadResource::Get(IDS_SAVE,msg,1024);//return   "Save ";
break;
case   3:
ReadResource::Get(IDS_DELETE,msg,1024);//return   "Delete ";
break;
case   4:
ReadResource::Get(IDS_UNDO,msg,1024);//return   "Undo ";
break;
case   5:
ReadResource::Get(IDS_REDO,msg,1024);//return   "Redo ";
break;
}
return   msg;
}


HWND   ToolBarWnd::CreateToolBar(HWND   hParentWnd,bool   bTop)
{
INITCOMMONCONTROLSEX   icex;

//   Ensure   that   the   common   control   DLL   is   loaded.  
      icex.dwSize   =   sizeof(INITCOMMONCONTROLSEX);
      icex.dwICC     =   ICC_BAR_CLASSES;
      InitCommonControlsEx(&icex);


HWND   hTBWnd=   CreateWindowEx(0,
  TOOLBARCLASSNAME,
  NULL,
  WS_CHILD|TBSTYLE_FLAT|TBSTYLE_WRAPABLE|TTS_ALWAYSTIP//
    ,   0,   0,   0,   0,
  hParentWnd,
  NULL,
  0,
  NULL);
SetWindowLong(hTBWnd,   GWL_USERDATA,(LONG)this);
lpfnToolProc   =   (WNDPROC)   GetWindowLong   (hTBWnd,   GWL_WNDPROC);
SetWindowLong   (hTBWnd,   GWL_WNDPROC,   (LONG)ToolBarProc);

SendMessage(hTBWnd,   TB_BUTTONSTRUCTSIZE,   (WPARAM)   sizeof(TBBUTTON),   0);  
SendMessage(hTBWnd,   TB_SETBUTTONSIZE,   0,MAKELONG(CX_COLUMN,CY_ROW));

HIMAGELIST   addHot;
HIMAGELIST   addNormal;
        addHot   =   ImageList_LoadBitmap(   (HINSTANCE)hModuleInstance,
      MAKEINTRESOURCE(IDR_TOOLBAR_HOT),
      16,1,
      RGB(192,   192,192));   //




 
addNormal   =   ImageList_LoadBitmap(   (HINSTANCE)hModuleInstance,
    MAKEINTRESOURCE(IDR_TOOLBAR_COL),
    16,1,
    RGB(192,   192,192));   //


SendMessage(hTBWnd,TB_SETIMAGELIST,0,(LPARAM)addNormal);
SendMessage(hTBWnd,TB_SETHOTIMAGELIST,0,(LPARAM)addHot);
DeleteObject(   addNormal);
DeleteObject(   addHot);
return   hTBWnd;
}

bool   ToolBarWnd::CreateButtons(HWND     hParentWnd)
{
int   numButtons   =   NUM_TIPS;
unsigned   long   lastToolID   =   ID_FIRST_TB;

TBBUTTON*   rgtb   =   new   TBBUTTON[numButtons];

memset(rgtb,0,sizeof(TBBUTTON)*numButtons);
for(int   ii   =   0;   ii   <NUM_TIPS   ;   ii++)
{

rgtb[ii].iBitmap   =   MAKELONG(ii,   0);
rgtb[ii].idCommand   =   lastToolID   +   ii;
rgtb[ii].dwData   =   0;
rgtb[ii].fsState     =   TBSTATE_ENABLED;
rgtb[ii].fsStyle   =   TBSTYLE_BUTTON;
rgtb[ii].iString   =   0;
}
/**/
//   add   the   five   buttons   to   the   toolbar   control
SendMessage(hParentWnd,   TB_ADDBUTTONS,   numButtons,   (LPARAM)rgtb);
delete   rgtb;

ShowWindow(hParentWnd,SW_SHOW);
//   now   insert   the   toolbar   into   the   rebar....
SendMessage(hParentWnd,TB_AUTOSIZE,0,0);
return   true;
}

HWND   ToolBarWnd::CreateToolTips(HWND   hParentWnd)
{
TOOLINFO   ti;         //   tool   information  
        //   Ensure   that   the   common   control   DLL   is   loaded,   and   create  
        //   a   tooltip   control.  
        InitCommonControls();  
        HWND   hTTWnd   =   CreateWindowEx(WS_EX_TOPMOST,TOOLTIPS_CLASS,   (LPSTR)   NULL,   TTS_ALWAYSTIP,  
                CW_USEDEFAULT,   CW_USEDEFAULT,   CW_USEDEFAULT,   CW_USEDEFAULT,  
                NULL,   (HMENU)   NULL,(HINSTANCE)   hModuleInstance,   NULL);  
 
        if   (hTTWnd   ==   (HWND)   NULL)  
                return   NULL;  
 
        //   Divide   the   client   area   into   a   grid   of   rectangles,   and   add   each  
        //   rectangle   to   the   tooltip.  
        for   (int   id   =   0;   id <NUM_TIPS   ;   id++   )  
{
                        ti.cbSize   =   sizeof(TOOLINFO);  
                        ti.uFlags   =   0   ;  
                        ti.hwnd   =   hParentWnd;  
                        ti.hinst   =   (HINSTANCE)hModuleInstance;  


                        ti.uId   =   (UINT)   id;
ti.rect.left   =   id*   CX_COLUMN;    
                        ti.rect.top   =   0;
ti.lpszText   =     GetTips(id);
                        ti.rect.right   =   ti.rect.left   +   CX_COLUMN;  
                        ti.rect.bottom   =   ti.rect.top   +   CY_ROW;  
                          if   (!SendMessage(hTTWnd,   TTM_ADDTOOL,   0,  
                                        (LPARAM)   (LPTOOLINFO)   &ti))  
                                return   NULL;  
        }
SendMessage(hParentWnd,TB_SETTOOLTIPS,(WPARAM)   (HWND)   hTTWnd,0);
return   hTTWnd;
}

void   ToolBarWnd::ReSetToolTips()
{
unsigned   long   lastToolID   =   ID_FIRST_TB;
if(m_hToolBar==NULL)   return;
for(int   id=0;id <NUM_TIPS;id++)
{
        TOOLINFO   ti;  
ti.cbSize   =   sizeof(TOOLINFO);  
                ti.uFlags   =   0;  
                ti.hwnd   =   m_hToolBar;  
                ti.hinst   =   (HINSTANCE)hModuleInstance;  
                ti.uId   =   (UINT)   id;
ti.lpszText   =   GetTips(id);
RECT   rect;
SendMessage(m_hToolBar,TB_GETRECT,lastToolID+id,(LPARAM)&rect);
ti.rect=rect;
                SendMessage(m_hToolTip,   TTM_SETTOOLINFO,   0,(LPARAM)   (LPTOOLINFO)   &ti);
}
        SendMessage(m_hToolBar,TB_SETTOOLTIPS,(WPARAM)   (HWND)m_hToolTip,0);
}

INT_PTR   CALLBACK   ToolWndProc(HWND   hWnd,   UINT   uMsg,   WPARAM   wParam,   LPARAM   lParam)
{
ToolBarWnd   *pToolBarWnd=(ToolBarWnd   *)GetWindowLong(   hWnd,GWL_USERDATA);
switch(uMsg)
{
case   WM_INITDIALOG:
SetWindowLong(   hWnd,   GWL_USERDATA,   lParam);
break;
case   WM_SIZE:
{
if(pToolBarWnd!=NULL)
pToolBarWnd-> Resize();
return   true;
}break;
}
return   FALSE;//return   DefWindowProc(hWnd,uMsg,wParam,lParam);
}

LRESULT   CALLBACK   ToolBarProc   (HWND   hWnd,   UINT   uMessage,   WPARAM   wParam,LPARAM   lParam)
{
return   CallWindowProc   ((WNDPROC)lpfnToolProc,   hWnd,   uMessage,   wParam,   lParam);
}
解决后,马上给分!


[解决办法]
直接双击工具栏资源,在最下面写上提示即可,加\n后面加提示语言就可以在指向工具栏图案的时候现出提示了,否则是在下面状态条上显示.
------解决方案--------------------


mfc中有一个CToolTipCtrl
你可以试一下。
[解决办法]
http://www.codeproject.com/docking/tooltipsindialog.asp
[解决办法]
看看这个例子:
http://www.czvc.com/down.asp?id=65

热点排行