VC++笔记(一)

 

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

LRESULT CALLBACK WNDFUN(HWND hWnd,UINT msg,WPARAM wparam,LPARAM lparam);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
 WNDCLASS wndcls;
 wndcls.style = CS_DBLCLKS|CS_VREDRAW|CS_HREDRAW;
 wndcls.lpszMenuName = NULL;
 wndcls.lpszClassName = "yunzhongyue";
 wndcls.lpfnWndProc = WNDFUN;
 wndcls.hInstance = GetModuleHandle(NULL);
 wndcls.hIcon = NULL;//LoadIcon(NULL,IDI_APPLICATION);
 wndcls.hCursor = NULL ;// LoadCursor(NULL,IDC_ARROW)
 wndcls.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH/*GRAY_BRUSH*/);
 wndcls.cbClsExtra = 0;
 wndcls.cbWndExtra = 6;

 RegisterClass(&wndcls);
 
 HWND hwnd;
 hwnd = CreateWindow("yunzhongyue","Win32App_yunzhongyue",WS_CAPTION|WS_OVERLAPPEDWINDOW|WS_SYSMENU,500,50,400,400,NULL,NULL,hInstance,NULL);

 ShowWindow(hwnd,SW_SHOW);
 UpdateWindow(hwnd);
 
 MSG msg;
 while(GetMessage(&msg,NULL,0,0))
 {
  TranslateMessage(&msg);
  DispatchMessage(&msg);
 }
 return msg.wParam;
 //return 0;
}
LRESULT CALLBACK WNDFUN(HWND hWnd,UINT msg,WPARAM wparam,LPARAM lparam)
{
 switch(msg)
 {
 case WM_PAINT:
  {
   HDC hdc = GetDC(hWnd);
   SetBkMode(hdc,TRANSPARENT);
   TextOut(hdc,120,80,"云中岳好样的",12);
   DeleteDC(hdc);
   break;
  
  }
 case WM_RBUTTONDOWN:
              MessageBox(hWnd,"mouse clicked","weixin",0);
              break;
 case WM_LBUTTONDOWN:
              MessageBox(hWnd,"mouse clicked","weixin",0);
              HDC hdc;
              hdc=GetDC(hWnd);
              TextOut(hdc,50,50,"计算机编程语言培训",strlen("计算机编程语言培训"));


 case WM_CLOSE:
  {
   
   DestroyWindow(hWnd);
   break;

  }
 case WM_DESTROY:
  {
   PostQuitMessage(0);
   break;
  }
 default:
  return DefWindowProc(hWnd ,msg,wparam,lparam);
 
 }

 return 0;

}

 

以下是转载内容:

#include <windows.h>

#include <stdio.h>

 

LRESULT CALLBACK WinSunProc(           //窗口过程函数前向引用声明

  HWND hwnd,      // handle to window          //窗口句柄

  UINT uMsg,      // message identifier        //消息

  WPARAM wParam,  // first message parameter  

  LPARAM lParam   // second message parameter   //附加参数

);

 

int WINAPI WinMain(                               //主函数WinMain

  HINSTANCE hInstance,      // handle to current instance  //当前实例句柄

  HINSTANCE hPrevInstance,  // handle to previous instance  //先前实例句柄

  LPSTR lpCmdLine,          // command line

  int nCmdShow             // show state

)

{

       WNDCLASS wndcls;

       wndcls.cbClsExtra=0;

       wndcls.cbWndExtra=0;

       wndcls.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);

//窗口类的背景画刷句柄,就是背景颜色

       wndcls.hCursor=LoadCursor(NULL,IDC_ARROW);  //窗口中光标的形状

       wndcls.hIcon=LoadIcon(NULL,IDI_APPLICATION);//窗口左上角的图形

       wndcls.hInstance=hInstance;

       wndcls.lpfnWndProc=WinSunProc;

       wndcls.lpszClassName="Weixin2009";          //类的名字

       wndcls.lpszMenuName=NULL;                  //菜单名字

       wndcls.style=0;//CS_HREDRAW ;//| CS_VREDRAW;

//当窗口发生变化时窗口重画,为0则表示不重画

 

       RegisterClass(&wndcls);  //注册窗口类

    //创建窗口

       HWND hwnd;              //定义窗口句柄

       hwnd=CreateWindow("Weixin2009","北京维新科学技术培训中心",WS_OVERLAPPEDWINDOW,

              200,200,600,400,NULL,NULL,hInstance,NULL);

 

   /*HWND CreateWindow(

  LPCTSTR lpClassName,   // pointer to registered class name //注册类名的指针

  LPCTSTR lpWindowName, // pointer to window name //窗口标题名字

  DWORD dwStyle,        // window style //所创建窗口的具体样式

  int x,                 // horizontal position of window

  int y,                // vertical position of window//窗口显示时左上角的坐

  int nWidth,           // window width

  int nHeight,          // window height   //窗口的宽度和高度

  HWND hWndParent,  // handle to parent or owner window   //副窗口

  HMENU hMenu,     // handle to menu or child-window identifier //菜单的句柄

  HANDLE hInstance,  //handle to application instance  //当前应用程序实例句柄

  LPVOID lpParam        // pointer to window-creation data   //附加信息

);*/

 

       ShowWindow(hwnd,SW_SHOW);             //显示窗口

       UpdateWindow(hwnd);                       //更新窗口

 

       MSG msg;                                //消息循环

       while(GetMessage(&msg,NULL,0,0))   //从消息队列中取出一个具体的消息

       {

              TranslateMessage(&msg);         //

              DispatchMessage(&msg);        //通过此函数把消息交给操作系统

       }

       return 0;

}

 

LRESULT CALLBACK WinSunProc(                   //窗口过程函数前向引用声明

  HWND hwnd,      // handle to window          //窗口句柄

  UINT uMsg,      // message identifier        //消息

  WPARAM wParam,  // first message parameter  

  LPARAM lParam   // second message parameter   //附加参数

)

{

       switch(uMsg)

       {

       case WM_CHAR:

              char szChar[20];

              sprintf(szChar,"char is %c",wParam);

              MessageBox(hwnd,szChar,"weixin",0);

              break;

       case WM_RBUTTONDOWN:

              MessageBox(hwnd,"mouse clicked","weixin",0);

              break;

       case WM_LBUTTONDOWN:

              MessageBox(hwnd,"mouse clicked","weixin",0);

              HDC hdc;

              hdc=GetDC(hwnd);

              TextOut(hdc,50,50,"计算机编程语言培训",strlen("计算机编程语言培训"));

 

              /* 关于TextOut 函数

              BOOL TextOut(

        HDC hdc,           // handle to device context 窗口句柄

        int nXStart,       // x-coordinate of starting position

        int nYStart,       // y-coordinate of starting position   输出时的坐标

        LPCTSTR lpString,  // pointer to string            输出文本的内容

        int cbString       // number of characters in string  输出文本的字符数

              );

              */

              ReleaseDC(hwnd,hdc);        //释放DC

              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,"是否真的结束?","weixin",MB_YESNO))

              {

                     DestroyWindow(hwnd);

              }

              break;

       case WM_DESTROY:

              PostQuitMessage(0);

              break;

       default:

              return DefWindowProc(hwnd,uMsg,wParam,lParam);  /其他消息的处理

       }

       return 0;

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值