[WIN_API] Windows API프로그래밍 기본 골격



 


#include  <windows.h>

LRESULT  CALLBACK  WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE  g_hInst;
LPCTSTR  lpszClass=TEXT("First");

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;
WndClass.lpszClassName=lpszClass;
WndClass.lpszMenuName=NULL;
WndClass.style=CS_HREDRAW  |  CS_VREDRAW;
RegisterClass(&WndClass);

hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,(HMENU)NULL,hInstance,NULL);
ShowWindow(hWnd,nCmdShow);

while  (GetMessage(&Message,NULL,0,0))  {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return  (int)Message.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));
}

-------------------------------------------------------------------------
Visual  Studio에서  Win32  빈  프로젝트를  생성하고
위에  소스를  그대로  붙여서  Build하면  빈  윈도우가  생긴다.
여기서  살을  붙여서  원하는걸  만들어도  됨..

 

 [ 등록일 : 2009-08-11 11:0 ]  

 

 

[목록]