S
szhcracker
Unregistered / Unconfirmed
GUEST, unregistred user!
我是用如下的代码建立的程序(只有.dpr文件),界面上有一个标签及按钮,点击按钮则弹出一个消息。问题是:这个窗体的背景色为淡黄色(见代码)而Label的背景为默认的灰色,怎样改变呢?谢谢。我试过SetBkColor,貌似无用。谢谢各位。
program Demo;
uses Windows;
var
wClass: TWndClass;
hInst, Handle, lable, hBtn: HWND;
Msg: TMsg;
function WindowProc(hWnd, Msg, wParam, lParam: Longint): Longint; stdcall;
var
RCT: TRect;
begin
Result := DefWindowProc(hWnd, Msg, wParam, lParam);
case Msg of
5: GetWindowRect(Handle, RCT);
$0111: //点击按钮显示一个消息框
if lParam = hBtn then MessageBox(0, PChar('测试'), '信息', 64);
2: Halt; //退出
end;
end;
begin
hInst := GetModuleHandle(nil);
with wClass do
begin
lpfnWndProc := @WindowProc;
hInstance:= hInst;
hbrBackground := COLOR_BTNFACE + 10; //窗体的背景颜色(接近淡黄色)
lpszClassName := 'SC';
end;
RegisterClass(wClass);
//创建窗体
Handle := CreateWindow('SC', 'Test', WS_SYSMENU or WS_VISIBLE, 200, 200, 325, 210, 0, 0, hInst, nil);
//创建Label
lable := CreateWindow('Static', 'Label', WS_VISIBLE or WS_CHILD or SS_LEFT, 5, 10, 60, 17, Handle, 0, hInst, 0);
//创建按钮
hBtn := CreateWindow('Button', '开始下载', WS_VISIBLE or WS_CHILD or BS_FLAT, 227, 146, 85, 24, Handle, 0, hInst, nil);
while GetMessage(Msg, Handle, 0, 0) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end.
program Demo;
uses Windows;
var
wClass: TWndClass;
hInst, Handle, lable, hBtn: HWND;
Msg: TMsg;
function WindowProc(hWnd, Msg, wParam, lParam: Longint): Longint; stdcall;
var
RCT: TRect;
begin
Result := DefWindowProc(hWnd, Msg, wParam, lParam);
case Msg of
5: GetWindowRect(Handle, RCT);
$0111: //点击按钮显示一个消息框
if lParam = hBtn then MessageBox(0, PChar('测试'), '信息', 64);
2: Halt; //退出
end;
end;
begin
hInst := GetModuleHandle(nil);
with wClass do
begin
lpfnWndProc := @WindowProc;
hInstance:= hInst;
hbrBackground := COLOR_BTNFACE + 10; //窗体的背景颜色(接近淡黄色)
lpszClassName := 'SC';
end;
RegisterClass(wClass);
//创建窗体
Handle := CreateWindow('SC', 'Test', WS_SYSMENU or WS_VISIBLE, 200, 200, 325, 210, 0, 0, hInst, nil);
//创建Label
lable := CreateWindow('Static', 'Label', WS_VISIBLE or WS_CHILD or SS_LEFT, 5, 10, 60, 17, Handle, 0, hInst, 0);
//创建按钮
hBtn := CreateWindow('Button', '开始下载', WS_VISIBLE or WS_CHILD or BS_FLAT, 227, 146, 85, 24, Handle, 0, hInst, nil);
while GetMessage(Msg, Handle, 0, 0) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end.