论坛交流
首页办公自动化| 网页制作| 平面设计| 动画制作| 数据库开发| 程序设计| 全部视频教程
应用视频: Windows | Word2007 | Excel2007 | PowerPoint2007 | Dreamweaver 8 | Fireworks 8 | Flash 8 | Photoshop cs | CorelDraw 12
编程视频: C语言视频教程 | HTML | Div+Css布局 | Javascript | Access数据库 | Asp | Sql Server数据库Asp.net  | Flash AS
当前位置 > 文字教程 > C语言程序设计教程
Tag:新手,函数,指针,数据类型,对象,Turbo,入门,运算符,数组,结构,二级,,tc,游戏,试题,问答,编译,视频教程

Windows窗口框架(API入门一)

文章类别:C语言程序设计 | 发表日期:2010-12-23 14:43:22

 #include 
  #include 
  #include 

  //声明函数 
  //////////////////////////////////////////////////////////////////
  long WINAPI WndProc //消息处理函数 
   (
   HWND hWnd,
   UINT iMessage,
   UINT wParam, 
   LONG lParam
   );
  BOOL InitWindowsClass(HINSTANCE hInstance); //初始化窗口类 
  BOOL InitWindows(HINSTANCE hInstance, int nCmdShow);//初始化窗口
  ///////////////////////////////////////////////////////////////////
  HWND hWndMain;


  int WINAPI WinMain ( //主函数 
   HINSTANCE hInstance,
   HINSTANCE hPrevInstance,
   LPSTR lpCmdLine,
   int nCmdShow
   )

  {
   MSG Message;
   if(!InitWindowsClass(hInstance))
   return FALSE;
   if(!InitWindows(hInstance, nCmdShow))
   return FALSE;
   while(GetMessage(&Message,0,0,0))//消息循环 
   {
   TranslateMessage(&Message);
   DispatchMessage(&Message);
   }
   return Message.wParam;
  }


  //定义函数 
  ///////////////////////////////////////////////////////////////////
  long WINAPI WndProc(
   HWND hWnd,
   UINT iMessage,
   UINT wParam,
   LONG lParam
   )
  {
   HDC hDC;
   HBRUSH hBrush;
   HPEN hPen;
   PAINTSTRUCT PtStr;
   POINT points[6]={{100,212},{70,227},{70,250},{130,250},{130,227},{100,212}};
   
   switch(iMessage)
   {
   case WM_PAINT:
   hDC=BeginPaint(hWnd,&PtStr);
   hPen=(HPEN)GetStockObject(NULL_PEN);
   SelectObject(hDC,hPen);
   hBrush=(HBRUSH)GetStockObject(BLACK_BRUSH);
   SelectObject(hDC,hBrush);
   LineTo(hDC,50,50);
   DeleteObject(hPen);
   hPen=CreatePen(PS_SOLID,2,RGB(255,0,0));
   SelectObject(hDC,hPen);
   
   LineTo(hDC,150,50);
   LineTo(hDC,100,137);
   LineTo(hDC,50,50);
   Polyline(hDC,points,6);
   Arc(hDC,63,137,138,212,100,137,100,137);
   Pie(hDC,213,137,288,212,240,137,260,137);
   Rectangle(hDC,213,212,287,250);
   RoundRect(hDC,213,100,287,137,20,20);
   DeleteObject(hPen);
   DeleteObject(hBrush);
   EndPaint(hWnd,&PtStr);
   return 0;
   case WM_DESTROY:
   PostQuitMessage(0);
   return 0;
   default:
   return(DefWindowProc(hWnd,iMessage,wParam,lParam));
   
   
   }
  }


  BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
  {
   HWND hWnd;
   hWnd=CreateWindow("WinFill", //窗口类名 
   "填充示例", //窗口实例的标题名 
   WS_OVERLAPPEDWINDOW, //窗口风格 
   CW_USEDEFAULT, //窗口左上角坐标为默认值 
   0,
   CW_USEDEFAULT, //窗口的高为默认值 
   0, //宽 
   NULL, //无父窗口 
   NULL, //无主菜单 
   hInstance, //创建此窗口的应用程序的当前句柄 
   NULL //不使用该值 
   );
   if(!hWnd)

   return FALSE;
   // hWndMain=hWnd;
   
   ShowWindow(hWnd,nCmdShow); //显示窗口 
   UpdateWindow(hWnd); //绘制用户区 
   return TRUE;
   
  }


  BOOL InitWindowsClass(HINSTANCE hInstance)
  {
   WNDCLASS WndClass;
   WndClass.cbClsExtra=0;
   WndClass.cbWndExtra=0;
   WndClass.hbrBackground=(HBRUSH)(GetStockObject(WHITE_BRUSH));
   WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
   WndClass.hIcon=LoadIcon(NULL,"END");
   WndClass.hInstance=hInstance;
   WndClass.lpfnWndProc=WndProc;
   WndClass.lpszClassName="WinFill";
   WndClass.lpszMenuName=NULL;
   WndClass.style=CS_HREDRAW|CS_VREDRAW;
   return RegisterClass(&WndClass);
   
  }
视频教程列表
文章教程搜索
 
C语言程序设计推荐教程
C语言程序设计热门教程
看全部视频教程
购买方式/价格
购买视频教程: 咨询客服
tel:15972130058