設定static控制元件背景顏色、控制元件字型的背景顏色和控制元件字型的顏色
阿新 • • 發佈:2019-02-01
注:轉載至:https://my.oschina.net/u/241930/blog/528285,謝謝該博主的分享
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); HINSTANCE hInst; int WINAPI WinMain( HINSTANCEhInstance, HINSTANCEhPrevInstance, LPSTR lpCmdLine, int nCmdShow) { static TCHARszClassName[] = TEXT("HelloWin"); HWND hwnd; MSG msg; WNDCLASS wndclass; hInst = hInstance; 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=szClassName; RegisterClass(&wndclass); hwnd =CreateWindow( szClassName, TEXT("Welcome"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL ); if(hwnd == NULL) { MessageBox(NULL, "建立窗口出錯!", "Error",MB_OK); return -1; } ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAMwParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; static HFONT hFont; //邏輯字型 static HWNDhLabUsername; //靜態文字框--使用者名稱 static HWNDhLabPassword; //靜態文字框--密碼 static HWNDhEditUsername; //單行文字輸入框 static HWNDhEditPassword; //密碼輸入框 static HWND hBtnLogin; //登入按鈕 static HBRUSH hBrush; //畫刷 //定義緩衝區 TCHARszUsername[100]; TCHARszPassword[100]; TCHARszUserInfo[200]; switch(message) { case WM_CREATE: { //建立畫刷 hBrush =CreateSolidBrush(RGB(0X41, 0X96, 0X4F));//翠綠色 //建立邏輯字型 hFont =CreateFont( -14, -7,0,0,400, FALSE, FALSE,FALSE, DEFAULT_CHARSET,//使用預設字符集 OUT_CHARACTER_PRECIS,CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY,//預設輸出質量 FF_DONTCARE, //不指定字型族 TEXT("微軟雅黑") //字型名 ); //建立靜態文字框控制元件--使用者名稱 hLabUsername = CreateWindow( TEXT("static"), TEXT("使用者名稱"), WS_CHILD | WS_VISIBLE |SS_CENTERIMAGE | SS_RIGHT, 0, 20, 70,26,//X座標、Y座標、寬度、高度 hWnd, (HMENU)1, hInst, NULL ); //建立靜態文字框控制元件--密碼 hLabPassword = CreateWindow( TEXT("static"), TEXT("密碼"), WS_CHILD | WS_VISIBLE |SS_CENTERIMAGE | SS_RIGHT, 0, 56, 70, 26, hWnd, (HMENU)2, hInst, NULL ); //建立單行文字框輸入控制元件 hEditUsername = CreateWindow( TEXT("edit"), TEXT(""), WS_CHILD | WS_VISIBLE |WS_BORDER | ES_AUTOHSCROLL, 80, 20, 200, 26, hWnd, (HMENU)3, hInst, NULL ); //建立密碼輸入框 hEditPassword = CreateWindow( TEXT("edit"), TEXT(""), WS_CHILD | WS_VISIBLE |WS_BORDER | ES_PASSWORD | ES_AUTOHSCROLL, 80, 56, 200, 26, hWnd, (HMENU)4, hInst, NULL ); //建立按鈕控制元件 hBtnLogin= CreateWindow( TEXT("button"),//按鈕控制元件類名 TEXT("登入"), WS_CHILD | WS_VISIBLE |WS_BORDER | BS_FLAT, 80,92, 200,30, hWnd, (HMENU)5, hInst, NULL ); //依次設定控制元件字型 SendMessage(hLabUsername, WM_SETFONT, (WPARAM)hFont, NULL); SendMessage(hLabPassword, WM_SETFONT, (WPARAM)hFont, NULL); SendMessage(hEditUsername, WM_SETFONT, (WPARAM)hFont, NULL); SendMessage(hEditPassword, WM_SETFONT, (WPARAM)hFont, NULL); SendMessage(hBtnLogin, WM_SETFONT, (WPARAM)hFont, NULL); break; } case WM_COMMAND: { wmId =LOWORD(wParam); wmEvent =HIWORD(wParam); switch(wmId) { case 5://按鈕的HMENU引數 { //獲取輸入框的資料 GetWindowText(hEditUsername, szUsername,100); GetWindowText(hEditPassword, szPassword,100); wsprintf(szUserInfo, TEXT("Warning:\r\nYour username is: %s\r\nYour Password is: %s"), szUsername,szPassword); MessageBox(hWnd, szUserInfo, TEXT("Informationtips"), MB_ICONINFORMATION); break; } default: { //不處理的訊息一定要交給defWindowProc處理 return DefWindowProc(hWnd, message, wParam,lParam); break; } } break; } case WM_CTLCOLORSTATIC: { return(INT_PTR)hBrush; //這裡必須返回畫刷控制代碼 } case WM_PAINT: { hdc =BeginPaint(hWnd, &ps); //Ellipse(hdc, 0, 100, 200, 200); EndPaint(hWnd, &ps); break; } case WM_DESTROY: { DeleteObject(hFont); //刪除建立的字型 DeleteObject(hBrush); PostQuitMessage(0); break; } default: { returnDefWindowProc(hWnd, message, wParam, lParam); } } return 0; } 設定控制元件字型的背景顏色和控制元件字型的顏色:
#include
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInst;
int WINAPI WinMain(
HINSTANCEhInstance,
HINSTANCEhPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
static TCHARszClassName[] = TEXT("HelloWin");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
hInst = hInstance;
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=szClassName;
RegisterClass(&wndclass);
hwnd =CreateWindow(
szClassName,
TEXT("Welcome"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL,
NULL,
hInstance,
NULL
);
if(hwnd == NULL)
{
MessageBox(NULL, "建立窗口出錯!", "Error",MB_OK);
return -1;
}
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAMwParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
HDC hdcWnd;
HDC hdcStatic;
static HFONT hFont; //邏輯字型
static HWNDhLabUsername; //靜態文字框--使用者名稱
static HWNDhLabPassword; //靜態文字框--密碼
static HWNDhEditUsername; //單行文字輸入框
static HWNDhEditPassword; //密碼輸入框
static HWND hBtnLogin; //登入按鈕
static HBRUSH hBrush; //畫刷
//定義緩衝區
TCHARszUsername[100];
TCHARszPassword[100];
TCHARszUserInfo[200];
switch(message)
{
case WM_CREATE:
{
//建立畫刷
hBrush =CreateSolidBrush(RGB(0X41, 0X96, 0X4F));//翠綠色,控制元件的背景顏色
//建立邏輯字型
hFont =CreateFont(
-14, -7,0,0,400,
FALSE, FALSE,FALSE,
DEFAULT_CHARSET,//使用預設字符集
OUT_CHARACTER_PRECIS,CLIP_CHARACTER_PRECIS,
DEFAULT_QUALITY,//預設輸出質量
FF_DONTCARE, //不指定字型族
TEXT("微軟雅黑") //字型名
);
//建立靜態文字框控制元件--使用者名稱
hLabUsername = CreateWindow(
TEXT("static"),
TEXT("使用者名稱"),
WS_CHILD | WS_VISIBLE |SS_CENTERIMAGE | SS_RIGHT,
0, 20, 70,26,//X座標、Y座標、寬度、高度
hWnd,
(HMENU)1,
hInst,
NULL
);
//建立靜態文字框控制元件--密碼
hLabPassword = CreateWindow(
TEXT("static"),
TEXT("密碼"),
WS_CHILD | WS_VISIBLE |SS_CENTERIMAGE | SS_RIGHT,
0, 56, 70, 26,
hWnd,
(HMENU)2,
hInst,
NULL
);
//建立單行文字框輸入控制元件
hEditUsername = CreateWindow(
TEXT("edit"),
TEXT(""),
WS_CHILD | WS_VISIBLE |WS_BORDER | ES_AUTOHSCROLL,
80, 20, 200, 26,
hWnd,
(HMENU)3,
hInst,
NULL
);
//建立密碼輸入框
hEditPassword = CreateWindow(
TEXT("edit"),
TEXT(""),
WS_CHILD | WS_VISIBLE |WS_BORDER | ES_PASSWORD | ES_AUTOHSCROLL,
80, 56, 200, 26,
hWnd,
(HMENU)4,
hInst,
NULL
);
//建立按鈕控制元件
hBtnLogin= CreateWindow(
TEXT("button"),//按鈕控制元件類名
TEXT("登入"),
WS_CHILD | WS_VISIBLE |WS_BORDER | BS_FLAT,
80,92, 200,30,
hWnd,
(HMENU)5,
hInst,
NULL
);
//依次設定控制元件字型
SendMessage(hLabUsername, WM_SETFONT, (WPARAM)hFont, 0);
SendMessage(hLabPassword, WM_SETFONT, (WPARAM)hFont, 0);
SendMessage(hEditUsername, WM_SETFONT, (WPARAM)hFont, 0);
SendMessage(hEditPassword, WM_SETFONT, (WPARAM)hFont, 0);
SendMessage(hBtnLogin, WM_SETFONT, (WPARAM)hFont, 0);
break;
}
case WM_COMMAND:
{
wmId =LOWORD(wParam);
wmEvent =HIWORD(wParam);
switch(wmId)
{
case 5://按鈕的HMENU引數
{
//獲取輸入框的資料
GetWindowText(hEditUsername, szUsername,100);
GetWindowText(hEditPassword, szPassword,100);
wsprintf(szUserInfo, TEXT("Warning:\r\nYour username is: %s\r\nYour Password is: %s"), szUsername,szPassword);
MessageBox(hWnd, szUserInfo, TEXT("Informationtips"), MB_ICONINFORMATION);
break;
}
default:
{
//不處理的訊息一定要交給defWindowProc處理
return DefWindowProc(hWnd, message, wParam,lParam);
break;
}
}
break;
}
case WM_CTLCOLORSTATIC:
{
hdcStatic= (HDC)wParam;
SetTextColor(hdcStatic, RGB(255,255,255));//控制元件文字的字型顏色
SetBkColor(hdcStatic, RGB(0X41, 0X96,0X4F));//控制元件字型的背景顏色,注意跟以上區分
return(INT_PTR)hBrush; //這裡必須返回畫刷控制代碼
}
case WM_PAINT:
{
hdc =BeginPaint(hWnd, &ps);
//Ellipse(hdc, 0, 100, 200, 200);
EndPaint(hWnd, &ps);
break;
}
case WM_DESTROY:
{
DeleteObject(hFont); //刪除建立的字型
DeleteObject(hBrush);
PostQuitMessage(0);
break;
}
default:
{
returnDefWindowProc(hWnd, message, wParam, lParam);
}
}
return 0;
}
設定透明背景:
#include
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE hInst;
int WINAPI WinMain(
HINSTANCEhInstance,
HINSTANCEhPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
static TCHARszClassName[] = TEXT("HelloWin");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
hInst = hInstance;
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=szClassName;
RegisterClass(&wndclass);
hwnd =CreateWindow(
szClassName,
TEXT("Welcome"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL,
NULL,
hInstance,
NULL
);
if(hwnd == NULL)
{
MessageBox(NULL, "建立窗口出錯!", "Error",MB_OK);
return -1;
}
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAMwParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
HDC hdcWnd;
HDC hdcStatic;
static HFONT hFont; //邏輯字型
static HWNDhLabUsername; //靜態文字框--使用者名稱
static HWNDhLabPassword; //靜態文字框--密碼
static HWNDhEditUsername; //單行文字輸入框
static HWNDhEditPassword; //密碼輸入框
static HWND hBtnLogin; //登入按鈕
static HBRUSH hBrush; //畫刷
//定義緩衝區
TCHARszUsername[100];
TCHARszPassword[100];
TCHARszUserInfo[200];
switch(message)
{
case WM_CREATE:
{
//建立畫刷
hBrush =CreateSolidBrush(RGB(0X41, 0X96, 0X4F));//翠綠色,控制元件的背景顏色
//建立邏輯字型
hFont =CreateFont(
-14, -7,0,0,400,
FALSE, FALSE,FALSE,
DEFAULT_CHARSET,//使用預設字符集
OUT_CHARACTER_PRECIS,CLIP_CHARACTER_PRECIS,
DEFAULT_QUALITY,//預設輸出質量
FF_DONTCARE, //不指定字型族
TEXT("微軟雅黑") //字型名
);
//建立靜態文字框控制元件--使用者名稱
hLabUsername = CreateWindow(
TEXT("static"),
TEXT("使用者名稱"),
WS_CHILD | WS_VISIBLE |SS_CENTERIMAGE | SS_RIGHT,
0, 20, 70,26,//X座標、Y座標、寬度、高度
hWnd,
(HMENU)1,
hInst,
NULL
);
//建立靜態文字框控制元件--密碼
hLabPassword = CreateWindow(
TEXT("static"),
TEXT("密碼"),
WS_CHILD | WS_VISIBLE |SS_CENTERIMAGE | SS_RIGHT,
0, 56, 70, 26,
hWnd,
(HMENU)2,
hInst,
NULL
);
//建立單行文字框輸入控制元件
hEditUsername = CreateWindow(
TEXT("edit"),
TEXT(""),
WS_CHILD | WS_VISIBLE |WS_BORDER | ES_AUTOHSCROLL,
80, 20, 200, 26,
hWnd,
(HMENU)3,
hInst,
NULL
);
//建立密碼輸入框
hEditPassword = CreateWindow(
TEXT("edit"),
TEXT(""),
WS_CHILD | WS_VISIBLE |WS_BORDER | ES_PASSWORD | ES_AUTOHSCROLL,
80, 56, 200, 26,
hWnd,
(HMENU)4,
hInst,
NULL
);
//建立按鈕控制元件
hBtnLogin= CreateWindow(
TEXT("button"),//按鈕控制元件類名
TEXT("登入"),
WS_CHILD | WS_VISIBLE |WS_BORDER | BS_FLAT,
80,92, 200,30,
hWnd,
(HMENU)5,
hInst,
NULL
);
//依次設定控制元件字型
SendMessage(hLabUsername, WM_SETFONT, (WPARAM)hFont, 0);
SendMessage(hLabPassword, WM_SETFONT, (WPARAM)hFont, 0);
SendMessage(hEditUsername, WM_SETFONT, (WPARAM)hFont, 0);
SendMessage(hEditPassword, WM_SETFONT, (WPARAM)hFont, 0);
SendMessage(hBtnLogin, WM_SETFONT, (WPARAM)hFont, 0);
break;
}
case WM_COMMAND:
{
wmId =LOWORD(wParam);
wmEvent =HIWORD(wParam);
switch(wmId)
{
case 5://按鈕的HMENU引數
{
//獲取輸入框的資料
GetWindowText(hEditUsername, szUsername,100);
GetWindowText(hEditPassword, szPassword,100);
wsprintf(szUserInfo, TEXT("Warning:\r\nYour username is: %s\r\nYour Password is: %s"), szUsername,szPassword);
MessageBox(hWnd, szUserInfo, TEXT("Informationtips"), MB_ICONINFORMATION);
break;
}
default:
{
//不處理的訊息一定要交給defWindowProc處理
return DefWindowProc(hWnd, message, wParam,lParam);
break;
}
}
break;
}
case WM_CTLCOLORSTATIC:
{
hdcStatic= (HDC)wParam;
SetTextColor(hdcStatic, RGB(0x41, 0x96, 0x4f));//控制元件文字的字型顏色
//SetBkColor(hdcStatic, RGB(0X41, 0X96,0X4F));//控制元件字型的背景顏色,注意跟以上區分
SetBkMode(hdcStatic, TRANSPARENT);//透明背景
return(INT_PTR)GetStockObject(NULL_BRUSH); //這裡返回無顏色畫刷
}
case WM_PAINT:
{
hdc =BeginPaint(hWnd, &ps);
//Ellipse(hdc, 0, 100, 200, 200);
EndPaint(hWnd, &ps);
break;
}
case WM_DESTROY:
{
DeleteObject(hFont); //刪除建立的字型
DeleteObject(hBrush);
PostQuitMessage(0);
break;
}
default:
{
returnDefWindowProc(hWnd, message, wParam, lParam);
}
}
return 0;
}
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); HINSTANCE hInst; int WINAPI WinMain( HINSTANCEhInstance, HINSTANCEhPrevInstance, LPSTR lpCmdLine, int nCmdShow) { static TCHARszClassName[] = TEXT("HelloWin"); HWND hwnd; MSG msg; WNDCLASS wndclass; hInst = hInstance; 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=szClassName; RegisterClass(&wndclass); hwnd =CreateWindow( szClassName, TEXT("Welcome"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL ); if(hwnd == NULL) { MessageBox(NULL, "建立窗口出錯!", "Error",MB_OK); return -1; } ShowWindow(hwnd,nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAMwParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; static HFONT hFont; //邏輯字型 static HWNDhLabUsername; //靜態文字框--使用者名稱 static HWNDhLabPassword; //靜態文字框--密碼 static HWNDhEditUsername; //單行文字輸入框 static HWNDhEditPassword; //密碼輸入框 static HWND hBtnLogin; //登入按鈕 static HBRUSH hBrush; //畫刷 //定義緩衝區 TCHARszUsername[100]; TCHARszPassword[100]; TCHARszUserInfo[200]; switch(message) { case WM_CREATE: { //建立畫刷 hBrush =CreateSolidBrush(RGB(0X41, 0X96, 0X4F));//翠綠色 //建立邏輯字型 hFont =CreateFont( -14, -7,0,0,400, FALSE, FALSE,FALSE, DEFAULT_CHARSET,//使用預設字符集 OUT_CHARACTER_PRECIS,CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY,//預設輸出質量 FF_DONTCARE, //不指定字型族 TEXT("微軟雅黑") //字型名 ); //建立靜態文字框控制元件--使用者名稱 hLabUsername = CreateWindow( TEXT("static"), TEXT("使用者名稱"), WS_CHILD | WS_VISIBLE |SS_CENTERIMAGE | SS_RIGHT, 0, 20, 70,26,//X座標、Y座標、寬度、高度 hWnd, (HMENU)1, hInst, NULL ); //建立靜態文字框控制元件--密碼 hLabPassword = CreateWindow( TEXT("static"), TEXT("密碼"), WS_CHILD | WS_VISIBLE |SS_CENTERIMAGE | SS_RIGHT, 0, 56, 70, 26, hWnd, (HMENU)2, hInst, NULL ); //建立單行文字框輸入控制元件 hEditUsername = CreateWindow( TEXT("edit"), TEXT(""), WS_CHILD | WS_VISIBLE |WS_BORDER | ES_AUTOHSCROLL, 80, 20, 200, 26, hWnd, (HMENU)3, hInst, NULL ); //建立密碼輸入框 hEditPassword = CreateWindow( TEXT("edit"), TEXT(""), WS_CHILD | WS_VISIBLE |WS_BORDER | ES_PASSWORD | ES_AUTOHSCROLL, 80, 56, 200, 26, hWnd, (HMENU)4, hInst, NULL ); //建立按鈕控制元件 hBtnLogin= CreateWindow( TEXT("button"),//按鈕控制元件類名 TEXT("登入"), WS_CHILD | WS_VISIBLE |WS_BORDER | BS_FLAT, 80,92, 200,30, hWnd, (HMENU)5, hInst, NULL ); //依次設定控制元件字型 SendMessage(hLabUsername, WM_SETFONT, (WPARAM)hFont, NULL); SendMessage(hLabPassword, WM_SETFONT, (WPARAM)hFont, NULL); SendMessage(hEditUsername, WM_SETFONT, (WPARAM)hFont, NULL); SendMessage(hEditPassword, WM_SETFONT, (WPARAM)hFont, NULL); SendMessage(hBtnLogin, WM_SETFONT, (WPARAM)hFont, NULL); break; } case WM_COMMAND: { wmId =LOWORD(wParam); wmEvent =HIWORD(wParam); switch(wmId) { case 5://按鈕的HMENU引數 { //獲取輸入框的資料 GetWindowText(hEditUsername, szUsername,100); GetWindowText(hEditPassword, szPassword,100); wsprintf(szUserInfo, TEXT("Warning:\r\nYour username is: %s\r\nYour Password is: %s"), szUsername,szPassword); MessageBox(hWnd, szUserInfo, TEXT("Informationtips"), MB_ICONINFORMATION); break; } default: { //不處理的訊息一定要交給defWindowProc處理 return DefWindowProc(hWnd, message, wParam,lParam); break; } } break; } case WM_CTLCOLORSTATIC: { return(INT_PTR)hBrush; //這裡必須返回畫刷控制代碼 } case WM_PAINT: { hdc =BeginPaint(hWnd, &ps); //Ellipse(hdc, 0, 100, 200, 200); EndPaint(hWnd, &ps); break; } case WM_DESTROY: { DeleteObject(hFont); //刪除建立的字型 DeleteObject(hBrush); PostQuitMessage(0); break; } default: { returnDefWindowProc(hWnd, message, wParam, lParam); } } return 0; } 設定控制元件字型的背景顏色和控制元件字型的顏色: