2014년 4월 10일 목요일

WIN32 API기반으로 간단히 구현해 본 StopWatch

API를 이용하여 간단하게 교육용 소스로 스톱워치를 만들어 보았다.

타이머를 하나 생성해서 돌려주면

타이머 이벤트가 발생할 때 마다 undercomma (1/100초)가 하나씩 증가하고

이넘들이 100개 모이면 1초 , 1초가 60개 모이면 다시 1분이 증가하는 순서이다.

소스는 간단함..

문제점이 있다면 실제 시간하고 맞지 않는다는것이다.
(실제시간 1초보다 타이머상의 1초가 증가하는데 더 오래걸린다)



//============================================================================================
#include <windows.h>
#include <stdio.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
HINSTANCE g_hInst;
HWND hWndMain;
LPCTSTR lpszClass=TEXT("StopWatch");
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)(COLOR_WINDOW+1);
 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,300,220,
  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)
{
   HDC hdc;
   PAINTSTRUCT ps;
   HFONT font, oldfont;
   static int min, sec, undercomma; // 분, 초, 0.01초
   switch (iMessage) {
     case WM_CREATE:
      hWndMain=hWnd;
      CreateWindow(TEXT("button"),TEXT("START"),WS_CHILD|WS_VISIBLE|
       BS_PUSHBUTTON,20,150,80,30,hWnd,(HMENU)0,g_hInst,NULL);
      CreateWindow(TEXT("button"),TEXT("STOP"),WS_CHILD|WS_VISIBLE|
       BS_PUSHBUTTON,105,150,80,30,hWnd,(HMENU)1,g_hInst,NULL);
      CreateWindow(TEXT("button"),TEXT("EXIT"),WS_CHILD|WS_VISIBLE|
       BS_PUSHBUTTON,190,150,80,30,hWnd,(HMENU)2,g_hInst,NULL);
    return 0;
 
   case WM_TIMER:
      undercomma+=5;
      if(undercomma >= 100) { sec++; undercomma=0; }
      if(sec >= 60) { min++; sec=0; }
      InvalidateRect(hWnd, NULL, TRUE);
    return 0;
   case WM_PAINT:
      char szTxt[16];
      hdc=BeginPaint(hWnd, &ps);
      font=CreateFont(60,0,0,0,0,0,0,0,HANGEUL_CHARSET,0,0,0,0,"돋움");
      oldfont=(HFONT)SelectObject(hdc,font);
      sprintf(szTxt, "%02d:%02d.%02d",min, sec, undercomma);
      TextOut(hdc, 20, 40, szTxt, strlen(szTxt));
      SelectObject(hdc,oldfont);
      DeleteObject(font);
      EndPaint(hWnd, &ps);
    return 0;
   case WM_COMMAND:
    switch(LOWORD(wParam)) {
    case 0:  // START button clicked
       min = 0;
       sec = 0;
     undercomma = 0;
       SetTimer(hWnd, 3355, 50, NULL);
       break;
    case 1:  // STOP button clicked
       KillTimer(hWnd, 3355);
       break;
    case 2:  // EXIT button clicked
       PostQuitMessage(0);
       break;
    }
    return 0;
   case WM_DESTROY:
      PostQuitMessage(0);
      return 0;
   }
   return(DefWindowProc(hWnd,iMessage,wParam,lParam));
}

2014년 4월 7일 월요일

[iOS] UIAlertView 사용하기

UIAlertView 간단한 사용 예제


UIAlertView는 UIAlertVIewDelegate 프로토콜을 따른다.
(헤더파일에 <UIAlertViewDelegate>를 포함시키지 않아도 작동된다.)
#1
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Question"
                                                       message:@"Do you want to build a snowman?"
                                                      delegate:self
                                             cancelButtonTitle:@"NO"    /* nil 로 지정할 경우 cancel button 없음 */
                                             otherButtonTitles:@"YES", nil];

    // alert창을 띄우는 method는 show이다.
    [alert show];



#2
// UIAlertView의 delegate method이다
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    // OK 버튼을 눌렀을 때 버튼Index가 1로 들어감
    if (buttonIndex == 1) {
        NSLog(@"Clicked YES");
    }
    else {
       
    }
}


예제 실행 화면



* 만약 하나의 ViewController 안에 alertview를 여러 개 사용해야 한다면
다음과 같이 각각의 alertview에 tag를 지정해주어 식별해야 한다.

alertA.tag = 101;
alertB.tag = 102;

...

// UIAlertView의 delegate method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
   if ( alertView.tag == 101 ) {
       if (buttonIndex == 1) {
            NSLog(@"Alert A - YES");
        }
    }
    else if ( alertView.tag == 102 ) {   
       if (buttonIndex == 1) {
            NSLog(@"Alert B - YES");
        }
    }
    
}


<Result>

alertA 호출 + YES버튼 터치 시 :
  2014-04-08 15:48:50.902 AlertViewTest[3098:60b] Alert A - YES

alertB 호출 + YES버튼 터치 시 :
  2014-04-08 15:53:22.981 AlertViewTest[3106:60b] Alert B - YES

2014년 4월 2일 수요일

구글 대량메일 발신자 가이드라인!


내 업무용 메일이 스팸이라니!! 말도안돼

단체 메일을 보낼 때 문제 없이 수신자에게 전달해주는 방법을 설명해 주고 있다.
생각보다 챙겨야 할 사항이 많음.

https://support.google.com/mail/answer/81126?hl=ko&ref_topic=3404235


DKIM까지는 안되더라도 최소한 SPF레코드 정도는 등록해주어야 유령취급받지 않을 수 있다.