怎么直接用windows API函数编写工具条和状态栏
1个回答
展开全部
#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加进去。
#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 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询