回 帖 发 新 帖 刷新版面

主题:[讨论]求教一个问题

#include<windows.h>
#include<stdio.h>

LRESULT CALLBACK WinSunProc(
  HWND hwnd, 
  UINT uMsg, 
  WPARAM wParam, 
  LPARAM lParam 
);

int WINAPI wWinMain(
  HINSTANCE hInstance, 
  HINSTANCE hPrevInstance, 
  LPWSTR lpCmdLine, 
  int nShowCmd 
)
{
    WNDCLASS test;
    test.cbClsExtra=0;
    test.cbWndExtra=0;
    test.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
    test.hCursor=LoadCursor(NULL,IDC_ARROW);
    test.hIcon=LoadIcon(NULL,IDI_APPLICATION);
    test.hInstance=hInstance;
    test.lpfnWndProc=WinSunProc;
    test.lpszClassName="myFirst";
    test.lpszMenuName=NULL;
    test.style=CS_HREDRAW|CS_VREDRAW;

    RegisterClass(&test);

    HWND hello;
    hello=CreateWindow("myFirst","test",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,
        hInstance,NULL);

    ShowWindow(hello,SW_SHOWNORMAL);
    UpdateWindow(hello);

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

LRESULT CALLBACK WinSunProc(
  HWND hwnd, 
  UINT uMsg, 
  WPARAM wParam, 
  LPARAM lParam 
)
{
    switch(uMsg)
    {
    case WM_CHAR:
        char szChar[20];
        sprintf(szChar,"char is %d",wParam);
        MessageBox(hwnd,szChar,"myFirst",0);
        break;
    case WM_LBUTTONDOWN:
        MessageBox(hwnd,"mouse clicked","myFirst",0);
        HDC hdc;
        hdc=GetDC(hwnd);
        TextOut(hdc,0,50,"计算机编程",strlen("计算机编程"));
        ReleaseDC(hwnd,hdc);
        break;
    case WM_PAINT:
        HDC hDC;
        PAINTSTRUCT ps;
        hDC=BeginPaint(hwnd,&ps);
        TextOut(hDC,0,0,"练习",strlen("练习"));
        EndPaint(hwnd,&ps);
        break;
    case WM_CLOSE:
        if(IDYES==MessageBox(hwnd,"是否真的结束","myFirst",MB_YESNO))
        {
            DestroyWindow(hwnd);
        }
        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd,uMsg,wParam,lParam);
    }
    return 0;
}

这是一个Win32程序,在Visual studio 2005中编的 ,但是运行起来总是出错,主要是数据问题,请教各位大侠如何修改啊?

回复列表 (共2个回复)

沙发

主要就是这种类型的错误

“CreateWindowExW”: 不能将参数 2 从“const char [8]”转换为“LPCWSTR”

总共7个错误,都是数据类型转换的错误

板凳

用A2T转换试试,
你在msdn查查就有这个!

我来回复

您尚未登录,请登录后再回复。点此登录或注册