//Button.c
#include "Window_Xp_Style.h"
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow)
{
static TCHAR szAppName[] = TEXT("Btn");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
int cxScreen, cyScreen;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
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)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT("This program requires Windows NT!"),
szAppName, MB_ICONERROR);
return 0;
}
cxScreen = GetSystemMetrics(SM_CXSCREEN);
cyScreen = GetSystemMetrics(SM_CYSCREEN);
hwnd = CreateWindow(TEXT("Btn"),
TEXT("Btn Demo"),
WS_OVERLAPPEDWINDOW,
cxScreen * 3 / 10,//居中显示
cyScreen / 5,
cxScreen * 2 / 5,
cyScreen * 3 / 5,
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)
{
static HWND hButton[NUM];//按钮窗口句柄
HFONT hFont; //字体句柄
LOGFONT lf; //逻辑字体
int i, cyButton;//循环变量和按钮之间的间隙
switch(message)
{
case WM_CREATE:
// SkinH_Attach();
//创建按钮
for(i=0; i<NUM; i++)
{
LONG BtnStyle = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | BS_BITMAP;
hButton[i] = CreateWindow(TEXT("button"), tBtnName[i],
BtnStyle,
0, 0, 0, 0, hwnd, (HMENU)iBtnID[i],
((LPCREATESTRUCT)lParam)->hInstance, NULL);
{
HBITMAP hBmp;//位图句柄
//加载
hBmp = LoadBitmap(((LPCREATESTRUCT)lParam)->hInstance,
MAKEINTRESOURCE(iBmpID[i]));
//发送消息
SendMessage(hButton[i], BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBmp);
}
SetWindowText(hButton[i], tBtnName[i]);
//创建字体
ZeroMemory(&lf, sizeof(LOGFONT));
lf.lfHeight = -14;//字体的大小
hFont = CreateFontIndirect(&lf);
//修改字体
SendMessage(hButton[i], WM_SETFONT, (WPARAM)hFont, 0);
}
return 0 ;
case WM_SIZE:
cyButton = HIWORD(lParam) / (NUM + 2);
//通过适应窗口大小 来设定按钮的位置
for(i=0; i<NUM; i++)
{
MoveWindow(hButton[i], 100, cyButton * (i + 1), 100, 60, TRUE);
}
return 0 ;
case WM_COMMAND:
switch(wParam)
{
case IDB_PUSHBUTTON1:
MessageBox(hwnd, TEXT("按下按钮1"), TEXT("提示"), MB_OK);
break;
case IDB_PUSHBUTTON2:
MessageBox(hwnd, TEXT("按下按钮2"), TEXT("提示"), MB_OK);
break;
case IDB_PUSHBUTTON3:
MessageBox(hwnd, TEXT("按下按钮3"), TEXT("提示"), MB_OK);
break;
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
- 1
- 2
前往页