본문 바로가기

[+] Information/[-] ETC

API MessageBox 예제

#include <windows.h>

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
LPSTR lpszClass="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)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,0,0,0)) {
  TranslateMessage(&Message);
  DispatchMessage(&Message);
 }
 return Message.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
 switch(iMessage) {
 case WM_LBUTTONDOWN: // 마우스 왼쪽 버튼을 누르면 발생하는 메시지.
  MessageBox(hWnd, TEXT("마우스 왼쪽 버튼을 눌렀습니다"), TEXT("메시지 박스"), MB_OK); // MessageBox 함수 호출.
  return 0;
 case WM_DESTROY:
  PostQuitMessage(0);
  return 0;
 }
 return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}



출력결과:

'[+] Information > [-] ETC' 카테고리의 다른 글

군대가기전에 TIP  (10) 2009.12.21
[Tip] 메모리에 written, read 될 수 없습니다??  (2) 2009.09.27
API GraphOut 예제  (0) 2009.07.20
API DrawText 예제  (0) 2009.07.18