본문 바로가기

Windows/Windows API

CREATESTRUCT

#include <windows.h>

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
LPSTR lpszClass="CreateStruct";

struct tag_Param {
    int x;
    int y;
    char mes[128];
};

tag_Param Param={100,100,"Create Parameter"};

int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance
         ,LPSTR lpszCmdParam,int nCmdShow)
{
    HWND hWnd;
    MSG Message;
    WNDCLASS WndClass;
    g_hInst=hInstance;
    
    WndClass.cbClsExtra=0;
    WndClass.cbWndExtra=0;
    WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
    WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
    WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    WndClass.hInstance=hInstance;
    WndClass.lpfnWndProc=(WNDPROC)WndProc;
    WndClass.lpszClassName=lpszClass;
    WndClass.lpszMenuName=NULL;
    WndClass.style=CS_HREDRAW | CS_VREDRAW;
    RegisterClass(&WndClass);

    hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW,
        100,100,300,200,
        NULL,(HMENU)NULL,hInstance,(LPVOID)&Param);
    ShowWindow(hWnd,nCmdShow);
    
    while(GetMessage(&Message,0,0,0)) {
        TranslateMessage(&Message);
        DispatchMessage(&Message);
    }
    return Message.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
    HDC hdc;
    PAINTSTRUCT ps;
    CREATESTRUCT cs;                // CrateWindow 에서 지정한 인수를 모두 조사 할 수 있다.
    static tag_Param WndParam;
    switch(iMessage) {
    case WM_CREATE:
        cs=*(LPCREATESTRUCT)lParam;
        WndParam=*((tag_Param *)(cs.lpCreateParams));
        return 0;
    case WM_PAINT:
        hdc=BeginPaint(hWnd, &ps);
        TextOut(hdc,WndParam.x,WndParam.y,WndParam.mes,strlen(WndParam.mes));
        EndPaint(hWnd, &ps);
        return 0;
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
    return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}

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

spy (EnumWindows)  (0) 2013.10.01
닫기 버튼 삭제 (WndClass.style=CS_NOCLOSE)  (0) 2013.10.01
윈도우 속성변경 WNDCLASS (SetClassLong)  (0) 2013.10.01
SetClassLong, GetClassLong  (0) 2013.10.01
차일드 윈도우3 (child)  (0) 2013.10.01