API窗口

以下为在VC6++下编译的API窗口源代码,若在VS上可能会出现乱码,

解决方案:1.在字符串前加"L"
    2.text("字符串");
    3._T("字符串");

#include <windows.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,PSTR szCmdLine, int iCmdShow)
{
     static char szWndClassName[] = "hellowin";
     HWND         hwnd ;
     MSG          msg ;
     WNDCLASS     wndclass ;
//窗口共性
     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;//窗口水平和垂直方向上均可自适应的变化
     wndclass.lpfnWndProc   = WndProc ;//与窗口过程有关====================================================
     wndclass.cbClsExtra    = 0 ;//为窗口类额外分配的内存空间
     wndclass.cbWndExtra    = 0 ;//此处虽为分配内存空间,但得告诉系统,否则出错
     wndclass.hInstance     = hInstance ;//传入实例句柄
     wndclass.hIcon /*句柄图标,窗口小图标*/        = LoadIcon (NULL, IDI_APPLICATION) ;//系统图标
     wndclass.hCursor/*光标*/       = LoadCursor (NULL, IDC_ARROW/*箭头*/) ;
     wndclass.hbrBackground/*背景颜色*/ = (HBRUSH) GetStockObject (WHITE_BRUSH/*白色*/) ;
     wndclass.lpszMenuName /*菜单*/ = NULL ; 
     wndclass.lpszClassName = szWndClassName ;//为窗口类起一个名字======================================
     if (!RegisterClass (&wndclass/*窗口类的地址*/))
     {//注册窗口类
          MessageBox (NULL, "注册失败","错误", MB_ICONERROR) ;
          return 0 ;
     }
//窗口句柄(参数),窗口个性
     hwnd = CreateWindow (szWndClassName,             // window class name
                          "喏~消除",  // window caption
                          WS_OVERLAPPEDWINDOW,        // window style
                          CW_USEDEFAULT,              // initial x position
                          CW_USEDEFAULT,              // initial y position
                          CW_USEDEFAULT,              // initial x size
                          CW_USEDEFAULT,              // initial y size
                          NULL,                       // parent window handle,父窗口
                          NULL,                       // window menu handle,菜单
                          hInstance,                  // program instance handle
                          NULL) ;                     // creation parameters,额外参数
     //显示窗口
     ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ;//与上一条一般一起使用


     while (GetMessage (&msg, NULL, 0, 0))  //消息队列
     {//取出
          TranslateMessage (&msg) ;//转换
          DispatchMessage (&msg) ;//传递给Windows(统一调度)
     }
     return msg.wParam ;  //WM_QUIT,其实就是0
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{//WndProc窗口过程,操作系统调用的,==========================重点===========
HDC         hdc ;
     PAINTSTRUCT ps ;
     RECT        rect ;
     switch (message)
     {
case WM_PAINT://窗口必须重绘的时候
          hdc = BeginPaint (hwnd, &ps) ;//返回设备描述表句柄
          GetClientRect (hwnd, &rect) ;         
          DrawText (hdc, TEXT ("这是一个窗口"), -1/*显示的字节数,-1表示全部显示*/, &rect,DT_SINGLELINE | DT_CENTER | DT_VCENTER/*字在中央*/) ;
          EndPaint (hwnd, &ps) ;//
          return 0 ;
 case WM_DESTROY:
          PostQuitMessage (0) ;//发送到消息队列中
          return 0 ;
     }
     return DefWindowProc (hwnd, message, wParam, lParam) ;//默认的处理,例如:最大化,最小化,拖动等
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值