WM_GESTURE에서 PAN 입력 받기 (one/ two finger)

 

WM_GESTURE 메시지를 등록하여 이벤트를 처리할 경우

등록한 OnGesture 함수에 two finger pan의 발생은 들어오는데

One finger panOnGesture이벤트가 발생조차 되지 않는다

 

이때 모든 pan 동작에 대하여 메시지를 받을 수 있도록

WM_GESTURENOTIFY 메시지에서 Gesture를 설정해주어야 한다.

 



    switch (message)

    {

    case WM_GESTURENOTIFY:

        GESTURECONFIG gc = {0,GC_ALLGESTURES,0};

        BOOL bResult = SetGestureConfig(hWnd,0,1,&gc,sizeof(GESTURECONFIG));

           

        if(!bResult)

        {

            // an error

        }

        return DefWindowProc(hWnd, WM_GESTURENOTIFY, wParam, lParam);

    }

     

 

 

WM_GESUTRENOTIFY에서 SetGestureConfig를 이용하여 어떤 제스처에 대해서만 메시지를 받을지 설정하고 나면

해당하는 제스처가 발생했을 경우 WM_GESTURE 메시지를 받을 수 있다

 

SetGestureConfig 함수를 이용하여 설정하기 위해서는 CGestureConfig 객체를 인자로 넘겨주는데

CGestureConfig로 제스처 사용 여부를 설정하는 방법은 해당하는 제스처의 Enable 함수를 호출하면 된다

 

Ex)

Pan 동작에 대하여 메시지를 설정하려면

EnablePan() 함수를 호출하여 Pan 동작 사용시에는 EnablePan(TRUE), EnablePan(FALSE)의 값으로 설정해준다

 

Pan의 경우 여러가지 동작이 있는데

#define GC_PAN_WITH_SINGLE_FINGER_VERTICALLY        0x00000002

#define GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY      0x00000004

#define GC_PAN_WITH_GUTTER                          0x00000008

#define GC_PAN_WITH_INERTIA                         0x00000010

 

EnablePan함수에서 flagDefault는  

GC_PAN_WITH_GUTTER | GC_PAN_WITH_INERTIA 로 되어 있어서,

한 손가락에 대한 터치 제스처를 받기 위해서는  GC_PAN_WITH_SINGLE_FINGER_VERTICALLY | GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY 값도 flag 설정을 해주어야 한다

 

그래서 모든 Pan 동작을 받기 위하여

gestureConfig.EnablePan(TRUE, GC_PAN);

로 설정을 해주었다

 

WM_GESTURE 관한 내용

https://msdn.microsoft.com/en-us/library/windows/desktop/dd353243(v=vs.85).aspx

window 깜빡임 처리 - WM_ERASEBKGND와 WM_PAINT

Window는 뭔가 새로 그려야할 필요성 있을 때마다 WM_PAINT Message를 받습니다. OnPaint라는 이름으로 WM_PAINT에 대한 Handler Function이 보통 만들어지죠. System으로부터 WM_PAINT가 날아오는 상황은 다음과 같습니다.

    - 윈도우가 처음 생성되었을 때
    - 윈도우의 위치가 이동되었을 때 
    - 윈도우의 크기가 변경되었을 때(최소 및 최대화 포함)
    - 윈도우의 전체 또는 일부가 다른 윈도우에 가려져 있다가 나타날 때
    - 윈도우가 스크롤 될 때
    - UpdateWindow나 RedrawWindow 함수가 불렸을 때
    - InvalidateRect나 InvalidateRgn 함수가 불려서 다시 그려져야할 영역이 발생 한 후,
      Message Queue에 다른 처리할 Windows Message가 없을 때

그런데 WM_PAINT가 날아오기 '전'에 대부분 같이 따라오는 Message가 있습니다 WM_ERASEBKGND라는 것으로, Erase Background 라는 의미죠. 즉, 배경을 지워라.

Window의 기본 Message Procedure(DefWindowProc)는 사용자가 WM_ERASEBKGND를 받고도 아무 처리를 하지 않으면, WNDCLASS의 hbrBackground 맴버에 정의된 색상으로 배경을 지워버립니다. 깜빡이는 것은 아래 처럼 되기 때문에 발생하는 것이지요.

    1. WM_ERASEBKGND 받음
    2. 배경 지움
    3. WM_PAINT 받음
    4. Image 다시 그림

2까지가 '깜'이고 4까지 가면 '빡'이 됩니다. 깜빡 깜빡의 실체는 이것입니다.
손쉬운 처리는 WM_ERASEBKGND를 받았을 때, 배경을 안지우도록 하는 방법입니다. 보통 OnEraseBkgnd 정도의 이름을 갖게 되는 WM_ERASEBKGND Message Handler에서 0을 return 하면 됩니다.

    BOOL CAboutDlg::OnEraseBkgnd(CDC* pDC)
    {
        return 0;
    }

깜빡 거리는 것이 WM_PAINT Message Handler에서 그려주는 어떤 것이 아니라, 또 다른 Window인 '자식' Control이라면, Window Styles 중에 WS_CLIPCHILDREN Style을 '부모' Window에 먹여서 자식 Control에 의해 가려지는 영역은 그리기 대상에서 아예 제외시켜버리는 것이 일반적인 해결책입니다.

출처 : 데브피아 ( 박재민(MAXIST) )

 

미리 컴파일된 헤더 사용

1. 프로젝트 속성 변경


구성 속성 > C/C++> 미리 컴파일된 헤더


미리 컴파일된 헤더  사용(/Yu)

미리 컴파일된 헤더 파일 StdAfx.h

미리 컴파일된 헤더 출력 파일 $(IntDir)$(TargetName).pch



2. ShdAfx.h 헤더 파일 생성

 

3. ShdAfx.cpp 파일 생성


4. ShdAfx.cpp의 속성 변경

구성 속성 > c/c++ > 미리 컴파일된 헤더


미리 컴파일된 헤더 만들기(/Yc)

미리 컴파일된 헤더 파일 StdAfx.h

미리 컴파일된 헤더 출력 파일 $(IntDir)$(TargetName).pch






5. ShdAfx.cpp 파일에 ShdAfx.h 추가

#include "ShdAfx.h"


6. include 된 헤더파일 앞쪽에 ShdAfx.h 헤더 파일 include


7. 자주 변경되지 않는 헤더 파일 ShdAfx.h 로 이동


사용자가 만든 헤더는 포함하지 않는다. 

인터넷에 연결 되어있는지 확인하는 API



InetIsOffline


BOOL InetIsOffline(
  DWORD dwFlags
);


Returns TRUE if the local system is not currently connected to the Internet. Returns FALSE if the local system is connected to the Internet or if no attempt has yet been made to connect to the Internet.

=================================================================================================



int InternetGetConnectedState()

{
DWORD dwConnectionTypes;
if(InternetGetConnectedState(&dwConnectionTypes, 0)) // 정상적으로 검사됨
{
   
if((dwConnectionTypes & INTERNET_CONNECTION_MODEM) != 0)
ShowMessage(
"Modem으로 인터넷 사용중...");
   
if((dwConnectionTypes & INTERNET_CONNECTION_LAN) != 0)
ShowMessage(
"LAN으로 인터넷 사용중...");
   
if((dwConnectionTypes & INTERNET_CONNECTION_PROXY) != 0)
ShowMessage(
"Proxy로 인터넷 사용중...");
   
if((dwConnectionTypes & INTERNET_CONNECTION_MODEM_BUSY) != 0)
ShowMessage(
"Modem을 다른 용도로 사용중");
   
if((dwConnectionTypes & INTERNET_RAS_INSTALLED) != 0)
ShowMessage(
"RAS가 설치되어 있음");
   
if((dwConnectionTypes & INTERNET_CONNECTION_OFFLINE) != 0)
ShowMessage(
"오프라인");
   
if((dwConnectionTypes & INTERNET_CONNECTION_CONFIGURED) != 0)
ShowMessage(
"인터넷 연결이 설정되었음");
}
else
   ShowMessage("검사할 수 없습니다");

return 0;

}

windows 버전 체크

bool is_version_xp()

{

OSVERSIONINFO osvi = {};

    BOOL bIsWindowsXPorLater;


    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);


    GetVersionEx(&osvi);


bIsWindowsXPorLater = ( (osvi.dwMajorVersion == 5.1) || (osvi.dwMajorVersion == 5.2)) ;

       //( (osvi.dwMajorVersion > 5) ||

       //( (osvi.dwMajorVersion == 5) && (osvi.dwMinorVersion >= 1) ));


    if(bIsWindowsXPorLater)

return true;

}



http://msdn.microsoft.com/en-us/library/ms724451%28VS.85%29.aspx

c++ 작업 스케줄러 동작 추가




작업 스케줄러를 사용하면

동작 탭에 등록된 작업을 수행하게 된다.


현재 등록되어 있는 작업의 경우 

c:\windows\system32\notepad.exe를 실행하는 작업만 등록되어 있는데


한가지 작업에서 여러가지 동작을 수행할 수 있다.

* 여러개로 등록된 동작은 순차적으로 동작 함.

예) 아래 그림에 있는 동작의 순서는 NOTEPAD.EXE가 종료 되면, winver.exe가 실행이 된다. 







동작을 생성하는 방법은

이미 만들었던 IActionCollection 인터페이스에 Create()로 새로운 동작을 추가해주는 것이다.


Create로 만들 수 있는 동작의 종류는 아래와 같다.


ValueMeaning
TASK_ACTION_EXEC
0

The action performs a command-line operation. For example, the action could run a script, start an executable, or, if the name of a document is provided, find its associated application and start the application with the document.

TASK_ACTION_COM_HANDLER
5

The action fires a handler.

TASK_ACTION_SEND_EMAIL
6

This action sends an email message.

TASK_ACTION_SHOW_MESSAGE
7

This action shows a message box.



그리고 맨 처음 동작 추가와 동일한 방식으로 

동작을 추가해 준다

  

    //  Create the action, specifying that it is an executable action.

    IAction *pAction1 = NULL;

    hr = pActionCollection->Create( TASK_ACTION_EXEC, &pAction1 );

    pActionCollection->Release();

    if( FAILED(hr) )

    {

        printf("\nCannot create the action: %x", hr );

        pRootFolder->Release();

        pTask->Release();

        CoUninitialize();

        return 1;

    }


    IExecAction *pExecAction1 = NULL;

    //  QI for the executable task pointer.

    hr = pAction1->QueryInterface( 

        IID_IExecAction, (void**) &pExecAction1 );

    pAction1->Release();

    if( FAILED(hr) )

    {

        printf("\nQueryInterface call failed for IExecAction: %x", hr );

        pRootFolder->Release();

        pTask->Release();

        CoUninitialize();

        return 1;

    }


//  Get the windows directory and set the path to notepad.exe.

wstring wstrWinVerExecutablePath = _wgetenv( L"WINDIR");

    wstrWinVerExecutablePath += L"\\SYSTEM32\\winver.exe";



    //  Set the path of the executable to notepad.exe.

    hr = pExecAction1->put_Path( _bstr_t( wstrWinVerExecutablePath.c_str() ) );

    pExecAction1->Release();

    if( FAILED(hr) )

    {

        printf("\nCannot set path of executable: %x", hr );

        pRootFolder->Release();

        pTask->Release();

        CoUninitialize();

        return 1;

    }

 


c++ 작업 스케줄러 > 가장 높은 수준의 권한으로 실행

예제에는 가장 높은 수준의 권한으로 실행시키는 옵션이 없다.




ITaskSettings 에서 priority 메소드를 이용해서 

권한을 HIGH_PRIORITY_CLASS로 부여해도 저 체크 박스는 여전히 체크가 되어 있지 않음..


현재 사용중인 인터페이스에서

작업의 속성을 변경 시킬 수 있는 옵션을 모두 찾았는데 못 찾았음...


사용중이 아니여서 찾을 수가 없었다 

작업 정의를 구성요소를 다시 살펴 본 결과


작업정의
Actions작업에서 수행하는 임무를 정의하는 한 개 이상의 동작입니다.
Triggers작업이 시작할 때를 나타내는 한 개 이상의 트리거입니다.
Principal권한 부여와 감사는 보안 컨텍스트에 바탕을 둡니다.
Settings이러한 설정으로 런타임 동작을 제어하고 작업을 제한할 수 있습니다.
Data동작에 사용할 수 있는 문자열입니다.
RegistrationInfo관리 기록 정보입니다.


저런게 있었음 저 Principal

을 이용하여 가장 높은 수준의 권한으로 실행 가능하다


사용 방법은


IPrincipal의 인터페이스 포인터를 반환 받아

put_RunLevel 메소드를 이용하여 가장 높은 수준의 권한으로 실행하도록 설정한다.

그리고 받은 포인터는 해제 한다.


IPrincipal *pPrincipal = NULL;

pTask->get_Principal(&pPrincipal);


pPrincipal->put_RunLevel(TASK_RUNLEVEL_HIGHEST);


pPrincipal->Release();




속성 값은 아래와 같다

ValueMeaning
TASK_RUNLEVEL_LUA
0

Tasks will be run with the least privileges.

TASK_RUNLEVEL_HIGHEST
1

Tasks will be run with the highest privileges.




TASK_RUNLEVEL_HIGHEST 로 설정하면

가장 높은 수준의 권한으로 실행 가능하다


'c/c++' 카테고리의 다른 글

windows 버전 체크  (0) 2014.03.11
c++ 작업 스케줄러 동작 추가  (0) 2014.03.05
c++ 관리자 권한으로 프로그램 실행시키는 방법  (0) 2014.03.03
스레드 생성  (0) 2013.04.05
정규식 표현  (0) 2013.03.27

ITaskSettings interface

Properties

The ITaskSettings interface has these properties.

PropertyAccess typeDescription

AllowDemandStart(요청 시 작업이 실행되도록 허용)

Read/write

Gets or sets a Boolean value that indicates that the task can be started by using either the Run command or the Context menu.

사용 예)

put_AllowDemandStart(VARIANT_FALSE);

AllowHardTerminate(요청할 때 실행 중인 작업이 끝나지 않으면 강제로 작업 중지)

Read/write

Gets or sets a Boolean value that indicates that the task may be terminated by using TerminateProcess.

사용 예)

put_AllowHardTerminate(VARIANT_FALSE); // 작업 중지

Compatibility

Read/write

Gets or sets an integer value that indicates which version of Task Scheduler a task is compatible with.

DeleteExpiredTaskAfter

Read/write

Gets or sets the amount of time that the Task Scheduler will wait before deleting the task after it expires.

DisallowStartIfOnBatteries(컴퓨터의 AC 전원이 켜져 있는 경우에만 작업 시작)

Read/write

Gets or sets a Boolean value that indicates that the task will not be started if the computer is running on battery power.

Enabled

Read/write

Gets or sets a Boolean value that indicates that the task is enabled. The task can be performed only when this setting istrue.

ExecutionTimeLimit

Read/write

Gets or sets the amount of time that is allowed to complete the task.

Hidden(숨김)

Read/write

Gets or sets a Boolean value that indicates that the task will not be visible in the UI by default.

사용 예)

put_Hidden(VARIANT_TRUE)

IdleSettings

Read/write

Gets or sets the information that specifies how the Task Scheduler performs tasks when the computer is in an idle state.

MultipleInstances

Read/write

Gets or sets the policy that defines how the Task Scheduler handles multiple instances of the task.

NetworkSettings

Gets or sets the network settings object that contains a network profile identifier and name. If theRunOnlyIfNetworkAvailable property of ITaskSettings is trueand a network propfile is specified in the NetworkSettingsproperty, then the task will run only if the specified network profile is available.

Priority

Read/write

Gets or sets the priority level of the task.

RestartCount(다음 횟수까지 다시 시작 시도)

Read/write

Gets or sets the number of times that the Task Scheduler will attempt to restart the task.

사용 예)

put_RestartCount(10);

RestartInterval(작업이 실패하는 경우 다시 시작 간격)

Read/write

Gets or sets a value that specifies how long the Task Scheduler will attempt to restart the task.

사용 예)

put_RestartInterval(_bstr_t(L"PT5M"));

RunOnlyIfNetworkAvailable(다음 네트워크 연결을 사용할 수 있는 경우에만 시작)

Read/write

Gets or sets a Boolean value that indicates that the Task Scheduler will run the task only when a network is available.

put_RunOnlyIfNetworkAvailable(VARIANT_TRUE)

StartWhenAvailable(예약된 시작 시간을 놓친 경우 가능한 대로 빨리 작업 시작)


Read/write

Gets or sets a Boolean value that indicates that the Task Scheduler can start the task at any time after its scheduled time has passed.

put_StartWhenAvailable(VARIANT_TRUE);

StopIfGoingOnBatteries()

(컴퓨터 배터리 전원으로 전환되는 경우 중지)

Read/write

Gets or sets a Boolean value that indicates that the task will be stopped if the computer switches to battery power.


WakeToRun(이 작업을 실행하기 위해 절전 모드 종료)

Read/write

Gets or sets a Boolean value that indicates that the Task Scheduler will wake the computer before it runs the task.

put_WakeToRun(VARIANT_TRUE);

XmlText

Read/write

Gets or sets an XML-formatted definition of the task settings.

 

'c/c++ > 레퍼런스' 카테고리의 다른 글

ILogonTrigger interface  (0) 2014.03.03
Shellexecute()  (0) 2013.02.06
PathFindSuffixArray 경로에 찾고자 하는 문자열 있는지 확인  (0) 2013.01.16

c++ 관리자 권한으로 프로그램 실행시키는 방법

관리자 권한이 필요한 프로그램이 있다.

예를들어 레지스트리를 조작해야 한다거나, 서비스를 설치 및 실행 시켜주어야 할 경우


사용자 계정에 UAC가 켜져있을 경우에 

관리자 권한이 필요한 프로그램을 그냥 실행하면 원하는 결과를 얻지 못하게 된다.

ex)

UAC가 켜져 있는 관리자 계정에서 

일반 프로그램이 서비스를 설치

==> 실패 OpenSCM 

GetLastError () 값 ERROR_ACCESS_DENIED : 5


따라서 이런 프로그램의 경우 관리자 권한으로 프로그램을 실행시켜주어야 한다







관리자 권한으로 프로그램을 실행시켜주는 방법


1. 사용자가 해당하는 프로그램을 마우스 오른쪽 클릭하여 실행시켜주는 방법이 있다.


하지만 사용자가 더블 클릭으로 걍 실행하면?? gg





2. 컴파일 속성의 변경으로 사용자가 마우스 왼쪽 클릭을 하지 않고 관리자 권한으로 실행시킬 수 있는 방법이 있다.


속성 > 구성 속성 > 링커 > 매니페스트 파일 > UAC 실행 수준

여기서 UAC 실행 수준의 값을 requireAdministrator 로 변경해주면 된다.



requireAdministrator로 값이 설정된 프로그램의 경우 

사용자가 프로그램을 실행 시키면  마우스 오른쪽 버튼을 클릭하지 않아도

사용자가 실행할때 관리자 권한으로 실행할 것인지 묻는 창이 나온다.


예를 누르면 관리자 권한으로 프로그램이 실행되고, 

아니요를 누르면 프로그램은 실행되지 않는다





'c/c++' 카테고리의 다른 글

c++ 작업 스케줄러 동작 추가  (0) 2014.03.05
c++ 작업 스케줄러 > 가장 높은 수준의 권한으로 실행  (0) 2014.03.05
스레드 생성  (0) 2013.04.05
정규식 표현  (0) 2013.03.27
스레드 생성  (0) 2013.03.26

ILogonTrigger interface


Properties

The ILogonTrigger interface has these properties.


PropertyAccess typeDescription

Delay (작업 지연 시간)

Read/write

Gets or sets a value that indicates the amount of time between when the user logs on and when the job is started.

Enabled(사용)

Read/write

Inherited from the ITrigger interface. Gets or sets a Boolean value that indicates whether the trigger is enabled.

EndBoundary(만료)

Read/write

Inherited from the ITrigger interface. Gets or sets the date and time when the trigger is deactivated. The trigger cannot start the task after it is deactivated.


사용 예)

put_EndBoundary(_bstr_t(L"2015-05-02T08:00:00"))

ExecutionTimeLimit (다음 기간 이상 실행되는 작업 중지)

Read/write

Inherited from the ITrigger interface. Gets or sets the maximum amount of time that the task launched by this trigger is allowed to run.

Id

Read/write

Inherited from the ITrigger interface. Gets or sets the identifier for the trigger.

Repetition (작업 반복 간격)

Read/write

Inherited from the ITrigger interface. Gets or sets a value that indicates how often the task is run and how long the repetition pattern is repeated after the task is started.

StartBoundary (활성화)

Read/write

Inherited from the ITrigger interface. Gets or sets the date and time when the trigger is activated.


사용 예)

put_StartBoundary(_bstr_t(L"2014-01-01T12:05:00"));

Type(작업 시작)

Read-only

Inherited from the ITrigger interface. Gets the type of the trigger.

TASK_TRIGGER_EVENT 이벤트 상태

TASK_TRIGGER_TIME 매일 지정된 시간

TASK_TRIGGER_DAILY 매일

TASK_TRIGGER_WEEKLY 매주

TASK_TRIGGER_MONTHLY 매달

TASK_TRIGGER_MONTHLYDOW 매달 지정된 날 

TASK_TRIGGER_IDLE 유휴 상태

TASK_TRIGGER_REGISTRATION 등록 되었을 때

TASK_TRIGGER_BOOT 시작할 때

TASK_TRIGGER_LOGON 로그온할 때

TASK_TRIGGER_SESSION_STATE_CHANGE 세션 상태 변경

UserId(특정 사용자)

Read/write

Gets or sets the identifier of the user.

NULL 모든 사용자 put_UserId() 로 사용자를 지정해주지 않으면 됨


 

'c/c++ > 레퍼런스' 카테고리의 다른 글

ITaskSettings interface  (0) 2014.03.04
Shellexecute()  (0) 2013.02.06
PathFindSuffixArray 경로에 찾고자 하는 문자열 있는지 확인  (0) 2013.01.16