当前位置:编程学习 > C/C++ >>

那位大哥帮忙注释一段代码 c++的

帮我注释下面的代码  特别是API函数的 最好详细点 API函数的作用 说清楚些

#include <windows.h>
#include <stdio.h>

LRESULT CALLBACK WinSunProc(
  HWND hwnd,
  UINT uMsg,
  WPARAM wParam,
  LPARAM lParam
);

int WINAPI WinMain(
  HINSTANCE hInstance,
  HINSTANCE hPrevInstance,
  LPSTR lpCmdLine,
  int nCmdShow
)
{
   WNDCLASS wndclass;
   wndclass.cbClsExtra =0;
   wndclass.cbWndExtra =0;
   wndclass.hbrBackground =(HBRUSH)GetStockObject(BLACK_BRUSH);
   wndclass.hCursor =LoadCursor(NULL,IDC_CROSS);
   wndclass.hIcon=LoadIcon(NULL,IDI_ERROR);
   wndclass.hInstance =hInstance;
   wndclass.lpfnWndProc =WinSunProc;
   wndclass.lpszClassName= "风。。";
   wndclass.lpszMenuName =NULL;
   wndclass.style =CS_HREDRAW | CS_VREDRAW;
   RegisterClass(&wndclass);

   HWND hwnd;
   hwnd=CreateWindow("风。。","习题一。。",WS_OVERLAPPEDWINDOW,
    0,0,600,400,NULL,NULL,hInstance,NULL);

   ShowWindow(hwnd,SW_SHOWNORMAL);
   UpdateWindow(hwnd);

   MSG msg;
   while(GetMessage(&msg,NULL,0,0))
   {
     TranslateMessage(&msg);
  DispatchMessage(&msg);
   }
   return 0;
}
LRESULT CALLBACK WinSunProc(
  HWND hwnd,
  UINT uMsg,
  WPARAM wParam,
  LPARAM lParam
 )
{
 switch(uMsg)
 {
 case WM_CHAR:
  char szChar[20];
  sprintf(szChar,"char is %d",wParam);
  MessageBox(hwnd,szChar,"风。。",0);
  break;
 case WM_LBUTTONDOWN:
  MessageBox(hwnd,"mouse clicked","风。。",0);
  HDC hdc;
  hdc=GetDC(hwnd);
  TextOut(hdc,0,50,"第二次输出",strlen("第二次输出"));
  ReleaseDC(hwnd,hdc);
  break;
 case WM_PAINT:
  HDC hDC;
  PAINTSTRUCT ps;
  hDC=BeginPaint(hwnd,&ps);
     TextOut(hDC,0,0,"第三次输出",strlen("第三次输出"));
  EndPaint(hwnd,&ps);
  break;
 case WM_CLOSE:
  if(IDYES==MessageBox(hwnd,"是否真的结束?","风。。",MB_YESNO))
  {
    DestroyWindow(hwnd);
  }
  break;
 case WM_DESTROY:
  PostQuitMessage(0);
  break;
 default:
  return DefWindowProc(hwnd,uMsg,wParam,lParam);
 }
 return 0;
}

追问:能帮我再把那些函数在说明一下吗

还有

int WINAPI WinMain(//windows main,类似于C语言程序的main主函数
  HINSTANCE hInstance,
  HINSTANCE hPrevInstance,
  LPSTR lpCmdLine,
  int nCmdShow
)

里面的参数说明一下吗 主要的用途

答案:

#include <windows.h>//windows标准定义头文件
#include <stdio.h>//标准i/o函数库

LRESULT CALLBACK WinSunProc(   //"调用返回"结构
  HWND hwnd,//窗口句柄
  UINT uMsg,//消息标识符

      WPARAM wParam,//第一个消息参数
  LPARAM lParam //第二个消息参数
);

int WINAPI WinMain(//windows main,类似于C语言程序的main主函数
  HINSTANCE hInstance,
  HINSTANCE hPrevInstance,
  LPSTR lpCmdLine,
  int nCmdShow
)

//以下是关于windows窗口属性的描述
{  WNDCLASS wndclass;//声明窗口类wndclass
   wndclass.cbClsExtra =0;
   wndclass.cbWndExtra =0;
   wndclass.hbrBackground =(HBRUSH)GetStockObject(BLACK_BRUSH);
   wndclass.hCursor =LoadCursor(NULL,IDC_CROSS);
   wndclass.hIcon=LoadIcon(NULL,IDI_ERROR);
   wndclass.hInstance =hInstance;
   wndclass.lpfnWndProc =WinSunProc;
   wndclass.lpszClassName= "风。。";
   wndclass.lpszMenuName =NULL;
   wndclass.style =CS_HREDRAW | CS_VREDRAW;
   RegisterClass(&wndclass); //注册窗口类 wndclass  

   HWND hwnd;//操作句柄
   hwnd=CreateWindow("风。。","习题一。。",WS_OVERLAPPEDWINDOW,
    0,0,600,400,NULL,NULL,hInstance,NULL);//创建指定的窗口(实体),此时还未显示该窗口

   ShowWindow(hwnd,SW_SHOWNORMAL);//以一般(normal)方式显示hwnd所指向的窗口
   UpdateWindow(hwnd);//更新窗口

   MSG msg;//声明一个消息结构msg
   while(GetMessage(&msg,NULL,0,0)) //循环获得系统发给自己想要的消息
   {
     TranslateMessage(&msg);//翻译当前消息
  DispatchMessage(&msg);//分发当前消息
   }
   return 0;//正常返回
}
LRESULT CALLBACK WinSunProc( //消息处理函数
  HWND hwnd,
  UINT uMsg,
  WPARAM wParam,
  LPARAM lParam
 )
{
 switch(uMsg) //根据参数uMsg的值(即消息类型)进行相应的操作
 {
 case WM_CHAR:
  char szChar[20];
  sprintf(szChar,"char is %d",wParam);
  MessageBox(hwnd,szChar,"风。。",0);
  break;
 case WM_LBUTTONDOWN:
  MessageBox(hwnd,"mouse clicked","风。。",0);
  HDC hdc;
  hdc=GetDC(hwnd);
  TextOut(hdc,0,50,"第二次输出",strlen("第二次输出"));
  ReleaseDC(hwnd,hdc);
  break;
 case WM_PAINT:
  HDC hDC;
  PAINTSTRUCT ps;
  hDC=BeginPaint(hwnd,&ps);
     TextOut(hDC,0,0,"第三次输出",strlen("第三次输出"));
  EndPaint(hwnd,&ps);
  break;
 case WM_CLOSE://当获得关闭消息时做以下操作
  if(IDYES==MessageBox(hwnd,"是否真的结束?","风。。",MB_YESNO))//显示一个消息窗口,并把返回值跟IDYES比较
  {
    DestroyWindow(hwnd);//比较得知用户选择:"是(yes)",摧毁窗口wndclass
  }
  break;
 case WM_DESTROY:
  PostQuitMessage(0);//当收到摧毁消息时,发送退出消息给操作系统
  break;
 default:
  return DefWindowProc(hwnd,uMsg,wParam,lParam);//执行默认的相关处理函数,并返回它的返回值
 }
 return 0;
}

上一个:关于C++的cin.get()的问题
下一个:C++给个求栈最大内存的程序

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,