C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[45428] TCustomControl에서 키입력 받기에 질문이 있습니다.?
장동훈 [] 1016 읽음    2006-06-24 21:21
안녕하세요...
몇일전부터 TCustomControld을 상속받아서 컴퍼넌트 공부중에 있습니다..
근데 다름이 아니라 help와 여기의 질/답을 검색해서 화면에 text를 찍는것 까지는 성공을 하였습니다.

그러나 키보드입력 처리부분을 하는도중 form에서 keypreview속성을 true로 주고
키입력부분을 처리하여서 상속받는 컴퍼넌트 paint 부분에서 다시 그려주게 했습니다.
그런데 제가 만든 컴퍼는트를 제외하고는 모두다 키입력을 받는데 제것만 못받더군여,

그래서 어제부터 계속 델마당과 함께 검색을 하다 도져히 알수가 없어서 이렇게 질문 드립니다.
소스를 첨부하겠습니다..

현제 동적으로 할당해서 사용하고 있습니다..

-# 헤더 파일
//---------------------------------------------------------------------------

#ifndef kfilewinH
#define kfilewinH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Classes.hpp>
#include <Controls.hpp>
//---------------------------------------------------------------------------
class PACKAGE Tfilewin : public TCustomControl
{
private:
    AnsiString gCaption;
    void __fastcall SetCaption(AnsiString Caption);

protected:
public:
    __fastcall Tfilewin(TComponent* Owner);
    __fastcall ~Tfilewin();
    void __fastcall Paint(void);
    TRect sRect; //선택막대 크기
__published:
    __property AnsiString Caption = { read = gCaption, write = SetCaption, nodefault};
    __property TKeyEvent OnKeyDown = {read=FOnKeyDown, write=FOnKeyDown};

};
//---------------------------------------------------------------------------
#endif

####################################################################################
-#소스 파일
//---------------------------------------------------------------------------

#include <vcl.h>

#pragma hdrstop

#include "kfilewin.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//

static inline void ValidCtrCheck(Tfilewin *)
{
    new Tfilewin(NULL);
}
//---------------------------------------------------------------------------
__fastcall Tfilewin::Tfilewin(TComponent* Owner)
    : TCustomControl(Owner)
{
    SetBounds(0,0,400,400);
    //sRect = Rect(1,1,ClientWidth/2 ,18);

    ControlStyle = ControlStyle <<
        csAcceptsControls <<
        csCaptureMouse <<
        csDesignInteractive <<
        csClickEvents <<
        csFramed <<
        csOpaque <<
        csDoubleClicks <<
        csFixedWidth <<
        csFixedHeight <<
        csReplicatable <<
        csDisplayDragImage <<
        csReflector <<
        csActionClient <<
        csMenuEvents;

    ControlState = ControlState <<
        csFocusing <<
        csLButtonDown <<
        csClicked <<
        csCustomPaint;
}
//---------------------------------------------------------------------------
__fastcall Tfilewin::~Tfilewin()
{
}
namespace Kfilewin
{
    void __fastcall PACKAGE Register()
    {
        TComponentClass classes[1] = {__classid(Tfilewin)};
        RegisterComponents("DHtools", classes, 0);
    }
}
//---------------------------------------------------------------------------
void __fastcall Tfilewin::Paint(void)
{
    TColor TopColor,BottomColor;
    TRect cRect;

    Canvas->Brush->Color = clBtnHighlight;
    Canvas->FillRect(ClientRect);
    cRect = ClientRect;

    Graphics::TBitmap *bit = new Graphics::TBitmap;
    bit->Width = ClientWidth;
    bit->Height = ClientHeight;
    bit->Canvas->Brush->Color = clBtnHighlight;
    bit->Canvas->FillRect(cRect);

    for(int i=0;i<3;i++)
        bit->Canvas->TextOutA(1,i * 14,gCaption);

    sRect = Rect(1,1,ClientWidth/2 ,18);

    bit->Canvas->DrawFocusRect(sRect);

    Frame3D(bit->Canvas,cRect,TopColor,BottomColor,1);
    BitBlt(Canvas->Handle,0,0,ClientWidth,ClientHeight,bit->Canvas->Handle,0,0,SRCCOPY);

    delete bit;
}
void __fastcall Tfilewin::SetCaption(AnsiString Caption)
{
    if(gCaption != Caption)
    {
        gCaption = Caption;
        Invalidate();
    }
}

#############################################################################
-# 폼에서 키보드 입력 처리 부분
void __fastcall TForm1::kview1KeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
    switch(Key)
    {
        case VK_UP:
            x -= 15;
            break;

        case VK_DOWN:
            x += 15;
            break;

        case VK_LEFT:
            y -= kview->ClientWidth/1;
            break;

        case VK_RIGHT:
            y += kview->ClientWidth/1;
            break;
    }

    kview->sRect = Rect(ClientRect.top + y,1,20+ClientRect.top,ClientWidth/2);
    //kview->Paint();
    Invalidate();
}

+ -

관련 글 리스트
45428 TCustomControl에서 키입력 받기에 질문이 있습니다.? 장동훈 1016 2006/06/24
45442     Re:TCustomControl에서 키입력 받기에 질문이 있습니다.? 박지훈.임프 1289 2006/06/26
45445         Re:Re:답변 감사 합니다.. 장동훈 802 2006/06/26
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.