std::cout << "Goodbye!" << std::endl << std::endl;
之类是控制台命令,
在window中应该使用gdi相关函数

解决方案 »

  1.   

    #include <iostream>
    #include <tchar.h>
    #include <windows.h>#define MAX_STR 100// 全局变量:
    HINSTANCE hInst;                                                    // 当前实例
    TCHAR szTitle[MAX_STR]       = _TEXT("聊天框");    // 标题栏文本
    TCHAR szWindowClass[MAX_STR] = _TEXT("聊天框");    // 主窗口类名// 此代码模块中包含的函数的前向声明:
    ATOM                MyRegisterClass(HINSTANCE hInstance);
    BOOL                InitInstance(HINSTANCE hInstance, int nCmdShow);
    LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);int _tmain(int argc, _TCHAR* argv[])
    {
    std::cout << "聊天系统" << std::endl << std::endl;
    std::cout << "================================" << std::endl << std::endl; HINSTANCE hInstance = NULL;
    int       nCmdShow  = SW_SHOW;      // 该变量取值参见MSDN hInstance = GetModuleHandle(NULL);
    std::cout << "hInstance: " << hInstance << std::endl;
    std::cout << "hInstance->unused: " << hInstance->unused << std::endl << std::endl;
    std::cout << "================================" << std::endl << std::endl; MSG msg; MyRegisterClass(hInstance); // 执行应用程序初始化:
    if (!InitInstance (hInstance, nCmdShow)) 
    {
    std::cout << "Error in InitInstance()!" << std::endl;
    return FALSE;
    } // 主消息循环:
    while (GetMessage(&msg, NULL, 0, 0)) 
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    } return (int) msg.wParam;
    }//
    //  函数: MyRegisterClass()
    //
    //  目的: 注册窗口类。
    //
    ATOM MyRegisterClass(HINSTANCE hInstance)
    {
    WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = (WNDPROC)WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = NULL;
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW-4);
    wcex.lpszMenuName   = NULL;
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = NULL; return RegisterClassEx(&wcex);
    }//
    //   函数: InitInstance(HANDLE, int)
    //
    //   目的: 保存实例句柄并创建主窗口。
    //
    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
    HWND hWnd; hInst = hInstance; // 将实例句柄存储在全局变量中 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,50,50,700,600,NULL, NULL, hInstance, NULL); if (!hWnd)
    {
    return FALSE;
    } ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd); return TRUE;
    }//
    //  函数: WndProc(HWND, unsigned, WORD, LONG)
    //
    //  目的: 处理主窗口的消息。
    //
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    PAINTSTRUCT ps;
    HDC hdc;
    HWND btn;
    HWND window;
    HWND textwindow;
    TCHAR strEdit[1000];
    switch (message) 


    case WM_CREATE:
    btn=CreateWindow(L"Button",L"发 送",WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,520,520,80,30,         
    hWnd,        
    NULL,hInst, 
    NULL);
    window=CreateWindow(L"Static", NULL, WS_VISIBLE|WS_CHILD|WS_VSCROLL,
    0,0,500,350,hWnd, NULL, hInst, NULL);
    textwindow=CreateWindow(L"EDIT",NULL,WS_CHILD | WS_VISIBLE|WS_VSCROLL|ES_LEFT |
    ES_MULTILINE | ES_AUTOVSCROLL| ES_AUTOHSCROLL,0,400,500,150,hWnd,NULL,hInst,NULL);
    SetFocus(textwindow);
    std::cout << "Hello! " << std::endl;
    break;
    case WM_COMMAND:
    if(LOWORD(wParam)==BN_CLICKED)
    //按下按钮
    {
    GetWindowText(textwindow,strEdit,1000);
    //GetWindowText(GetDlgItem(hWnd,3),strEdit,1000);
    SendMessage(GetDlgItem(hWnd,2),NULL,0,0);
    //SetWindowText(GetDlgItem(hWnd,2),strEdit);
    }
    break;
    case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    EndPaint(hWnd, &ps);
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    std::cout << "Goodbye!" << std::endl << std::endl;
    break;
    default:
    return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return (DefWindowProc(hWnd,message,wParam,lParam));
    }
      

  2.   

    声明成静态变量
    static HWND btn;
    static HWND window;
    static HWND textwindow;
    case WM_COMMAND中
    if((HWND)lParam == btn && LOWORD(wParam) == BN_CLICKED)