혹시 최용일님 보시면, 용서하세요.
해결이 되지 않아, 해결된 부분 빼고 자꾸 올립니다. --;
전번 답변 정말 감사드리구요.
아래 소스와 같이 실행을 했는데,
도대체가 되질 않습니다.
한수 가르쳐 주십시요.
그대로 복사, 붙여넣기 하시면, 테스트 해 보실수 있습니다.
VK_F1도 되질 않지만,
특히, VK_F8의 경우에는,
다음의 어느 구문으로 실행시켜도 배경색은 항상 흰색입니다.
imsiHBRUSH := CreateSolidBrush(RGB(0,0,0)); // 검정색
imsiHBRUSH := CreateSolidBrush(RGB(255,0,0)); // 빨간색
imsiHBRUSH := CreateSolidBrush(RGB(0,0,255)); // 파란색
정말 모르겠군요...
//////////////////////////////////////////////////////////////////////
program Project2;
uses
Windows,Messages,SysUtils,Graphics;
{$R *.res}
var
nX,nY:Integer;
cX,cY:Integer;
function WindowProc(TheWindow:HWND;TheMessage:UINT; WParam:WPARAM; LParam: LPARAM): Longint; stdcall; export;
var
imsiHBRUSH:HBRUSH;
imsiDC:HDC;
imsips:PAINTSTRUCT;
begin
case TheMessage of
WM_KEYDOWN
:begin
Case LOWORD(WParam) of
VK_F1:begin
nX:=100; nY:=100;
imsiDC:=BeginPaint(TheWindow,imsips);
SetTextAlign(imsiDC,TA_TOP or TA_RIGHT);
SetTextColor(imsiDC,RGB(255,255,0));
SetBkColor(imsiDC,RGB(255,0,0));
TextOut(imsiDC,nX,nY,PChar('이것은'),6);
nY:=nY+20;
TextOut(imsiDC,nX,nY,PChar('책'),2);
nY:=nY+20;
TextOut(imsiDC,nX,nY,PChar('입니다'),10);
EndPaint(TheWindow,imsips);
Exit;
end;
VK_F8:begin
imsiHBRUSH := CreateSolidBrush(RGB(0,0,125));
SetClassLong(TheWindow,GCL_HBRBACKGROUND,imsiHBRUSH);
DeleteObject(imsiHBRUSH);
InvalidateRect(TheWindow,nil,TRUE);
Exit;
end;
end;
end;
WM_DESTROY
:begin
PostQuitMessage(0);
Exit;
end;
end;
Result := DefWindowProc(TheWindow, TheMessage, WParam, LParam)
end;
function RegisterClass:Boolean;
var
WindowClass:TWndClass;
begin
WindowClass.Style := CS_HREDRAW or CS_VREDRAW;
WindowClass.lpfnWndProc := @WindowProc ;
WindowClass.cbClsExtra := 0;
WindowClass.cbWndExtra := 0;
WindowClass.hInstance := hInstance;
WindowClass.hIcon := LoadIcon(0,IDI_APPLICATION);
WindowClass.hCursor := LoadCursor(0,IDC_CROSS);
WindowClass.hbrBackground := COLOR_WINDOW;
WindowClass.lpszMenuName := nil;
WindowClass.lpszClassName:= PChar('test');
Result := Windows.RegisterClass(WindowClass) <>0 ;
end;
var
TheMessage:TMsg;
hWindow:HWND;
begin
if not RegisterClass then
begin
messageBox(0,'RegisterClass Failed',nil,MB_OK);
Exit;
end;
hWindow := CreateWindow(PChar('test'),
PChar('test'),
WS_OVERLAPPEDWINDOW or WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
0,
0,
hInstance,
nil
);
if hWindow = 0 then
begin
messageBox(0,'CreateWindow Failed',nil,MB_OK);
Exit;
end;
While GetMessage(TheMessage,0,0,0) do
begin
TranslateMessage(TheMessage);
DispatchMessage(TheMessage);
end;
end.
//////////////////////////////////////////////////////////////////////
몇번 말씀드렸지만 API로 삽질하느니 델파이 폼을 쓰는게 낮지 않을까요? 뭐 꼭 이렇게 해야 한다면 할말 없지만...
아래와 같이 해보세요...
Case LOWORD(WParam) of
VK_F2:begin
GetClientRect(TheWindow, R);
nX:=100; nY:=100;
imsiDC:= GetDC(TheWindow);
TextOut(imsiDC, r.left, r.top, 'Defenestration can be hazardous', 4);
Windows.FillRect(imsidc, r, GetStockObject(WHITE_BRUSH));
Pen := CreatePen(PS_SOLID, 1, RGB(0, 255, 0));
SelectObject(ImsiDC, Pen);
SetTextAlign(imsiDC,TA_TOP or TA_RIGHT);
SetTextColor(imsiDC,RGB(255,255,0));
SetBkColor(imsiDC,RGB(255,0,0));
TextOut(imsiDC,nX,nY,PChar('This '),6);
nY:=nY+20;
TextOut(imsiDC,nX,nY,PChar('is'),2);
nY:=nY+20;
TextOut(imsiDC,nX,nY,PChar('Book'),10);
DeleteObject(Pen);
ReleaseDC(TheWindow, imsiDC);
Exit;
end;
VK_F8:begin
imsiHBRUSH := CreateSolidBrush(RGB(0,255, 0));
SetClassLong(TheWindow,GCL_HBRBACKGROUND,imsiHBRUSH);
InvalidateRect(TheWindow,nil,TRUE);
Exit;
end;
^^ 항상 즐코하세요...