hi all,
怎么使用sdk函数创建工具栏
我采用sdk做了一个软件,但是现在缺少一个工具栏,sdk怎么实现一个工具栏呢?
请大家谈谈自己的想法.先谢了!
怎么使用sdk函数创建工具栏
我采用sdk做了一个软件,但是现在缺少一个工具栏,sdk怎么实现一个工具栏呢?
请大家谈谈自己的想法.先谢了!
解决方案 »
- 如何往另一个进程的消息循环里发消息?
- 关键代码段 同步问题
- 一个vc的工程文件好大哦,是不是有一些没用的东东可以删掉?
- 这道题难道没人会???神奇。
- 在对话框里,如何控制才单项的Enable 或Check属性?
- 请问如何去除ie上的yahoo toolbar?
- 请问各位高手,怎样在一个已经存在的.exe文件的工具条中加入一个工具按扭?(详细见内)
- 女友分手,闷,找兼职
- 请问如何判断用户的操作系统是win95,98,2000,nt,win me ?最好有源代码!!!!!!!!
- 到哪里可以找到最新的platform SDK
- 关于DllUnregisterServer
- 『急』请教MySQL中数据汇总、同步问题
找一下:User Interface->Window Controls->Individual Control Information->Toolbar Controls->Toolbar Controls Overviews->Using Toolbar Controls.
#include <commctrl.h>
#include "resource.h"TBBUTTON tbButtons[] = {
{ 0, ID_CUT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 1, ID_COPY, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 2, ID_PASTE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
};
#define NUM_BUTTONS 3
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
static HWND hwnd;
static HINSTANCE hInst;
static TCHAR szAppname[] = TEXT("TOOLBAR");
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreInstance,
PSTR szCmdLine,int iCmdShow)
{
MSG msg;
WNDCLASS wndclass; wndclass.style = CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.hInstance = hInstance;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH);
wndclass.lpszMenuName = szAppname;
wndclass.lpszClassName = szAppname; if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT("This Programing Needs Windows NT"),szAppname,MB_ICONERROR);
return 0;
}
hwnd = CreateWindow(szAppname,TEXT("Toolbar"),WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd); while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
HWND hwndTB;
int iCut,iCopy,iPaste;
char szBuf[16];
TCHAR szBuf1[16] = TEXT("iCut");
TCHAR szBuf2[16] = TEXT("iCopy");
TCHAR szBuf3[16] = TEXT("iPaste");
int MAX_LEN = 10;
switch(message)
{
case WM_CREATE:
hInst = ((LPCREATESTRUCT)lParam)->hInstance;
hwndTB = CreateToolbarEx(hwnd,WS_CHILD | WS_BORDER | WS_VISIBLE | TBSTYLE_TOOLTIPS | CCS_ADJUSTABLE|TBSTYLE_FLAT,
IDR_TOOLBAR,
NUM_BUTTONS,
hInst,
IDB_BITMAP,
(LPCTBBUTTON)&tbButtons,
NUM_BUTTONS,
16,16,
10,10,
sizeof(TBBUTTON));
// Add the button strings to the toolbar.
LoadString(hInst, ID_CUT, (LPSTR) &szBuf, MAX_LEN);
iCut = SendMessage(hwndTB, TB_ADDSTRING, 0, (LPARAM) (LPSTR) &szBuf);
LoadString(hInst, ID_COPY, (LPSTR) &szBuf, MAX_LEN);
iCopy = SendMessage(hwndTB, TB_ADDSTRING, 0, (LPARAM) (LPSTR) &szBuf);
LoadString(hInst, ID_PASTE, (LPSTR) &szBuf, MAX_LEN);
iPaste = SendMessage(hwndTB, TB_ADDSTRING, 0, (LPARAM) (LPSTR) &szBuf);
// Fill the TBBUTTON array with button information, and add the
// buttons to the toolbar.
tbButtons[0].iString = (int)szBuf1;
tbButtons[1].iString = (int)szBuf2;
tbButtons[2].iString = (int)szBuf3;
SendMessage(hwndTB, TB_ADDBUTTONS, (WPARAM) NUM_BUTTONS,
(LPARAM) (LPTBBUTTON) &tbButtons);
SendMessage(hwndTB, TB_AUTOSIZE, 0, 0);
ShowWindow(hwndTB, SW_SHOWNORMAL);
if(hwndTB == NULL)
{
MessageBox(hwnd,TEXT("Failed To The Toolbar Class!"),szAppname,MB_ICONERROR);
break;
} return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_CUT:
MessageBeep(0);
MessageBox(hwnd,TEXT("Hasn't Cut Implement The Command"),szAppname,MB_OK);
break;
case ID_COPY:
MessageBeep(0);
MessageBox(hwnd,TEXT("Hasn't Copy Implement The Command"),szAppname,MB_OK);
break;
case ID_PASTE:
MessageBeep(0);
MessageBox(hwnd,TEXT("Hasn't Paste Implement The Command"),szAppname,MB_OK);
break;
case IDM_EXIT:
PostQuitMessage(0);
return 0;
}
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps); EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
看看有没有帮助~~~
这个是我以前做的~~~
#include <commdlg.h>
#include <stdio.h>
#include <stdlib.h>
#include <commctrl.h>
#include <strsafe.h>
#include "resource.h"
#define ID_TIMER 1OPENFILENAME ofn;
HWND hStatusBar,hToolBar;static HINSTANCE hInst;
int RightEnd[3];LPNMHDR lpnmhdr;
LPTOOLTIPTEXT lpttext;//定义工具栏按钮
TBBUTTON tbButton[]=
{
0,IDM_NEW,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0,0,
1,IDM_OPEN,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0,0,
2,IDM_SAVE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0,0,
0,0,TBSTATE_ENABLED,TBSTYLE_SEP,0,0,0,0,
3,IDM_CUT,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0,0,
4,IDM_COPY,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0,0,
5,IDM_PASTE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0,0,
6,IDM_DELETE,TBSTATE_ENABLED,TBSTYLE_BUTTON,0,0,0,0,
};
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow)
{
HWND hwnd ;
MSG Msg ;
HACCEL hAccel;
WNDCLASS wndclass ;
char lpszMenuName[]="Menu";
char lpszClassName[] = "窗口类控件";
char lpszTitle[]= "窗口类控件示例";wndclass.style = 0;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor( NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH)COLOR_BACKGROUND ;
wndclass.lpszMenuName = lpszMenuName;
wndclass.lpszClassName = lpszClassName ; if( !RegisterClass( &wndclass))
{
MessageBeep(0) ;
return FALSE ;
}hInst=hInstance;
hwnd = CreateWindow(lpszClassName,
lpszTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL) ; ShowWindow( hwnd, nCmdShow) ;
UpdateWindow(hwnd); InitCommonControls(); //初始化通用控件//hInst=hInstance;
hAccel=LoadAccelerators(hInst,lpszMenuName);
while( GetMessage(&Msg, NULL, 0, 0))
{
if (!TranslateAccelerator(hwnd,hAccel,&Msg))
{
TranslateMessage( &Msg) ;
DispatchMessage( &Msg) ;
}
}return Msg.wParam;
}LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam){
static char szFilter[] = "Text Files (*.TXT)\0*.txt\0" \
"All Files (*.*)\0*.*\0\0" ;
static char lpstrFileName[]="";
TCHAR* pszTxt = TEXT("The Time is");
static RECT WinRect;
char szBuf[25];//// Temp buffer.
SYSTEMTIME sysTime;
HINSTANCE hInstance;switch(message)
{
case WM_CREATE:
//初始化对话框结构
hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
ofn.lStructSize = sizeof (OPENFILENAME);
ofn.hwndOwner = hwnd ;
ofn.hInstance = NULL ;
ofn.lpstrFilter = szFilter ;
ofn.lpstrCustomFilter = NULL ;
ofn.nMaxCustFilter = 0 ;
ofn.nFilterIndex = 1 ;
ofn.lpstrFile = NULL ;
ofn.nMaxFile = 0 ;
ofn.lpstrFileTitle = NULL ;
ofn.nMaxFileTitle = 0 ;
ofn.lpstrInitialDir = NULL ;
ofn.lpstrTitle = NULL ;
ofn.Flags = 0 ;
ofn.nFileOffset = 0 ;
ofn.nFileExtension = 0 ;
ofn.lpstrDefExt = NULL ;
ofn.lCustData = 0 ;
ofn.lpfnHook = NULL ;
ofn.lpTemplateName = NULL ;
CreateToolBarEx(aparent,TBSTYLE_LIST or WS_CHILD or TBSTYLE_TOOLTIPS or CCS_ADJUSTABLE,1000,
0,0,IDB_STD_SMALL_COLOR ,0,0,16,16,0,0,SizeOf(TTBBUTTON));//创建工具栏
hToolBar=CreateToolbarEx(hwnd,
WS_CHILD|WS_BORDER|WS_VISIBLE|TBSTYLE_FLAT
|TBSTYLE_TOOLTIPS|TBSTYLE_LIST|CCS_ADJUSTABLE,
ID_TOOLBAR,
7,//该工具栏包含7个图形按钮
hInst,//使用系统提供的图形按钮
IDB_TOOLBAR,
tbButton,
7,
0,0,
0,0,
sizeof(TBBUTTON));
//创建状态栏
hStatusBar=CreateStatusWindow(
WS_CHILD|WS_VISIBLE,
"",
hwnd,
ID_STATUSBAR);
/*if(hStatusBar)
{
SetTimer(hwnd, IDM_TIMER, TIMER_TIMEOUT, NULL);
return 0;
}*/
//设置本地时间
GetLocalTime(&sysTime);
StringCchPrintfA(szBuf,
sizeof(szBuf),
"%s %2d:%02d:%02d %s",
pszTxt,
(sysTime.wHour == 0 ? 12 :
(sysTime.wHour <= 12 ? sysTime.wHour : sysTime.wHour -12)),
sysTime.wMinute,
sysTime.wSecond,
(sysTime.wHour < 12 ? "AM":"PM"));
//设置状态栏
//获取用户区坐标
GetClientRect(hwnd,&WinRect);RightEnd[0]=WinRect.right*1/3;
RightEnd[1]=WinRect.right*2/3;
RightEnd[2]=WinRect.right;//设置状态栏各部分的大小
SendMessage(hStatusBar,SB_SETPARTS,(WPARAM)3,
(LPARAM)RightEnd);//设置状态栏各部分的文本
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)0,
(LPARAM)"欢迎使用NetSlave");SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)1,
(LPARAM)"工具栏状态");
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)2,
(LPARAM)szBuf);return 0;
case WM_SIZE:
SendMessage(hStatusBar,WM_SIZE,wParam,lParam);
SendMessage(hToolBar,WM_SIZE,wParam,lParam);
return 0;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_NEW:
//在状态栏中显示文本
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)1,
(LPARAM)"新建文件");break;case IDM_OPEN:
//在状态栏中显示文本
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)1,
(LPARAM)"打开文件");//设置“打开”对话框
ofn.lpstrFile=lpstrFileName;
ofn.Flags=OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST
|OFN_HIDEREADONLY;
ofn.lpstrTitle="打开";//调用函数GetOpenFileName显示对话框
GetOpenFileName(&ofn);
//文件读写操作break;case IDM_SAVE:
//在状态栏中显示文本
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)1,
(LPARAM)"保存文件");//存储操作//文件保存成功则显示消息框
MessageBox(hwnd,"文件保存成功","文件保存",MB_OK);
break;case IDM_SAVEAS:
//在状态栏中显示文本
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)1,
(LPARAM)"另存文件");//设置“另存为”对话框
ofn.lpstrFile=lpstrFileName;
ofn.Flags=OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST
|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT;
ofn.lpstrTitle="另存为";//调用函数GetSaveFileName显示对话框
GetSaveFileName(&ofn);//存储操作
//文件保存成功则显示消息框
MessageBox(hwnd,"文件保存成功!","文件保存",MB_OK);break;case IDM_CLOSE:
//在状态栏中显示文本
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)1,
(LPARAM)"关闭文件");break;case IDM_EXIT:
SendMessage(hwnd,WM_DESTROY,0,0);
break;case IDM_CUT:
//在状态栏中显示文本
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)1,
(LPARAM)"剪切");break;case IDM_COPY:
//在状态栏中显示文本
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)1,
(LPARAM)"复制");break;case IDM_PASTE:
//在状态栏中显示文本
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)1,
(LPARAM)"粘贴");break;case IDM_DELETE:
SendMessage(hStatusBar,SB_SETTEXT,(WPARAM)1,
(LPARAM)"删除");
break;case IDM_ABOUT:
MessageBox(hwnd,"通用控件综合示例","关于",MB_OK);
break;}
break;case WM_NOTIFY:
//设置工具栏提示的文本
lpnmhdr=(LPNMHDR)lParam;
if (lpnmhdr->code==TTN_NEEDTEXT)
{
lpttext=(LPTOOLTIPTEXT)lParam;
switch(lpttext->hdr.idFrom)
{
case IDM_NEW:
lpttext->lpszText="新建";
break;case IDM_OPEN:
lpttext->lpszText="打开";
break;case IDM_SAVE:
lpttext->lpszText="保存";
break;case IDM_CUT:
lpttext->lpszText="剪切";
break;case IDM_COPY:
lpttext->lpszText="复制";
break;case IDM_PASTE:
lpttext->lpszText="粘贴";
break;
case IDM_DELETE:
lpttext->lpszText="删除";}
}break;
case WM_DESTROY:
PostQuitMessage(0);
break; default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}
上面一个使用的图标是系统里面的~~
这个可以自己加进来自己的图标~~~