資源簡介
本資源包含源代碼以及位圖資源
創建位圖按鈕、MFC樣式的按鈕
主要用于博文的資源下載,博文地址:
http://blog.csdn.net/crocodile__/article/details/10237943

代碼片段和文件信息
//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 {
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 {
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(“提示“)
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????18054??2013-08-23?17:58??1.bmp
?????文件???????24054??2013-08-23?17:58??2.bmp
?????文件???????18054??2013-08-23?17:58??3.bmp
?????文件????????3251??2013-08-23?21:46??Button.c
?????文件?????????713??2013-08-23?21:39??Window_Xp_st
評論
共有 條評論