예제 #1
0
파일: MAIN.C 프로젝트: KvitkovIgor/SUM2016
/* The start of 'MyWinFunc' function */
LRESULT CALLBACK MyWinFunc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )
{
  HDC hDC;
  PAINTSTRUCT ps;
  MINMAXINFO *MinMax;
  INT w, h;
  SetDbgMemHooks();

  switch (Msg)
  {
  case WM_GETMINMAXINFO:
    MinMax = (MINMAXINFO *)lParam;
    MinMax->ptMaxTrackSize.y = 
     GetSystemMetrics(SM_CYMAXTRACK) +
     GetSystemMetrics(SM_CYCAPTION) +
     GetSystemMetrics(SM_CYMENU) +
     GetSystemMetrics(SM_CYBORDER) * 2;
  case WM_CREATE:
    SetTimer(hWnd, 30, 2, NULL);
    IK3_AnimUnit(hWnd); 
    SendMessage(hWnd, WM_SIZE, 0, 0);
  case WM_SIZE:
    w = LOWORD(lParam);
    h = HIWORD(lParam);
    /* Animation resize */
    IK3_Reasize(w, h);
    SendMessage(hWnd, WM_TIMER, 0, 0);
    return 0;
  case WM_MOUSEWHEEL:
    IK3_MouseWheel += (SHORT)HIWORD(wParam);
    return 0;
  case WM_KEYDOWN:
    if (LOWORD(wParam) == 'F')
      FlipFullScreen(hWnd);
    if (LOWORD(wParam) == VK_ESCAPE)
      SendMessage(hWnd, WM_DESTROY, 0, 0);
    return 0;
  case WM_ERASEBKGND:
    return 0;
  case WM_TIMER: 
    IK3_AnimRender();
    InvalidateRect(hWnd, NULL, FALSE);
    return 0;
  case WM_PAINT:
    hDC = BeginPaint(hWnd, &ps);
    IK3_AnimCopyFrame(hDC);
    EndPaint(hWnd, &ps);
    return 0;
  case WM_DESTROY:
    IK3_AnimClose();
    KillTimer(hWnd, 30);
    PostQuitMessage(0);
    return 0;
  }
  return DefWindowProc(hWnd, Msg, wParam, lParam);

} /* End of 'MyWinFunc' function */
예제 #2
0
파일: T02CLOCK.C 프로젝트: CGSG/SUM2016
/* Window message handle function */
LRESULT CALLBACK MyWindowFunc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )
{
  HDC hDC;
  PAINTSTRUCT ps;
  DOUBLE a, r;
  CHAR s[300];
  SYSTEMTIME t;
  HPEN hPen, hOldPen;
  HBRUSH hBr, hOldBr;
  CREATESTRUCT *cs;
  MINMAXINFO *MinMax;
  static POINT pts[] =
  {
    {0, 0}, {30, 300}, {200, 20}
  };
  static HFONT hFnt;
  static INT w, h;
  static BITMAP bm, bmPig;
  static HBITMAP hFrame, hFace, hPigXOR, hPigAND;
  static HDC hMemDCFrame, hMemDCFace, hMemDCPig;

  switch (Msg)
  {
  case WM_GETMINMAXINFO:
    MinMax = (MINMAXINFO *)lParam;
    MinMax->ptMaxTrackSize.y =
      GetSystemMetrics(SM_CYMAXTRACK) +
      GetSystemMetrics(SM_CYCAPTION) +
      GetSystemMetrics(SM_CYMENU) +
      GetSystemMetrics(SM_CYBORDER) * 2;
    return 0;
  case WM_CREATE:
    cs = (CREATESTRUCT *)lParam;
    SetTimer(hWnd, 11, 2, NULL);

    hFace = LoadBitmap(cs->hInstance, (CHAR *)IDB_CLOCKFACE);
    GetObject(hFace, sizeof(bm), &bm);

    hPigXOR = LoadImage(cs->hInstance, (CHAR *)IDB_XOR, IMAGE_BITMAP, 0, 0, 0);
    GetObject(hPigXOR, sizeof(bmPig), &bmPig);
    hPigAND = LoadImage(cs->hInstance, (CHAR *)IDB_AND, IMAGE_BITMAP, 0, 0, 0);

    hDC = GetDC(hWnd);
    hMemDCFace = CreateCompatibleDC(hDC);
    hMemDCFrame = CreateCompatibleDC(hDC);
    hMemDCPig = CreateCompatibleDC(hDC);
    ReleaseDC(hWnd, hDC);

    SelectObject(hMemDCFace, hFace);

    hFnt = CreateFont(59, 0, 0, 9000, FW_BOLD, FALSE, FALSE, FALSE,
      RUSSIAN_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
      DEFAULT_QUALITY, VARIABLE_PITCH | FF_SCRIPT, "Bookman Old Style");
    SelectObject(hMemDCFrame, hFnt);
    return 0;
  case WM_SIZE:
    w = LOWORD(lParam);
    h = HIWORD(lParam);

    if (hFrame != NULL)
      DeleteObject(hFrame);
    hDC = GetDC(hWnd);
    hFrame = CreateCompatibleBitmap(hDC, w, h);
    ReleaseDC(hWnd, hDC);

    SelectObject(hMemDCFrame, hFrame);
    SendMessage(hWnd, WM_TIMER, 0, 0);
    return 0;
  case WM_KEYDOWN:
    if (LOWORD(wParam) == 'F')
      FlipFullScreen(hWnd);
    else if (LOWORD(wParam) == VK_ESCAPE)
      DestroyWindow(hWnd);
    return 0;
  case WM_ERASEBKGND:
    return 0;
  case WM_TIMER:
    SelectObject(hMemDCFrame, GetStockObject(NULL_PEN));
    Rectangle(hMemDCFrame, 0, 0, w + 1, h + 1);
    BitBlt(hMemDCFrame, (w - bm.bmWidth) / 2, (h - bm.bmHeight) / 2,
      bm.bmWidth, bm.bmHeight, hMemDCFace, 0, 0, SRCCOPY);

    GetLocalTime(&t);

    a = (t.wSecond) * 2 * 3.1415926535 / 60;
    r = bm.bmWidth / 2.2;
    
    hPen = CreatePen(PS_SOLID, 6, RGB(0xFF, 0, 0xFF));
    hOldPen = SelectObject(hMemDCFrame, hPen);
    MoveToEx(hMemDCFrame, w / 2, h / 2, NULL);
    LineTo(hMemDCFrame, w / 2 + sin(a) * r, h / 2 - cos(a) * r);
    SelectObject(hMemDCFrame, hOldPen);
    DeleteObject(hPen);

    a = (t.wMinute + t.wSecond / 60.0) * 2 * 3.1415926535 / 60;
    r = bm.bmWidth / 3.2;
    hPen = CreatePen(PS_SOLID, 10, RGB(0, 0, 255));
    hOldPen = SelectObject(hMemDCFrame, hPen);
    MoveToEx(hMemDCFrame, w / 2, h / 2, NULL);
    LineTo(hMemDCFrame, w / 2 + sin(a) * r, h / 2 - cos(a) * r);
    SelectObject(hMemDCFrame, hOldPen);
    DeleteObject(hPen);

    a = (t.wHour % 12 + t.wMinute / 60.0) * 2 * 3.1415926535 / 12;
    r = bm.bmWidth / 4.0;
    MoveToEx(hMemDCFrame, w / 2, h / 2, NULL);
    LineTo(hMemDCFrame, w / 2 + sin(a) * r, h / 2 - cos(a) * r);

    /* SetBkMode(hMemDCFrame, TRANSPARENT); */
    SetTextColor(hMemDCFrame, RGB(130, 90, 30));
    TextOut(hMemDCFrame, 0, h / 2 + h / 2 * sin(clock() / 2000.0), s,
      sprintf(s, "Current date: %02i.%02i.%i", t.wDay, t.wMonth, t.wYear));
    /* VOID WINAPI GetLocalTime(lpSystemTime); */

    SelectObject(hMemDCPig, hPigAND);
    BitBlt(hMemDCFrame, 200 + 150 * sin(clock() / 200.0), 100,
      bmPig.bmWidth, bmPig.bmHeight, hMemDCPig, 0, 0, SRCAND);
    SelectObject(hMemDCPig, hPigXOR);
    BitBlt(hMemDCFrame, 200 + 150 * sin(clock() / 200.0), 100,
      bmPig.bmWidth, bmPig.bmHeight, hMemDCPig, 0, 0, SRCINVERT);


    hBr = CreateHatchBrush(HS_DIAGCROSS, RGB(0, 0, 255));
    SetBkMode(hMemDCFrame, TRANSPARENT);
    hOldBr = SelectObject(hMemDCFrame, hBr);
    Polygon(hMemDCFrame, pts, 3);
    SelectObject(hMemDCFrame, hOldBr);
    DeleteObject(hBr);

    a = clock() / (DOUBLE)CLOCKS_PER_SEC;
    Draw(hMemDCFrame, 100, 100, 30 * sin(a * 5));
    Draw(hMemDCFrame, 100, 100, 59 * sin(-a * 8));
    Draw(hMemDCFrame, 100, 100, 36 * a);
    Draw(hMemDCFrame, 100, 100, -36 * a);

    InvalidateRect(hWnd, NULL, FALSE);
    return 0;
  case WM_PAINT:
    hDC = BeginPaint(hWnd, &ps);
    BitBlt(hDC, 0, 0, w, h, hMemDCFrame, 0, 0, SRCCOPY);
    EndPaint(hWnd, &ps);
    return 0;
  case WM_DESTROY:
    KillTimer(hWnd, 11);
    DeleteDC(hMemDCFrame);
    DeleteDC(hMemDCFace);
    DeleteObject(hFrame);
    DeleteObject(hFace);
    DeleteObject(hFnt);
    PostQuitMessage(0);
    return 0;
  }
  return DefWindowProc(hWnd, Msg, wParam, lParam);
} /* End of 'MyWindowFunc' function */
예제 #3
0
LRESULT CALLBACK MyWinFunc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )
{
  INT x = 500, y = 500;
  SYSTEMTIME st;
  HDC hDC;
  HPEN hPen, hOldPen;
  PAINTSTRUCT ps;
  static INT w, h;
  static BITMAP bm;
  static HBITMAP hBm, hBmLogo;
  static HDC hMemDC, hMemDCLogo;
  DOUBLE P = 3.14159265358979323846, t, si, co, r = 400;

  GetLocalTime(&st);

  switch (Msg)
  {
  case WM_CREATE:
    SetTimer(hWnd, 30, 10, NULL);
    hBmLogo = LoadImage(NULL, "CLOCKFACE.BMP", IMAGE_BITMAP, 0, 0,
        LR_LOADFROMFILE);
    GetObject(hBmLogo, sizeof(bm), &bm);
    hDC = GetDC(hWnd);
    hMemDC = CreateCompatibleDC(hDC);
    hMemDCLogo = CreateCompatibleDC(hDC);
    SelectObject(hMemDCLogo, hBmLogo);
    ReleaseDC(hWnd, hDC);
  case WM_SIZE:
    w = LOWORD(lParam);
    h = HIWORD(lParam);
    if (hBm != NULL)
      DeleteObject(hBm);
    hDC = GetDC(hWnd);
    hBm = CreateCompatibleBitmap(hDC, w, h);
    ReleaseDC(hWnd, hDC);
    SelectObject(hMemDC, hBm);
    SendMessage(hWnd, WM_TIMER, 0, 0);
    return 0;
  case WM_ERASEBKGND:
    return 0;
  case WM_KEYDOWN:
    if (LOWORD(wParam) == 'F')
      FlipFullScreen(hWnd);
    if (LOWORD(wParam) == VK_ESCAPE)
      SendMessage(hWnd, WM_DESTROY, 0, 0);
    return 0;
  case WM_TIMER:
    Rectangle(hMemDC, 0, 0, w + 1, h + 1);    
    
    BitBlt(hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, hMemDCLogo, 0, 0, SRCCOPY);
    hPen = CreatePen(PS_SOLID, 10, RGB(10, 10, 35));
    hOldPen = SelectObject(hMemDC, hPen);
    GetLocalTime(&st);
    t = (st.wSecond  + st.wMilliseconds / 1000.0 ) / 60.0 * 2 * P;
    si = sin(t);
    co = cos(t);
    PutLineTime(hMemDC, 500, 500, 500 + si * r, 500 - co * r);
    t = (st.wMinute + st.wSecond / 60.0) / 60.0 * 2.0 * P + st.wSecond / 60;
    si = sin(t);
    co = cos(t);
    PutLineTime(hMemDC, 500, 500, 500 + 300 * si, 500 - 300 * co);
    t = (st.wHour + st.wMinute / 60.0) / 12.0 * 2.0 * P;

    si = sin(t);
    co = cos(t);
    PutLineTime(hMemDC, 500, 500, 500 + 230 * si, 500 - 230 * co);
    SelectObject(hMemDC, hOldPen);
    DeleteObject(hPen);
    InvalidateRect(hWnd, NULL, FALSE);
    return 0;
  case WM_PAINT:
    hDC = BeginPaint(hWnd, &ps);
    BitBlt(hDC, 0, 0, w, h, hMemDC, 0, 0, SRCCOPY);
    EndPaint(hWnd, &ps);                                                   
    return 0;
  case WM_DESTROY:
    KillTimer(hWnd, 30);
    DeleteObject(hBm);
    DeleteObject(hMemDC); 
    PostQuitMessage(0);
    return 0;
  }
  return DefWindowProc(hWnd, Msg, wParam, lParam);
} /* End of 'MyWinFunc' function */
예제 #4
0
파일: T02CLOCK.c 프로젝트: Killaz/SUM2014
LRESULT CALLBACK WindowFunc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )
{
  HDC hDC, hMemDC, hMemDCLogo;
  PAINTSTRUCT ps;
  BITMAP bm;
  static INT W = 0, H = 0, k = 1, r = 290;
  static HBITMAP hBm, hBmLogo;
  SYSTEMTIME st;
  POINT c;
  CHAR chr;

  switch (Msg)
  {
  case WM_CREATE:
    SetTimer(hWnd, 4, 10, NULL);
    hBmLogo = LoadImage(NULL, "clockface.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    break;
  case WM_CHAR:
    chr = (CHAR) wParam;

    if (chr == 27)
      DestroyWindow(hWnd);
    else if (chr == '+')
      k++;
    else if (chr == '-')
      k--;
    else if (chr == 'f' || chr == 'F')
      FlipFullScreen(hWnd, 1);
    else if (chr == 'g' || chr == 'G')
      FlipFullScreen(hWnd, 0);
    return 0;
  case WM_ERASEBKGND:
    return 1;
  case WM_SIZE:
    W = LOWORD(lParam);
    H = HIWORD(lParam);
    hDC = GetDC(hWnd);
    if (hBm != NULL)
      DeleteObject(hBm);
    hBm = CreateCompatibleBitmap(hDC, W, H);
    ReleaseDC(hWnd, hDC);
    return 0;
  case WM_PAINT:
    hDC = BeginPaint(hWnd, &ps);
    hMemDC = CreateCompatibleDC(hDC);
    SelectObject(hMemDC, hBm);

    SetDCBrushColor(hMemDC, RGB(255, 255, 255));
    Rectangle(hMemDC, 0, 0, W, H);
    
    GetObject(hBmLogo, sizeof(bm), &bm);/**/

    hMemDCLogo = CreateCompatibleDC(hMemDC);
    SelectObject(hMemDCLogo, hBmLogo);
    BitBlt(hMemDC, max(W / 2 - PIC_CX, 0), max(H / 2 - PIC_CY, 0), W, H, hMemDCLogo, 0, 0, SRCCOPY);
    c.x = PIC_CX + max(W / 2 - PIC_CX, 0);
    c.y = PIC_CY + max(H / 2 - PIC_CY, 0);

    GetLocalTime(&st);
    Arrow(hMemDC, c, k * 2 * M_PI * (st.wHour/* % 12*/ + st.wMinute / 60.0 + st.wSecond / 3600.0 + st.wMilliseconds / 3600000.0) / 12 - M_PI / 2, r, 7, RGB(255, 0, 0));
    Arrow(hMemDC, c, k * 2 * M_PI * (st.wMinute + st.wSecond / 60.0 + st.wMilliseconds / 60000.0) / 60 - M_PI / 2, r, 4, RGB(0, 255, 0));
    Arrow(hMemDC, c, k * 2 * M_PI * (st.wSecond + st.wMilliseconds / 1000.0) / 60 - M_PI / 2, r, 2, RGB(0, 0, 0));
                           
    BitBlt(hDC, 0, 0, W, H, hMemDC, 0, 0, SRCCOPY);
    DeleteDC(hMemDC);
    DeleteDC(hMemDCLogo);
    EndPaint(hWnd, &ps);
    return 0;
  case WM_TIMER:
    InvalidateRect(hWnd, NULL, 0);
    break;
  case WM_DESTROY:
    DeleteObject(hBm);
    DeleteObject(hBmLogo);
    PostQuitMessage(0);
    KillTimer(hWnd, 4);
    return 0;
  }

  return DefWindowProc(hWnd, Msg ,wParam, lParam);
}
예제 #5
0
LRESULT CALLBACK WindowFunc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
  HDC hDC, hMemDC, hMemDCLogo;
  PAINTSTRUCT ps;
  SYSTEMTIME st;
  FLOAT PI = 3.14159265358979323846;
  BITMAP bm;
  static INT W = 0, H = 0;
  static HBITMAP hBm, hBmLogo;
  INT r = 5;
  INT i = 0;

  switch (Msg)
  {
  case WM_CREATE:
    SetTimer(hWnd, 30, 10, NULL);
    hBmLogo = LoadImage(NULL, "cf.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    return 0;
  case WM_CHAR:
    if ((CHAR)wParam == 27)
        DestroyWindow(hWnd);
    if ((CHAR)wParam == 'f' || 'F')
        FlipFullScreen( hWnd );
    return 0;
  case WM_ERASEBKGND:
    return 1;
  case WM_SIZE:
    W = LOWORD(lParam);
    H = HIWORD(lParam);
    hDC = GetDC(hWnd);
    if (hBm != NULL)
      DeleteObject(hBm);
    hBm = CreateCompatibleBitmap(hDC, W, H);
    ReleaseDC(hWnd, hDC);
    return 0;
  case WM_PAINT:
    hDC = BeginPaint(hWnd, &ps);
    hMemDC = CreateCompatibleDC(hDC);
    hMemDCLogo = CreateCompatibleDC(hDC);
    SelectObject(hMemDCLogo, hBmLogo); 
    SelectObject(hMemDC, hBm);
   
    GetLocalTime(&st);
    GetObject(hBmLogo, sizeof(bm), &bm);
    
    BitBlt(hMemDC, 0,0, bm.bmWidth, bm.bmHeight, hMemDCLogo, 0, 0, SRCCOPY);
    
    SelectObject(hMemDC, GetStockObject(DC_BRUSH));
    SelectObject(hMemDC, GetStockObject(DC_PEN));
    SetDCPenColor(hMemDC, RGB(0, 0, 0));
    SetDCBrushColor(hMemDC, RGB(0, 0, 255));
    DrawArrow(hMemDC, 300, 300 , 100, 50, (-(st.wHour % 12 + st.wMinute / 60.0) / 12.0) * 2 * PI);
    SelectObject(hMemDC, GetStockObject(DC_BRUSH));
    SetDCBrushColor(hMemDC, RGB(0, 255, 0));
    DrawArrow(hMemDC, 300, 300, 140, 45, (-(st.wMinute + st.wSecond / 60.0) / 60.0) * 2 * PI);
    SelectObject(hMemDC, GetStockObject(DC_BRUSH));
    SetDCBrushColor(hMemDC, RGB(255, 0, 0));
    DrawArrow(hMemDC, 300, 300, 200, 30, (-(st.wSecond + st.wMilliseconds / 1000.0) / 60.0) * 2 * PI);
    //DrawArrow(hDC, 300, 300, 250, 20, (-st.wMilliseconds / 1000.0) * 2 * PI);
    SelectObject(hMemDC, GetStockObject(DC_BRUSH));
    SetDCBrushColor(hMemDC, RGB(0, 0, 0));
    Ellipse(hMemDC, 300 - r, 300 - r, 300 + r, 300 + r);
    
    BitBlt(hDC, 0, 0, W, H, hMemDC, 0, 0, SRCCOPY);
    
    DeleteDC(hMemDCLogo);
    DeleteDC(hMemDC);
    DeleteDC(hDC);
    EndPaint(hWnd, &ps);
    return 0;
  case WM_TIMER:
    InvalidateRect(hWnd, NULL, 0);
    return 0;
  case WM_DESTROY:
    DeleteObject(hBm);
    DeleteObject(hBmLogo);
    PostQuitMessage(0);
    KillTimer(hWnd, 30);
    return 0;
  }
  return DefWindowProc(hWnd, Msg ,wParam, lParam);
}
예제 #6
0
/* The start of 'MyWinFunc' function */
LRESULT CALLBACK MyWinFunc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )
{
  HDC hDC;
  PAINTSTRUCT ps;
  static INT w, h;
  static BITMAP bm;
  static HBITMAP hBm, hBmLogo;
  static HDC hMemDC, hMemDCLogo;

  switch (Msg)
  {
  case WM_CREATE:
    SetTimer(hWnd, 30, 2, NULL);
    hBmLogo = LoadImage(NULL, "M.BMP", IMAGE_BITMAP, 0, 0,
        LR_LOADFROMFILE);
    GetObject(hBmLogo, sizeof(bm), &bm);
    hDC = GetDC(hWnd);
    hMemDC = CreateCompatibleDC(hDC);
    hMemDCLogo = CreateCompatibleDC(hDC);
    SelectObject(hMemDCLogo, hBmLogo);
    ReleaseDC(hWnd, hDC);
    LoadSphere();
  case WM_SIZE:
    w = LOWORD(lParam);
    h = HIWORD(lParam);
    if (hBm != NULL)
      DeleteObject(hBm);
    hDC = GetDC(hWnd);
    hBm = CreateCompatibleBitmap(hDC, w, h);
    ReleaseDC(hWnd, hDC);
    SelectObject(hMemDC, hBm);
    SendMessage(hWnd, WM_TIMER, 0, 0);
    return 0;
  case WM_ERASEBKGND:
    return 0;

  case WM_KEYDOWN:
    if (LOWORD(wParam) == 'F')
      FlipFullScreen(hWnd);
    if (LOWORD(wParam) == VK_ESCAPE)
      SendMessage(hWnd, WM_DESTROY, 0, 0);
    return 0;
  case WM_TIMER:
    Rectangle(hMemDC, 0, 0, w + 1, h + 1);
    DrawSphere( hMemDC, w / 2 + sin(clock() / 600.0) * 450.0, h / 2, 256);
    BitBlt(hMemDC, 725 + sin(clock() / 600.0) * 650.0, 0, bm.bmWidth, bm.bmHeight, hMemDCLogo, 0, 0, SRCAND);  
    SetBkMode(hMemDC, TRANSPARENT);
    SetTextColor(hMemDC, RGB(255, 0, 255));
    TextOut(hMemDC, 5, 5, "THE PROGRAMMER IN THE WORLD", 15);
    InvalidateRect(hWnd, NULL, FALSE);
    return 0;
  case WM_PAINT:
    hDC = BeginPaint(hWnd, &ps);
    BitBlt(hDC, 0, 0, w, h, hMemDC, 0, 0, SRCCOPY);
    EndPaint(hWnd, &ps);
    return 0;
  case WM_DESTROY:
    KillTimer(hWnd, 30);
    DeleteObject(hBm);
    DeleteObject(hMemDC);
    PostQuitMessage(0);
    return 0;
  }
  return DefWindowProc(hWnd, Msg, wParam, lParam);
} /* End of 'MyWinFunc' function */
예제 #7
0
/* Window process function 
*  Arguments:
*    - window handle:
*        HWND hWnd;
*    - message number:
*        UINT Msg;
*    - word parameter:
*        WPARAM wParam;
*    - long parameter:
*        LPARAM lParam;
*  returns:
*    (LRESULT)
*/
LRESULT CALLBACK MyWindowFunc( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam )
{
  INT i;
  static HBITMAP hBm, hBufBm;
  static BITMAP Bm;
  static INT W, H;
  HDC hMemDC, hBufDC;
  static HDC hDC;
  static SYSTEMTIME tm;
  PAINTSTRUCT ps;
  RECT rc;
  POINT pt;
  double sec, min, hour;
  switch(Msg)
  {
  case WM_CHAR:
    if ((CHAR)wParam == 27)
      DestroyWindow(hWnd);
    if ((CHAR)wParam == 'f' || (CHAR)wParam == 'à')
      FlipFullScreen(hWnd);
    return 0;
  case WM_CREATE:
    SetTimer(hWnd, TimerId, 10, NULL);
    hBm = LoadImage(NULL, "clocks.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    GetObject(hBm, sizeof(BITMAP), &Bm);     
    GetLocalTime(&tm);
    hBufDC = GetDC(hWnd);
    hDC = CreateCompatibleDC(hBufDC);
    ReleaseDC(hWnd, hBufDC);
    return 0;
  case WM_SIZE:
    H = HIWORD(lParam);
    W = LOWORD(lParam);
    if (hBufBm != NULL)
      DeleteObject(hBufBm);
    hBufDC = GetDC(hWnd);
    hBufBm = CreateCompatibleBitmap(hBufDC, W, H);
    ReleaseDC(hWnd, hBufDC);
    SelectObject(hDC, hBufBm);
    return 0;
  case WM_PAINT:
    hBufDC = BeginPaint(hWnd, &ps);   
    hMemDC = CreateCompatibleDC(hDC);
    SelectObject(hMemDC, hBm);
    StretchBlt(hDC, 0, 0, W, H, hMemDC, 0, 0, Bm.bmWidth, Bm.bmHeight, SRCCOPY);
    /*
    sec = tm.wSecond / 30.0 * PI; 
    min = tm.wMinute / 30.0 * PI;
    hour = (tm.wHour % 12) / 6.0 * PI;
    
    for (i = -100; i++; i < 100)
    {
      MoveToEx(hDC, W / 2, H / 2 + i, NULL);
      LineTo(hDC, W / 2.0  * sin(sec) + W / 2.0, H / 2.0 * -1.0 * cos(sec) + H / 2.0);
      MoveToEx(hDC, W / 2, H / 2 + i, NULL);
      LineTo(hDC, W / 2.0  * sin(min) + W / 1.8, H / 2.0 * -1.0 * cos(min) + H / 1.8);
      MoveToEx(hDC, W / 2, H / 2 + i, NULL);
      LineTo(hDC, W / 2.0  * sin(hour) + W / 2.5, H / 2.0 * -1.0 * cos(hour) + H / 2.5);
    } 
    */
    SelectObject(hDC, GetStockObject(DC_BRUSH));
    SetDCBrushColor(hDC, RGB(255, 255, 255));
    SelectObject(hDC, GetStockObject(DC_PEN));
    SetDCPenColor(hDC, RGB(0, 255, 0));    
    DrawArrow(hDC, W / 2, H / 2, H / 3.5, W / 20, (-(tm.wHour % 12 + tm.wMinute / 60.0) / 12.0) * 2 * PI);
    SetDCPenColor(hDC, RGB(0, 0, 255));
    DrawArrow(hDC, W / 2, H / 2, H / 2.5, W / 25, (-(tm.wMinute + tm.wSecond / 60.0) / 60.0) * 2 * PI);
    SetDCPenColor(hDC, RGB(255, 0, 0));
    DrawArrow(hDC, W / 2, H / 2, H / 2.1, W / 30, (-(tm.wSecond + tm.wMilliseconds / 1000.0) / 60.0) * 2 * PI);
    SetDCPenColor(hDC, RGB(0, 255, 255));
    DrawArrow(hDC, W / 2, H / 2, H / 2, W / 32, (-tm.wMilliseconds / 1000.0) * 2 * PI);

    BitBlt(hBufDC, 0, 0, W, H, hDC, 0, 0, SRCCOPY);
    DeleteDC(hMemDC);
    EndPaint(hWnd, &ps);
    return 0;
  case WM_TIMER:
    GetLocalTime(&tm);
    InvalidateRect(hWnd, NULL, TRUE);
    return 0;
  case WM_ERASEBKGND:
    return 0;
  case WM_DESTROY:
    KillTimer(hWnd, TimerId);
    DeleteObject(hBm);
    PostQuitMessage(0);
    return 0;
  }
  return DefWindowProc(hWnd, Msg, wParam, lParam);
} /* End of 'MyWindowFunc' function */
예제 #8
0
파일: t05globe.c 프로젝트: Akrilont/SUM2015
/* Функция обработки сообщения окна.
* АРГУМЕНТЫ:
* - дескриптор окна:
* HWND hWnd;
* - номер сообщения (см. WM_***):
* UINT Msg;
* - параметр сообшения ('word parameter'):
* WPARAM wParam;
* - параметр сообшения ('long parameter'):
* LPARAM lParam;
* ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ:
* (LRESULT) - в зависимости от сообщения.
*/
LRESULT CALLBACK MyWindowFunc( HWND hWnd, UINT Msg,
WPARAM wParam, LPARAM lParam )
{
HDC hDC;
static HDC hMemDC;
static INT w, h;
static BITMAP bm;
static HBITMAP hBm;
switch (Msg)
{
case WM_CREATE:
SetTimer(hWnd, 111, 50, NULL);
/* создаем контекст в памяти */
hDC = GetDC(hWnd);
hMemDC = CreateCompatibleDC(hDC);
ReleaseDC(hWnd, hDC);
return 0;
case WM_SIZE:
w = LOWORD(lParam);
h = HIWORD(lParam);
/* создаем картинку размером с окно */
if (hBm != NULL)
DeleteObject(hBm);
hDC = GetDC(hWnd);
hBm = CreateCompatibleBitmap(hDC, w, h);
ReleaseDC(hWnd, hDC);
SelectObject(hMemDC, hBm);
SendMessage(hWnd, WM_TIMER, 111, 0);
return 0;
case WM_TIMER:
/* Clear Background */
SelectObject(hMemDC, GetStockObject(NULL_PEN));
SelectObject(hMemDC, GetStockObject(DC_BRUSH));
SetDCBrushColor(hMemDC, RGB(255, 255, 255));
Rectangle(hMemDC, 0, 0, w + 1, h + 1);
SelectObject(hMemDC, GetStockObject(NULL_PEN));
SelectObject(hMemDC, GetStockObject(DC_BRUSH));
SetDCBrushColor(hMemDC, RGB(255, 0, 0));
GlobeBuild();
GlobeDraw(hMemDC, w, h);
InvalidateRect(hWnd, NULL, TRUE);
return 0;
case WM_KEYDOWN:
if (wParam == 'F')
  FlipFullScreen(hWnd);
if (wParam == 27)
  SendMessage(hWnd, WM_CLOSE, 0, 0);
if (wParam == 'W')
  IsWire = !IsWire;
return 0;

case WM_CLOSE:
if (MessageBox(hWnd, "Are you shure to exit from program?",
"Exit", MB_YESNO | MB_ICONQUESTION) == IDNO)
return 0;
break;
case WM_ERASEBKGND:
BitBlt((HDC)wParam, 0, 0, w, h, hMemDC, 0, 0, SRCCOPY);
return 0;
case WM_DESTROY:
DeleteDC(hMemDC);
DeleteObject(hBm);
KillTimer(hWnd, 111);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, Msg, wParam, lParam);
}