网上找到的方法均无法解决!
cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'
就是下面这个函数:
hWnd = CreateWindow("EDIT", _T("This window was created from main() and can get messages from the console below."),我使用L"ABC"或者_T("ABC")错误依旧。
我的是Console Application。默认使用Unicode的VC2005。#include <windows.h>
#include <stdio.h>DWORD WINAPI mainGUI( LPVOID lp)
{
  HMODULE hInstance= 0;
  hInstance = GetModuleHandle(NULL);
  HWND  hWnd;  MSG msg;
  hWnd = CreateWindow("EDIT", _T("This window was created from main() and can get messages from the console below."),
   WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
  if (!hWnd) return (1);
  *(HWND*)lp = hWnd;
  ShowWindow(hWnd, SW_SHOW);
  UpdateWindow(hWnd);
  while (GetMessage(&msg, NULL, NULL, NULL))
  {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
  }
  return (msg.wParam);
}int main(int argc, char* argv[])
{
   DWORD ID;  HWND  hWindow;
   char szOutput[64];
   CreateThread(NULL,0,mainGUI, &hWindow, NULL,&ID);
   printf("This console created the window above.\nType in the message you want to send to the window.\n\"quit\" to exit.\n\n");
   while (true) {
      scanf("%s", szOutput);
      if (!strcmp(szOutput, "quit")) break;
      SendMessage(hWindow,WM_SETTEXT, strlen(szOutput), (LPARAM)szOutput);
   }
   return 0;
}error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'

解决方案 »

  1.   

    unicode ?改成:
    hWnd = CreateWindow(_T("EDIT"), _T("This window was created from main() and can get messages from the console below."), 
       WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT, CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL); 
      

  2.   

    的确是这样。我幡然醒悟了。
    可是:
    cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR' 
    为什么错误是parameter 2而不是parameter 1呢?
      

  3.   

    因为CreateWindow是一个宏,展开后是调用CreateWindowExW,CreateWindowExW的第1参数自动给0,后面依次给CreateWindow的参数,所以CreateWindow的第1参数变成了CreateWindowExW第2参数,编译时是在宏展开后检查出错误的,所以是parameter 2。
      

  4.   

    cnzdgs好厉害!
    可是
    HWND CreateWindow(          LPCTSTR lpClassName,
        LPCTSTR lpWindowName,
        DWORD dwStyle,
        int x,
        int y,
        int nWidth,
        int nHeight,
        HWND hWndParent,
        HMENU hMenu,
        HINSTANCE hInstance,
        LPVOID lpParam
    );
    并不是一个宏阿?我查找了MSDN