VC/win32 windows 窗口的注册和创建

windows 窗口的注册和创建
   1 窗口创建的过程
     1.1 定义WinMain函数
     1.2 定义窗口处理函数 WindowProc
     1.3 注册窗口类(WNDCLASS, RegisterClass)
     1.4 创建窗口(CreateWindow)
     1.5 显示窗口(ShowWindow/UpdateWindow)
     1.6 消息循环(GetMessage/TranslateMessage/
                   DispatchMessage)
     1.7 消息处理

   2 窗口类
     窗口类是一个结构体,包含了窗口创建的各种参
     数信息。每个窗口都需要一个窗口类。
     每个窗口类都有一个名称,使用之前注册到系统
   3 窗口类的分类
     3.1 系统窗口类
        系统已经注册的窗口类,所有应用程序无须
 注册,直接使用。
     3.2 应用程序全局窗口类
        由用户自己定义,当前应用程序的所有模块
 均可以使用。
     3.3 应用程序局部窗口类
        由用户自己定义,当前应用程序的本模块可以
 使用。
   4 系统窗口类
     不需要注册(不需要RegisterClass),直接使用
     系统已经定义的窗口类,即可。
     系统注册的窗口类 例如:
         按钮 - BUTTON
  编辑框 - EDIT

 

 #include "stdafx.h"

HINSTANCE g_hInstance = 0;
void SysReg( ){
 HWND hWnd = CreateWindow( "EDIT", "WinButton",
     WS_OVERLAPPEDWINDOW,
              100, 100, 500, 500, NULL, NULL,
        g_hInstance, NULL );
 ShowWindow( hWnd, SW_SHOW );
 UpdateWindow( hWnd );
 MSG msg = { 0 };
 while( GetMessage( &msg, NULL, 0, 0 ) ){
  TranslateMessage( &msg );
  DispatchMessage( &msg );
 }
}

void AppReg( ){
 WNDCLASSEX wce = { 0 };
 wce.cbSize = sizeof( wce );
 wce.style = CS_HREDRAW|CS_VREDRAW;
 wce.lpfnWndProc = DefWindowProc;
 wce.cbClsExtra = 0;
 wce.cbWndExtra = 0;
 wce.hInstance = g_hInstance;
 wce.hIcon = NULL;
 wce.hCursor = NULL;
 wce.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
 wce.lpszClassName = "MyApp";
 wce.hIconSm = NULL;
 wce.lpszMenuName = NULL;
 ATOM nAtom = RegisterClassEx( &wce );
 if( nAtom == 0 ){
  MessageBox( NULL, "注册窗口失败", "Infor", MB_OK );
  return;
 }
 HWND hWnd = CreateWindow( "MyApp", "AppWizard",
           WS_OVERLAPPEDWINDOW,
           100, 100, 500, 500, NULL, NULL, g_hInstance,
     NULL );
 ShowWindow( hWnd, SW_SHOW );
 UpdateWindow( hWnd );
 MSG msg = { 0 };
 while( GetMessage( &msg, NULL, 0, 0 ) ){
  TranslateMessage( &msg );
  DispatchMessage( &msg );
 }


}

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
  // TODO: Place code here.
 g_hInstance = hInstance;
//    SysReg( );
 AppReg( );
 return 0;
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值