用c语言创建windows窗口

耐得住寂寞,禁得起诱惑,这就是程序人生

步骤:
1.在WinMain中定义各种变量
2.注册窗口类RegisterClass
3.创建窗口CreateWindow
4.显示窗口和更新窗口
ShowWindow (hwnd, iCmdShow) ;
     UpdateWindow (hwnd) ;
5.消息循环
while (GetMessage (&msg, NULL, 0, 0))
     {
          TranslateMessage (&msg) ;
          DispatchMessage (&msg) ;
     }
#include <windows.h>

LRESULT CALLBACK MyProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
     MSG      msg;
     HWND     hwnd;
     static TCHAR szAppName[] = "hl";

     WNDCLASS wndclass;
     wndclass.style        = CS_HREDRAW | CS_VREDRAW;
     wndclass.cbClsExtra   = 0;
     wndclass.cbWndExtra   = 0;
     wndclass.lpfnWndProc  = MyProc;
     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= szAppName;

     if(!RegisterClass(&wndclass))
     {
          MessageBox(NULL,TEXT("error"),TEXT("title"),MB_ICONERROR);
          return 0;
     }
     hwnd = CreateWindow(szAppName,
                              TEXT("Hello"),
                              WS_OVERLAPPEDWINDOW,
                              CW_USEDEFAULT,
                              CW_USEDEFAULT,
                              CW_USEDEFAULT,
                              CW_USEDEFAULT,
                              NULL,
                              NULL,
                              hInstance,
                              NULL
                              );
     ShowWindow(hwnd,nShowCmd);
     UpdateWindow(hwnd);

     while(GetMessage(&msg,hwnd,0,0))
     {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
     }
     return msg.wParam;
}

LRESULT CALLBACK MyProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{

     switch(message)
     {
     case WM_DESTROY:
          PostQuitMessage(0);
          return 0;
     }
     return DefWindowProc(hwnd,message,wParam,lParam);
}

我的blog:http://blog.csdn.net/booirror 

我的邮箱:booirror@163.com



转载于:https://www.cnblogs.com/booirror/archive/2012/07/02/3604318.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值