怎么直接用windows API函数编写工具条和状态栏

 我来答
xiangjuan314
2016-07-04 · TA获得超过3.3万个赞
知道大有可为答主
回答量:2.9万
采纳率:0%
帮助的人:2930万
展开全部
#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 = 0; i < nParts; i++)
{
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;
HWND hwnd;
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加进去。
AiPPT
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图... 点击进入详情页
本回答由AiPPT提供
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式