레지스트리키를 만들어주는 API


RegCreateKeyEx( hKey,lpKey,0,NULL,REG_OPTION,KEY_OPTION,NULL,&key,NULL);


hKey : 생성할 키의 루트키이다.

lpKey : 생성할 서브키(문자열)

NULL : 키의 지정된 클래스명,보통 NULL

REG_OPTION : REG_OPTION_NON_VOLATILE, REG_OPTION_VOLATILE 중에 선택할 수 있는데 전자는 정보를 파일에 기록한다는 의미이고, 후자는 시스템종료시 기록을 지우겠다는 의미이다. 보통 전자를 선택함.


KEY_OPTION : KEY_WRITE , KEY_ALL_ACCESS , KEY_READ 바로 눈에 보이겠지만, WRITE는 쓰기에 관한 모든권한, 가운데는 모든권한, READ는 읽기와 관련된 모든권한을 설정한다는 의미이다.


NULL : SECURITY_ATTRIBUTES 구조체 포인터 ,보통 NULL

&key : 생성된 키의 핸들포인터

NULL : DWROD포인터 보통 NULL



여기서 루트키에 대해서 잠깐 살펴보고 넘어가자.

루트키란 , 실행창에서 regedit을 치고 들어가면


위와 같은 창을 볼 수 있다. 내컴퓨터 하위항목들이 루트키에 해당함.

(각 루트키에는 서브키를 가지고 있다.)


HKEY_CLASSES_ROOT 

윈도우에 사용하는 프로그램과 각 프로그램에 연결된 확장명에 대한 정보, 단축키,드래그 앤 드롭, 윈도우의 관련된 정보가 저장.


HKEY_CURRENT_USER 

사용자가 설정한 윈도우 환경에 대한 정보가 저장


HKEY_LOCAL_MACHINE 

컴퓨터에 설치된 하드웨어와 소프트웨어에 관련된 모든 설정 내용이 저장. 특히 하드웨어와 하드웨어를 구동시키는 드라이버와 설정 사항에 대한 정보가 저장.


HKEY_USERS 

HKEY_CURRENT_USER에 저장된 정보 전체와 데스크탑 설정, 네트워크 연결등의 정보가 저장되어있다.


HKEY_CURRENT_CONFIG 

HKEY_LOCAL_MACHINE 키의 하위키인 Config키의 내용을 담고 있다.




열려있는 레지스트리 키를 이용하여 명시된 항목이름의 데이터 형식이나 내용을 설정하는 사용


RegSetValueEx(HKEY hKey,LPCTSTR lpValueName,DWORD lpReserved, DWORD dwType, const BYTE *lpData, DWORD cbData);


hKey : 현재 열어서 사용하고 있는 레지스트리 키에 대한 핸들


lpValueName : 정보를 설정하고자 하는 항목의 이름을 가지고 있는 문자열의 주소 명시.


lpReserved : 0으로 예약.


dwType : lpData에 들어있는 정보를 설정할 항목의 데이터 형식을 명시,

REG-BINARY : 이진값으로 구성된 데이터 형식

REG_DWORD : 32비트 크기의 정수 데이터 형식

REG_DWORD_LITTLE_ENDIAN :32비트 크기정수(바이트정렬little endian)

REG_DWORD_BIG_ENDIAN : 32비트 크기정수(바이트정렬 big endian)

REG_SZ : NULL로 끝나는 문자열 형식

REG_MULTI_SZ : NULL로 끝나는 문자열이 나열되어 있는 형식

 종결시에는 NULL을 두번.

REG_EXP_AND_SZ : NULL로 끝나는 문자열형식,환경변수참조가능

REG_RESOURCE_LIST : 장치드라이버의 자원목록에 관련된 형식

REG_NONE  : 데이터 형식이 정해져 있지 않은 경우


lpData  : 설정할 항목에 사용할 데이터가 들어있는 메모리 공간의 주소를 명시.


cbData : lpData 매개변수에 사용한 메모리 공간의 크기를 명시.


'System > Windows' 카테고리의 다른 글

Message HOOK - Window  (0) 2012.08.20
CreateProcess  (2) 2012.08.03
파일복사 api  (0) 2012.08.02
WinApi MessageBox  (0) 2012.07.26
CreateWindow  (0) 2012.07.26

MessageBox(내용,타이틀,옵션)

MessageBox 옵션 :

  • MB_ABORTRETRYIGNORE   The message box contains three pushbuttons: Abort, Retry, and Ignore.

  • MB_OK   The message box contains one pushbutton: OK.

  • MB_OKCANCEL   The message box contains two pushbuttons: OK and Cancel.

  • MB_RETRYCANCEL   The message box contains two pushbuttons: Retry and Cancel.

  • MB_YESNO   The message box contains two pushbuttons: Yes and No.

  • MB_YESNOCANCEL   The message box contains three pushbuttons: Yes, No, and Cancel.

Message-Box Modality

  • MB_APPLMODAL   The user must respond to the message box before continuing work in the current window. However, the user can move to the windows of other applications and work in those windows. The default is MB_APPLMODAL if neither MB_SYSTEMMODAL nor MB_TASKMODAL is specified.

  • MB_SYSTEMMODAL   All applications are suspended until the user responds to the message box. System-modal message boxes are used to notify the user of serious, potentially damaging errors that require immediate attention and should be used sparingly.

  • MB_TASKMODAL   Similar to MB_APPLMODAL, but not useful within a Microsoft Foundation class application. This flag is reserved for a calling application or library that does not have a window handle available.

Message-Box Icons

  • MB_ICONEXCLAMATION   An exclamation-point icon appears in the message box.

  • MB_ICONINFORMATION   An icon consisting of an “i” in a circle appears in the message box.

  • MB_ICONQUESTION   A question-mark icon appears in the message box.

  • MB_ICONSTOP   A stop-sign icon appears in the message box.

Message-Box Default Buttons

  • MB_DEFBUTTON1   The first button is the default. Note that the first button is always the default unless MB_DEFBUTTON2 or MB_DEFBUTTON3 is specified.

  • MB_DEFBUTTON2   The second button is the default.

  • MB_DEFBUTTON3   The third button is the default.


From MSDN


ex)

#include<Windows.h>


#define CONTENT "Error code:1401 - 응용 프로그램 구성이 올바르지 않기 때문에 이 응용 프로그램을 시작하지 못했습니다. 이 문제를 해결하려면 응용 프로그램을 다시 설치하십시오.\nDLL <C:\\Program Files\Autodesk\3ds Max 9\Plugins\CurveCtl.dle> failed to initialize."

int main(){

MessageBox(NULL,CONTENT,"Error ",MB_RETRYCANCEL | MB_ICONSTOP);

return 0;

}



'System > Windows' 카테고리의 다른 글

Message HOOK - Window  (0) 2012.08.20
CreateProcess  (2) 2012.08.03
파일복사 api  (0) 2012.08.02
WinAPI 레지스트리  (0) 2012.07.27
CreateWindow  (0) 2012.07.26
#include<Windows.h>

API선언, 상수, 데이터타입, 필요한 헤더들 포함.


Winmain

- Windows 프로그램의 엔트리 포인트


hInstance

- 프로그램의 인스턴스 핸들

- 인스턴스(Instance) : 클래스가 메모리에 실제로 구현된 실체


WndClass

-윈도우를 생성하는 클래스




typedef struct tagWNDCLASS{

UINT style;

WNDPROC lpfnWndProc;

int            cbClsExtra;

int            cbWndExtra;

HINSTANCE    hInstance;

HICON            hIcon;

HCURSOR        hCursor;

HBRUSH            hbrBackground;

LPCSTR            lpszMenuName;

LPCSTR            lpszCLassName;

}WNDCLASS;



style : 윈도우의 스타일 지정

lpfnWndProc : 메시지 발생시 여기서 지정한 함수를 호출하여 메시지를 처리함.

cbClsExtra,cbWndExtra : 예약영역

hInstance : 윈도우 클래스를 사용하느 프로그램

hIcon,hCursor : 마우스 커서와 아이콘 지정

hbrBackground : 배경 색지정

lpszMenuName : 프로그램이 사용할 메뉴 지정

lpszClassName : 클래스 이름 정의


윈도우 클래스를 정의한 후에는 다음과 같이 등록한다.

RegisterClass(&ClassName);


윈도우 생성 함수 : CreateWindow


HWND CreateWindow(lpszClassName,lpszWindowName,dwStyle,x,y,nWidth,nHeight,hwndParent,hmenu,hinst,lpvParam);


lpszClassName : 생성하고자 하는 윈도우 클래스 지정

lpszWindowName : 타이틀 바에 나타날 문자

dwStyle : 윈도우 형태 지정

X,Y,nWidth,nHeigth : 윈도우 크기와 위치 지정

hWndParent : 부모윈도우 존재 시 부모윈도우 핸들 지정

hmenu : 윈도우에서 사용할 메뉴의 핸들 지정

hinst : 윈도우를 만드는 주체 지정

lpvParam : 보통 NULL


화면 출력함수

ShowWindow(hWnd,nCmdShow);


hwnd : 출력하고자 하는 윈도우의 핸들 값

nCmdShow : 화면에 출력하는 방식 지정.


윈도우 창띄우기 소스


#include <windows.h>

 

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);


int WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevious, LPSTR lpCmdString, int CmdShow )

{

    WNDCLASS windowClass;

    HWND hWnd;


    windowClass.cbClsExtra = 0;

    windowClass.cbWndExtra = 0;

    windowClass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);

    windowClass.hCursor = LoadCursor (NULL, IDC_ARROW);

    windowClass.hIcon = LoadIcon (NULL, IDI_APPLICATION);

    windowClass.hInstance = hInstance;

    windowClass.lpfnWndProc = (WNDPROC)WndProc;

    windowClass.lpszClassName = "ClassName";

    windowClass.lpszMenuName = NULL;

    windowClass.style = CS_HREDRAW | CS_VREDRAW;

 

    if (!RegisterClass (&windowClass))

    {

        MessageBox(NULL, "Error : Cannot Register Window Class", "ERROR", MB_OK);

        return (0);

    } // end if

 

    hWnd = CreateWindow ("ClassName",   // 클래스명

       "Taesun1114",   // 윈도우 타이틀

       WS_OVERLAPPEDWINDOW | 

       WS_VISIBLE |

       WS_SYSMENU |

       WS_CLIPCHILDREN |

       WS_CLIPSIBLINGS,

       100,     // 윈도우 좌표 x

       100,     // 윈도우 좌표 y

       640,     // 윈도우 너비

       480,     // 윈도우 높이

       NULL, 

       NULL, 

       hInstance, 

       NULL);

 

    if ( hWnd == NULL )

    {

        MessageBox(NULL, "Error : Failed to Create Window", "ERROR", MB_OK);

        return (0);

    } // end if

 

    ShowWindow ( hWnd , CmdShow);

    UpdateWindow ( hWnd );

 

    MSG msg;

    while(1)

    {

        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))

        {

            if (msg.message == WM_QUIT)

                break;

 

            TranslateMessage(&msg); 

DispatchMessage (&msg);

        } // end if

    } // end while

 

    return msg.wParam;

}


LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam){

switch(iMessage)

{

case WM_DESTROY:

PostQuitMessage(0);

return 0;

}

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

}


윈도우가 띄어짐!!


'System > Windows' 카테고리의 다른 글

Message HOOK - Window  (0) 2012.08.20
CreateProcess  (2) 2012.08.03
파일복사 api  (0) 2012.08.02
WinAPI 레지스트리  (0) 2012.07.27
WinApi MessageBox  (0) 2012.07.26

+ Recent posts