VC学习之路(实例代码1) - [VC学习]

// GT_HelloWorldWin32.cpp
// compile with: /D_UNICODE /DUNICODE /DWIN32 /D_WINDOWS /c
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
// Global variables
// The main window class name.static TCHAR szWindowClass[] = _T("win32app");
// The string that appears in the application's title bar.static TCHAR szTitle[] = _T("Win32 Guided Tour Application");

HINSTANCE hInst;

// Forward declarations of functions included in this code module:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,

                   HINSTANCE hPrevInstance,

                   LPSTR lpCmdLine,

                   int nCmdShow)
{
    WNDCLASSEX wcex;
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = NULL;
    wcex.lpszClassName  = L"Windows";
    wcex.hIconSm        = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
    if (!RegisterClassEx(&wcex))
    {
        MessageBox(NULL,
            _T("Call to RegisterClassEx failed!"),
            _T("Win32 Guided Tour"),
            NULL);
        return 1;
    }
    hInst = hInstance; // Store instance handle in our global variable
    // The parameters to CreateWindow explained:
    // szWindowClass: the name of the application
    // szTitle: the text that appears in the title bar
    // WS_OVERLAPPEDWINDOW: the type of window to create
    // CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y)
    // 500, 100: initial size (width, length)
    // NULL: the parent of this window
    // NULL: this application does not have a menu bar
    // hInstance: the first parameter from WinMain
    // NULL: not used in this application
    HWND hWnd = CreateWindow(
        L"Windows",
        L"西南科技大学",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT,
        500, 100,
        NULL,
        NULL,
        hInstance,
        NULL
    );
    if (!hWnd)
    {
        MessageBox(NULL,
            _T("Call to CreateWindow failed!"),
            _T("Win32 Guided Tour"),
            NULL);
        return 1;
    }

    // The parameters to ShowWindow explained:
    // hWnd: the value returned from CreateWindow
    // nCmdShow: the fourth parameter from WinMain
    ShowWindow(hWnd,nCmdShow);
    UpdateWindow(hWnd);
    // Main message loop:

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

//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//  PURPOSE:  Processes messages for the main window.//
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;
    TCHAR greeting[] = _T("Hello, World!");

    switch (message)
    {
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        // Here your application is laid out.// For this introduction, we just print out "Hello, World!"
        // in the top left corner.
        TextOut(hdc, 5, 5, greeting, _tcslen(greeting));
        // End application-specific layout section.
        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
        break;
    }
    return 0;
}

  

输出显示
5839893_1279010497f.jpg

转载于:https://www.cnblogs.com/xielechuan/archive/2010/08/05/1793337.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实例2-1:演示C++程序的运行步骤。源代码在光盘中“\02\firstcpp”目录下。 实例2-2:Visual C++语言基本元素介绍。源代码在光盘中“\02\secondcpp”目录下。 实例2-3:cout流控制符setw的使用。源代码在光盘中“\02\thirdcpp”目录下。 实例2-4:增加域内填充字符。源代码在光盘中“\02\fourthcpp”目录下。 实例2-5:同一数据用不同进制输出结果。源代码在光盘中“\02\fifthcpp”目录下。 实例2-6:用浮点数的形式输出数据。源代码在光盘中“\02\sixthcpp”目录下。 实例2-7:数据的输入及输出。源代码在光盘中“\02\seventhcpp”目录下。 实例2-8:计算学生平均成绩。源代码在光盘中“\02\eighthcpp”目录下。 实例2-9:函数的调用。源代码在光盘中“\02\ninthcpp”目录下。 实例2-10:用指针传递参数。源代码在光盘中“\02\tenthcpp”目录下。 实例2-11:全局变量和局部变量。源代码在光盘中“\02\eleventhcpp”目录下。 实例2-12:使用指针注意内存的分配。源代码在光盘中“\02\twelfthcpp”目录下。 实例2-13:引用实例。源代码在光盘中“\02\thirteencpp”目录下。 实例2-14:虚函数的使用实例。源代码在光盘中“\02\fourteencpp”目录下。 。。。。。。 实例13-1:动态链接库(Dll)实例。源代码在光盘中“\13\dlltest ”目录下。 实例13-2:鼠标钩子应用实例。源代码在光盘中“\13\MouseHook”目录下。 实例13-3:键盘钩子应用实例。源代码在光盘中“\13\KeyboardHook”目录下。 实例14-1:WinSock网络程序:聊天室。源代码在光盘中“\14\WinSocketChat”目录下。 实例14-2:利用MSComm控件进行串口数据传输。源代码在光盘中“\14\MSComm”目录下。 实例14-3:简单的WinInet应用程序。源代码在光盘中“\14\SimpleNet”目录下。 实例15-1:创建Access数据库。源代码在光盘的“\15\Info”中。 实例15-2:MFC的ODBC数据库实例。源代码在光盘中“\15\Enroll”目录下。 实例15-3:利用ADO查询并操作数据库实例。源代码在光盘中“\15\AdoTest”目录下。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值