| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 756 人关注过本帖
标题:vc2010中怎么解决乱码???
只看楼主 加入收藏
环及
Rank: 2
来 自:广西
等 级:论坛游民
帖 子:21
专家分:25
注 册:2012-3-19
结帖率:83.33%
收藏
已结贴  问题点数:10 回复次数:4 
vc2010中怎么解决乱码???
#include <windows.h>
#include<cstdio>

// Global variable
 
HINSTANCE hinst;
 
// Function prototypes.
 
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
BOOL InitApplication(HINSTANCE);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);
 
// Application entry point.
 
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;
 
    if (!InitApplication(hinstance))
        return FALSE;
 
    if (!InitInstance(hinstance, nCmdShow))
        return FALSE;
 
    while (GetMessage(&msg, (HWND) NULL, 0, 0) != 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
        UNREFERENCED_PARAMETER(lpCmdLine);
}
 
BOOL InitApplication(HINSTANCE hinstance)
{
    WNDCLASSEX wcx;
 
    // Fill in the window class structure with parameters
    // that describe the main window.
 
    wcx.cbSize = sizeof(wcx);          // size of structure
    wcx.style = CS_HREDRAW |
        CS_VREDRAW;                    // redraw if size changes
    wcx.lpfnWndProc = MainWndProc;     // points to window procedure
    wcx.cbClsExtra = 0;                // no extra class memory
    wcx.cbWndExtra = 0;                // no extra window memory
    wcx.hInstance = hinstance;         // handle to instance
    wcx.hIcon = LoadIcon(NULL,
        IDI_ERROR);              // predefined app. icon
    wcx.hCursor = LoadCursor(NULL,
        IDC_ARROW);                    // predefined arrow
    wcx.hbrBackground =(HBRUSH)GetStockObject(
        WHITE_BRUSH);                  // white background brush
    wcx.lpszMenuName =  (LPCWSTR)"MainMenu";    // name of menu resource
    wcx.lpszClassName =(LPCWSTR) "MainWClass";  // name of window class
    wcx.hIconSm =(HICON)LoadImage(hinstance, // small class icon
        MAKEINTRESOURCE(5),
        IMAGE_ICON,
        GetSystemMetrics(SM_CXSMICON),
        GetSystemMetrics(SM_CYSMICON),
        LR_DEFAULTCOLOR);
 
    // Register the window class.
 
    return RegisterClassEx(&wcx);
}
 
BOOL InitInstance(HINSTANCE hinstance, int nCmdShow)
{
    HWND hwnd;
 
    // Save the application-instance handle.
 
    hinst = hinstance;
 
    // Create the main window.
 
    hwnd = CreateWindow(
       (LPCWSTR)"MainWClass",        // name of window class
        (LPCWSTR)"哈哈",            // title-bar string
        WS_OVERLAPPEDWINDOW, // top-level window
        CW_USEDEFAULT,       // default horizontal position
        CW_USEDEFAULT,       // default vertical position
        CW_USEDEFAULT,       // default width
        CW_USEDEFAULT,       // default height
        (HWND) NULL,         // no owner window
        (HMENU) NULL,        // use class menu
        hinstance,           // handle to application instance
        (LPVOID) NULL);      // no window-creation data
 
    if (!hwnd)
        return FALSE;
 
    // Show the window and send a WM_PAINT message to the window
    // procedure.
 
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);
    return TRUE;
 
}
LRESULT   CALLBACK   MainWndProc(
      HWND   hwnd,
      UINT   uMsg,
      WPARAM   wParam,
      LPARAM   lParam
    )
{
switch(uMsg)
{
case   WM_CHAR:
char   szchar[20];
sprintf(szchar,"char   is   %d",wParam);
MessageBox(hwnd,(LPCWSTR)szchar,(LPCWSTR)"哈哈",0);
break;
case   WM_LBUTTONDOWN:
        MessageBox(hwnd,(LPCWSTR)"mouse   click",(LPCWSTR)"哈哈",0);
        HDC   hdc;
        hdc=GetDC(hwnd);
        TextOut(hdc,0,50,(LPCWSTR)"heihei",strlen("heihei"));
        ReleaseDC(hwnd,hdc);
break;
case   WM_PAINT:
        HDC   hDC;
        PAINTSTRUCT   ps;
        hDC=BeginPaint(hwnd,&ps);
        TextOut(hDC,0,0,(LPCWSTR)"嘿嘿",strlen("嘿嘿"));
        EndPaint(hwnd,&ps);
break;
case   WM_CLOSE:
        if(IDYES==MessageBox(hwnd,(LPCWSTR)"是否结束?",(LPCWSTR)"哈哈",MB_YESNO))
        {
                DestroyWindow(hwnd);
                  }
break;
case   WM_DESTROY:
        PostQuitMessage(0);
break;
default:
return   DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return   0;
}
怎么才能输出不乱码呢?
搜索更多相关主题的帖子: include return 
2012-05-12 17:17
hellovfp
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:禁止访问
威 望:30
帖 子:2976
专家分:7697
注 册:2009-7-21
收藏
得分:10 
#include <windows.h>
#include <tchar.h>
#include<cstdio>

// Global variable

HINSTANCE hinst;

// Function prototypes.

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int);
BOOL InitApplication(HINSTANCE);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM);

// Application entry point.

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow)
{
    MSG msg;
   
    if (!InitApplication(hinstance))
        return FALSE;
   
    if (!InitInstance(hinstance, nCmdShow))
        return FALSE;
   
    while (GetMessage(&msg, (HWND) NULL, 0, 0) != 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
    UNREFERENCED_PARAMETER(lpCmdLine);
}

BOOL InitApplication(HINSTANCE hinstance)
{
    WNDCLASSEX wcx;
   
    // Fill in the window class structure with parameters
    // that describe the main window.
   
    wcx.cbSize = sizeof(wcx);          // size of structure
    wcx.style = CS_HREDRAW |
        CS_VREDRAW;                    // redraw if size changes
    wcx.lpfnWndProc = MainWndProc;     // points to window procedure
    wcx.cbClsExtra = 0;                // no extra class memory
    wcx.cbWndExtra = 0;                // no extra window memory
    wcx.hInstance = hinstance;         // handle to instance
    wcx.hIcon = LoadIcon(NULL,
        IDI_ERROR);              // predefined app. icon
    wcx.hCursor = LoadCursor(NULL,
        IDC_ARROW);                    // predefined arrow
    wcx.hbrBackground =(HBRUSH)GetStockObject(
        WHITE_BRUSH);                  // white background brush
    wcx.lpszMenuName =  _T("MainMenu");    // name of menu resource
    wcx.lpszClassName = _T("MainWClass");  // name of window class
    wcx.hIconSm =(HICON)LoadImage(hinstance, // small class icon
        MAKEINTRESOURCE(5),
        IMAGE_ICON,
        GetSystemMetrics(SM_CXSMICON),
        GetSystemMetrics(SM_CYSMICON),
        LR_DEFAULTCOLOR);
   
    // Register the window class.
   
    return RegisterClassEx(&wcx);
}

BOOL InitInstance(HINSTANCE hinstance, int nCmdShow)
{
    HWND hwnd;
   
    // Save the application-instance handle.
   
    hinst = hinstance;
   
    // Create the main window.
   
    hwnd = CreateWindow(
        _T("MainWClass"),        // name of window class
        _T("哈哈"),            // title-bar string
        WS_OVERLAPPEDWINDOW, // top-level window
        CW_USEDEFAULT,       // default horizontal position
        CW_USEDEFAULT,       // default vertical position
        CW_USEDEFAULT,       // default width
        CW_USEDEFAULT,       // default height
        (HWND) NULL,         // no owner window
        (HMENU) NULL,        // use class menu
        hinstance,           // handle to application instance
        (LPVOID) NULL);      // no window-creation data
   
    if (!hwnd)
        return FALSE;
   
    // Show the window and send a WM_PAINT message to the window
    // procedure.
   
    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);
    return TRUE;
   
}
LRESULT   CALLBACK   MainWndProc(
                                 HWND   hwnd,
                                 UINT   uMsg,
                                 WPARAM   wParam,
                                 LPARAM   lParam
                                 )
{
    switch(uMsg)
    {
    case   WM_CHAR:
        TCHAR  szchar[20];
        wsprintf(szchar,_T("char   is   %d"),wParam);
        MessageBox(hwnd,szchar,_T("哈哈"),0);
        break;
    case   WM_LBUTTONDOWN:
        MessageBox(hwnd,_T("mouse   click"),_T("哈哈"),0);
        HDC   hdc;
        hdc=GetDC(hwnd);
        TextOut(hdc,0,50,_T("heihei"),strlen("heihei"));
        ReleaseDC(hwnd,hdc);
        break;
    case   WM_PAINT:
        HDC   hDC;
        PAINTSTRUCT   ps;
        hDC=BeginPaint(hwnd,&ps);
        TextOut(hDC,0,0,_T("嘿嘿"),lstrlen(_T("嘿嘿")));
        EndPaint(hwnd,&ps);
        break;
    case   WM_CLOSE:
        if(IDYES==MessageBox(hwnd,_T("是否结束?"),_T("哈哈"),MB_YESNO))
        {
            DestroyWindow(hwnd);
        }
        break;
    case   WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return   DefWindowProc(hwnd,uMsg,wParam,lParam);
    }
    return   0;
}

我们都在路上。。。。。
2012-05-13 10:10
环及
Rank: 2
来 自:广西
等 级:论坛游民
帖 子:21
专家分:25
注 册:2012-3-19
收藏
得分:0 
谢谢
2012-05-13 11:37
TWO2LIFE
Rank: 2
等 级:论坛游民
帖 子:7
专家分:19
注 册:2012-5-3
收藏
得分:0 
一楼的也可以把LPCWSTR 改为 LPCSTR执行也可以!
2012-05-13 14:32
环及
Rank: 2
来 自:广西
等 级:论坛游民
帖 子:21
专家分:25
注 册:2012-3-19
收藏
得分:0 
我照你那样不行喔把LPCWSTR 改为 LPCSTR。
2012-05-14 08:45
快速回复:vc2010中怎么解决乱码???
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016179 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved