日期:2014-05-17  浏览次数:20853 次

好久没写windows的SDK代码了无聊的时钟程序

好久没写windows的SDK代码了无聊的时钟程序
2011年04月12日
  /*********************
  偏爱 c/c++    2011-4-12
  画图练习
  **********************/
  #include "stdafx.h"
  #include "test_412_1.h"
  #include
  #include
  #define MAX_LOADSTRING 100
  // 全局变量:
  HINSTANCE hInst;// 当前实例
  TCHAR szTitle[MAX_LOADSTRING];// 标题栏文本
  TCHAR szWindowClass[MAX_LOADSTRING];// 主窗口类名
  static int s_nprehour;
  static int s_npreminute;
  static int s_npresecond;
  static int s_cxclient;
  static int s_cyclient;
  static int s_btop;
  // 此代码模块中包含的函数的前向声明:
  ATOMMyRegisterClass(HINSTANCE hInstance);
  BOOLInitInstance(HINSTANCE, int);
  LRESULT CALLBACKWndProc(HWND, UINT, WPARAM, LPARAM);
  INT_PTR CALLBACKAbout(HWND, UINT, WPARAM, LPARAM);
  void drawclockface(HDC hdc);//绘制时钟上的12个点
  void setisotropic(HDC hdc,int cx,int cy);
  void drawhand(HDC hdc,int nlengh,int nwidth,int ndegree,COLORREF color);
  int APIENTRY _tWinMain(HINSTANCE hInstance,
  HINSTANCE hPrevInstance,
  LPTSTR    lpCmdLine,
  int       nCmdShow)
  {
  UNREFERENCED_PARAMETER(hPrevInstance);
  UNREFERENCED_PARAMETER(lpCmdLine);
  // TODO: 在此放置代码。
  MSG msg;
  HACCEL hAccelTable;
  // 初始化全局字符串
  LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
  LoadString(hInstance, IDC_TEST_412_1, szWindowClass, MAX_LOADSTRING);
  MyRegisterClass(hInstance);
  // 执行应用程序初始化:
  if (!InitInstance (hInstance, nCmdShow))
  {
  return FALSE;
  }
  hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_TEST_412_1));
  // 主消息循环:
  while (GetMessage(&msg, NULL, 0, 0))
  {
  if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
  {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
  }
  }
  return (int) msg.wParam;
  }
  //
  //  函数: MyRegisterClass()
  //
  //  目的: 注册窗口类。
  //
  //  注释:
  //
  //    仅当希望
  //    此代码与添加到 Windows 95 中的“RegisterClassEx”
  //    函数之前的 Win32 系统兼容时,才需要此函数及其用法。调用此函数十分重要,
  //    这样应用程序就可以获得关联的
  //    “格式正确的”小图标。
  //
  ATOM MyRegisterClass(HINSTANCE hInstance)
  {
  WNDCLASSEX wcex;
  wcex.cbSize = sizeof(WNDCLASSEX);
  wcex.style= CS_HREDRAW | CS_VREDRAW;
  wcex.lpfnWndProc= WndProc;
  wcex.cbClsExtra= 0;
  wcex.cbWndExtra= 0;
  wcex.hInstance= hInstance;
  wcex.hIcon= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_TEST_412_1));
  wcex.hCursor= LoadCursor(NULL, IDC_ARROW);
  wcex.hbrBackground= (HBRUSH)(COLOR_WINDOW+1);
  wcex.lpszMenuName= MAKEINTRESOURCE(IDC_TEST_412_1);
  wcex.lpszClassName= szWindowClass;
  wcex.hIconSm= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
  return RegisterClassEx(&wcex);
  }
  //
  //   函数: InitInstance(HINSTANCE, int)
  //
  //   目的: 保存实例句柄并创建主窗口
  //
  //   注释:
  //
  //        在此函数中,我们在全局变量中保存实例句柄并
  //        创建和显示主程序窗口。
  //
  BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  {
  HWND hWnd;
  hInst = hInstance; // 将实例句柄存储在全局变量中
  hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
  CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
  if (!hWnd)
  {
  return FALSE;
  }
  ShowWindow(hWnd, nCmdShow);
  UpdateWindow(hWnd);
  return TRUE;
  }
  //
  //  函数: WndProc(HWND, UINT, WPARAM, LPARAM)
  //
  //  目的: 处理主窗口的消息。