Showing posts with label Win32API. Show all posts
Showing posts with label Win32API. Show all posts
2009/03/30
윈도우가 보여지고 사라질때 에니메이션 효과 주기
AnimateWindow
윈도우에 효과를 주어 사라지고 등장하게 해 주는 API 이다.
함수 설명 ( 출처 : MSDN )
첫 번째 인자인 hwnd 는 효과를 적용하기위한 윈도우의 핸들이다.
두 번째 인자인 dwTime 은 지정된 효과를 수행할 시간으로 밀리세컨드 단위로 입력한다. 입력값이 작을 수록 에니메이션 효과의 시간이 짧아 지므로 에니메이션이 빠르게 동작한다.
세 번째 인자는 효과의 종류이다.
아래 소스는 이 글 위에 포함되어 있는 플래시를 만들면서 작성한 코드이다.
Original Post : http://neodreamer-dev.tistory.com/275
윈도우에 효과를 주어 사라지고 등장하게 해 주는 API 이다.
함수 설명 ( 출처 : MSDN )
Syntax
BOOL AnimateWindow(
HWND hwnd,
DWORD dwTime,
DWORD dwFlags
);
Parameter 설명 보기
Parameters
hwnd
[in] Handle to the window to animate.
The calling thread must own this window.
dwTime
[in] Specifies how long it takes to play the animation, in milliseconds.
Typically, an animation takes 200 milliseconds to play.
dwFlags
[in] Specifies the type of animation.
This parameter can be one or more of the following values.
Note that, by default, these flags take effect when showing a window.
To take effect when hiding a window,
use AW_HIDE and a logical OR operator with the appropriate flags.
AW_SLIDE
Uses slide animation. By default, roll animation is used.
This flag is ignored when used with AW_CENTER.
AW_ACTIVATE
Activates the window. Do not use this value with AW_HIDE.
AW_BLEND
Uses a fade effect.
This flag can be used only if hwnd is a top-level window.
AW_HIDE
Hides the window. By default, the window is shown.
AW_CENTER
Makes the window appear to collapse inward
if AW_HIDE is used or expand outward if the AW_HIDE is not used.
The various direction flags have no effect.
AW_HOR_POSITIVE
Animates the window from left to right.
This flag can be used with roll or slide animation.
It is ignored when used with AW_CENTER or AW_BLEND.
AW_HOR_NEGATIVE
Animates the window from right to left.
This flag can be used with roll or slide animation.
It is ignored when used with AW_CENTER or AW_BLEND.
AW_VER_POSITIVE
Animates the window from top to bottom.
This flag can be used with roll or slide animation.
It is ignored when used with AW_CENTER or AW_BLEND.
AW_VER_NEGATIVE
Animates the window from bottom to top.
This flag can be used with roll or slide animation.
It is ignored when used with AW_CENTER or AW_BLEND.
첫 번째 인자인 hwnd 는 효과를 적용하기위한 윈도우의 핸들이다.
두 번째 인자인 dwTime 은 지정된 효과를 수행할 시간으로 밀리세컨드 단위로 입력한다. 입력값이 작을 수록 에니메이션 효과의 시간이 짧아 지므로 에니메이션이 빠르게 동작한다.
세 번째 인자는 효과의 종류이다.
- AW_SLIDE : 기본 인자로 에니메이션 효과를 의미하며 생략해도 슬리이딩 효과가 있는 것 같다. AW_CENTER 가 함께 적용되면 무시된다.
- AW_ACTIVATE : 윈도우을 활성화 한다. AW_HIDE와 사용하지 않는다.
- AW_BLEND : Fading 효과
- AW_HIDE : 윈도우를 사라지게 한다.
- AW_CENTER : 윈도우의 가운데 점을 기준으로 효과를 적용한다.
- AW_HOR_POSITIVE : 윈도우를 좌에서 우로 사라지게 또는 보이게 함.
- AW_HOR_NEGATIVE : 윈도우를 우에서 좌로 사라지게 또는 보이게 함.
- AW_VER_POSITIVE : 윈도우를 위에서 아래로 사라지게 또는 보이게 함.
- AW_VER_NEGATIVE : 윈도우를 아래에서 위로 사라지게 또는 보이게 함.
아래 소스는 이 글 위에 포함되어 있는 플래시를 만들면서 작성한 코드이다.
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnBlendClick(TObject *Sender)
{
// Blending
AnimateWindow( Handle, 1000, AW_HIDE | AW_BLEND );
Sleep(1000);
AnimateWindow( Handle, 1000, AW_SLIDE | AW_BLEND );
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnCenterClick(TObject *Sender)
{
// Center
AnimateWindow( Handle, 1000, AW_HIDE | AW_CENTER );
Sleep(1000);
AnimateWindow( Handle, 1000, AW_SLIDE | AW_CENTER );
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnHPosClick(TObject *Sender)
{
// Horizontal Positive
AnimateWindow( Handle, 1000, AW_HIDE | AW_HOR_POSITIVE );
Sleep(1000);
AnimateWindow( Handle, 1000, AW_SLIDE | AW_HOR_POSITIVE );
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnHNegClick(TObject *Sender)
{
// Horizontal Negative
AnimateWindow( Handle, 1000, AW_HIDE | AW_HOR_NEGATIVE );
Sleep(1000);
AnimateWindow( Handle, 1000, AW_SLIDE | AW_HOR_NEGATIVE );
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnVPosClick(TObject *Sender)
{
// Vertical Positive
AnimateWindow( Handle, 1000, AW_HIDE | AW_VER_POSITIVE );
Sleep(1000);
AnimateWindow( Handle, 1000, AW_SLIDE | AW_VER_POSITIVE );
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnVNegClick(TObject *Sender)
{
// Vertical Negative
AnimateWindow( Handle, 1000, AW_HIDE | AW_VER_NEGATIVE );
Sleep(1000);
AnimateWindow( Handle, 1000, AW_SLIDE | AW_VER_NEGATIVE );
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnHPosVPosClick(TObject *Sender)
{
AnimateWindow( Handle, 1000, AW_HIDE | AW_HOR_POSITIVE | AW_VER_POSITIVE );
Sleep(1000);
AnimateWindow( Handle, 1000, AW_SLIDE | AW_HOR_POSITIVE | AW_VER_POSITIVE );
}
//---------------------------------------------------------------------------
void __fastcall TfrmMain::btnHNegVNegClick(TObject *Sender)
{
AnimateWindow( Handle, 1000, AW_HIDE | AW_HOR_NEGATIVE | AW_VER_NEGATIVE );
Sleep(1000);
AnimateWindow( Handle, 1000, AW_SLIDE | AW_HOR_NEGATIVE | AW_VER_NEGATIVE );
}
//---------------------------------------------------------------------------
Original Post : http://neodreamer-dev.tistory.com/275
Labels:
C++
,
C++ Builder
,
TistoryOldPost
,
Turbo C++
,
Visual C++
,
Win32API
2008/07/02
문자형식 변경하기. UNICODE <-> ASCII
Visual Studio 2005 부터는 프로젝트의 기본 설정이 Unicode 기반으로 설정되어 있다.
따라서 문자열 대입시에 신경을 좀 더 써 주어야 한다.
간단하게 UNICODE 를 ASCII 코드로 바꾸는 일은 USES_CONVERSION; 매크로를 활용하면 쉽다.
변경하고자 하는 위치에 USES_CONVERSION; 을 입력하고 입맛에 맛는 매크로 함수를 호출하기만 하면 된다.
아주 간편해서 좋은데 문제점을 안고 있는 방법이다. 왜 그런지는 자세히 파악이 되지 않았지만 위의 매크로 함수들은 메모리 활용면에서 비효율적인 문제가 있다고 한다. 간단하게 사용하는건 무리가 없는데 한번에 많은 수(10000번이상)의 변환에 이용하게되면 문제가 발생하기도 하였다.
실제로 32비트 프로젝트에서 아무런 문제가 발생하지 않았는데 이를 64비트로 변환시에 위의 함수를 사용하는 곳에서 문제가 발생하였다.
그래서 API를 활용하는 방법으로 바꾸어 사용을 하였다.
API를 이용한 문자형식 변경은 다음 두 함수를 이용하는 것이다.
사용방법.
MSDN - ATL and MFC String Conversion Macros
MSDN - MultiByteToWideChar
MSDN - WideCharToMultiByte
Original Post : http://neodreamer-dev.tistory.com/119
따라서 문자열 대입시에 신경을 좀 더 써 주어야 한다.
간단하게 UNICODE 를 ASCII 코드로 바꾸는 일은 USES_CONVERSION; 매크로를 활용하면 쉽다.
변경하고자 하는 위치에 USES_CONVERSION; 을 입력하고 입맛에 맛는 매크로 함수를 호출하기만 하면 된다.
USES_CONVERSION;
// Unicode 를 Ascii 로 변환 하고자 할 경우
W2A(LPWSTR), T2A(LPWSTR)
// Ascii 를 Unicode로 변경하고자 하는경우
A2W(LPSTR), A2T(LPSTR)
// MSDN 의 예제
//Example 1
// Convert LPCWSTR to LPCSTR.
void ExampleFunctionW( LPCWSTR pszW )
{
// Create an instance of CW2A, called pszA,
// and initialize it with pszW.
CW2A pszA( pszW );
// pszA works like an LPCSTR, and can be used thus:
ExampleFunctionA( pszA );
// Note: pszA will become invalid when it goes out of scope.
}
// Example 2
// Use a temporary instance of CW2A.
void ExampleFunctionW( LPCWSTR pszW )
{
// Create a temporary instance of CW2A,
// and initialize it with pszW.
ExampleFunctionA( CW2A( pszW ) );
// Note: the temporary instance becomes invalid
// after the execution of the statement above.
}
// Example 3
// Incorrect use of conversion macros.
void ExampleFunctionW( LPCWSTR pszW )
{
// Create a temporary instance of CW2A,
// save a pointer to it and then delete
// the temportary instance.
LPCSTR pszA = CW2A( pszW );
// The pszA in the following line is an invalid pointer,
// as the instance of CW2A has gone out of scope.
ExampleFunctionA( pszA );
}
아주 간편해서 좋은데 문제점을 안고 있는 방법이다. 왜 그런지는 자세히 파악이 되지 않았지만 위의 매크로 함수들은 메모리 활용면에서 비효율적인 문제가 있다고 한다. 간단하게 사용하는건 무리가 없는데 한번에 많은 수(10000번이상)의 변환에 이용하게되면 문제가 발생하기도 하였다.
실제로 32비트 프로젝트에서 아무런 문제가 발생하지 않았는데 이를 64비트로 변환시에 위의 함수를 사용하는 곳에서 문제가 발생하였다.
그래서 API를 활용하는 방법으로 바꾸어 사용을 하였다.
API를 이용한 문자형식 변경은 다음 두 함수를 이용하는 것이다.
// Ascii 를 Unicode 로 변환할 경우
int MultiByteToWideChar(
UINT CodePage,
DWORD dwFlags,
LPCSTR lpMultiByteStr,
int cbMultiByte,
LPWSTR lpWideCharStr,
int cchWideChar
);
// Unicode를 Ascii 로 변환할 경우
int WideCharToMultiByte(
UINT CodePage,
DWORD dwFlags,
LPCWSTR lpWideCharStr,
int cchWideChar,
LPSTR lpMultiByteStr,
int cbMultiByte,
LPCSTR lpDefaultChar,
LPBOOL lpUsedDefaultChar
);
사용방법.
// Ascii 를 Unicode 로 변환할 경우
char szSource[1024] = "Sample Ascii string";
WCHAR wszBuf[1024];
int nBufSize = 1024;
MultiByteToWideChar( CP_ACP, 0, szSource, -1, wszBuf, nBufSize);
// Unicode를 Ascii 로 변환할 경우
WCHAR wszSource[1024] = _T("Sample Unicode string");
char szDest[1024];
int nBufSize = 1024
WideCharToMultiByte( CP_ACP, 0, wszSource, -1, szDest, nBufSize,
NULL, NULL );
MSDN - ATL and MFC String Conversion Macros
MSDN - MultiByteToWideChar
MSDN - WideCharToMultiByte
Original Post : http://neodreamer-dev.tistory.com/119
Labels:
ASCII
,
C++
,
MultiByteToWideChar
,
TistoryOldPost
,
UNICODE
,
USES_CONVERSION
,
WideCharToMultiByte
,
Win32API
Subscribe to:
Posts
(
Atom
)