最近看windows98编程从入门到精通,在学工具栏时,发现和书上一样的程序,就是没有显示!希望高手指点,如有时间,最好留个email,帮我看看原程序!我的方法如下:
     1:在CreateToolbarEx()中设置TBSTYLE_TOOLTIPS
     2:处理WM_NOTIFY
     具体如下:
         case WM_NOTIFY:
{
TTtext=(LPNMTTDISPINFO)lParam;
if (TTtext->hdr.code == TTN_GETDISPINFO)
{
switch(TTtext->hdr.idFrom)
{
case IDM_LINE:
TTtext->lpszText="Lines";
break;
case IDM_RECTANGLE:
TTtext->lpszText="rect";
break;
case IDM_CIRCLE:
TTtext->lpszText="Circle";
break;
case IDM_MYHELP:
TTtext->lpszText="Help";
break;
}
}
break;
}
希望高手指点,是不是显示提示还要设些其他的?但我看另一个程序也和我一样,或者要设工程环境?希望高手救我于苦海,我已经盯着它看了2个小时了,痛苦!-------------------------------------
#include<windows.h>
#include<string.h>
#include<stdio.h>
#include<time.h>
#include"resource.h"#include<commctrl.h>  //通用控件#define NUMBUTTONS 7  //public data
HINSTANCE hThisInst;
char szMyWnd[]="zlf";
char szKeybordStr[200]={" "};
char szMouseStr[200]={" "};
int xPos=0,yPos=0;
char szTime[255]="显示当前时间";
int X=0,Y=76;
int maxX=0,maxY=0;//屏幕大小
COLORREF textColor;//字体颜色;
char szText[255]={" "};
HDC memdc;
HBITMAP hBitmap;
HBRUSH  hBrush;
HFONT newFont1,newFont2,oldFont;
int lineSpace;//每行间距;
TBBUTTON tb[NUMBUTTONS];
HWND tbwnd;VOID CALLBACK TimerProc(
  HWND hwnd,     // handle of window for timer messages
  UINT uMsg,     // WM_TIMER message
  UINT idEvent,  // timer identifier
  DWORD dwTime   // current system time
);LRESULT CALLBACK MyWndFun(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
BOOL CALLBACK MyDlgFun(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
int CALLBACK FontEnumProc(ENUMLOGFONTEX *lpelfe,    // pointer to logical-font data
      NEWTEXTMETRICEX *lpntme,  // pointer to physical-font data
                              int FontType,             // type of font
      LPARAM lParam             // application-defined data
);void InitToolbar(void);//初始化TBBUTTON [];int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
HWND hwnd;
MSG msg;
HACCEL hAccel;
HMENU hMenu;
INITCOMMONCONTROLSEX ccs; //set windows class
WNDCLASSEX wcl;
wcl.cbSize=sizeof(wcl);
wcl.style=0;
wcl.hInstance=hInstance;
wcl.lpszClassName=szMyWnd;
wcl.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wcl.hCursor=LoadCursor(NULL,IDC_ARROW);
wcl.hIconSm=LoadIcon(NULL,IDI_WINLOGO);
wcl.lpfnWndProc=MyWndFun;
wcl.lpszMenuName="IDR_MyPoly";
wcl.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wcl.cbWndExtra=0;
wcl.cbClsExtra=0; //register windows class
if(!RegisterClassEx(&wcl))
return 0;        //save current hInstance
hThisInst=hInstance; //load menu;
//如果是向导加的,必须用MAKEINTRESOURCE(ID)转化为字符串资源;
hMenu=LoadMenu(hThisInst,MAKEINTRESOURCE(IDR_MYPOLY));
        
//create windows
hwnd=CreateWindow(szMyWnd,"Win32 骨架",WS_OVERLAPPEDWINDOW,
     CW_USEDEFAULT,
     CW_USEDEFAULT,
     CW_USEDEFAULT,
     CW_USEDEFAULT,
     HWND_DESKTOP,
     hMenu,
     hThisInst,
     NULL);

//load accelerators
hAccel=LoadAccelerators(hThisInst,"MyAccel");

//加载通用控件
ccs.dwSize=sizeof(ccs);
ccs.dwICC=ICC_BAR_CLASSES;
InitCommonControlsEx(&ccs); InitToolbar();//设置位图与菜单项的对应关系; tbwnd = CreateToolbarEx(hwnd,
WS_VISIBLE|WS_CHILD|WS_BORDER|TBSTYLE_TOOLTIPS,
IDM_TOOLBAR,
NUMBUTTONS,
hThisInst,
IDB_TOOLBAR,
tb,
NUMBUTTONS,
16,16,16,16,
sizeof(TBBUTTON));
//set timer
SetTimer(hwnd,1,1000,(TIMERPROC)TimerProc);
//show window
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd); //message loop
while(GetMessage(&msg,hwnd,0,0))
{
if(!TranslateAccelerator(hwnd,hAccel,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
        
//release menu,but not necessary,and can be deleted;
/*
Before closing, an application must use the DestroyMenu function to destroy a menu 
not assigned to a window. A menu that is assigned to a window is automatically destroyed
when the application closes.
*/
// DestroyMenu(hMenu); //release timer
KillTimer(hwnd,1); return msg.wParam;
}

解决方案 »

  1.   

    #include<commctrl.h>  //通用控件
    #pragma comment(lib, "comctl32.lib")int WinMain(...)
    {
       //你未初始化Common Controls库, 加入下面代码或直接调用InitCommonControls();
       INITCOMMONCONTROLSEX icc;
       icc.dwSize=sizeof(INITCOMMONCONTROLSEX);
       icc.dwICC=ICC_BAR_CLASSES;
       InitCommonControlsEx(&icc);
       ....}
      

  2.   

    我初始化化了,没用!要不,留个email,我发源程序给你看看,行不?
      

  3.   

    你的MyWndFunc的WM_SIZE中是否对Toolbar的大小做了设置?
    case WM_SIZE:
       ...
       SendMessage(hToolsBar, TB_AUTOSIZE,0,0);
       return 0;如还不行,我需要看一下源程序。[email protected]
      

  4.   

    你的程序在我这儿运行没有问题,工具栏显示正常。
    我的系统的win2000。
    你重新编译一下看看。
      

  5.   

    我也试了一下,也没有显示,也没有提示。
    我的系统是win me