Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How do I use string as a param for CreateWindowEx function

How do I use string as a param for CreateWindowEx function

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpc++visual-studioquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    scody
    wrote on last edited by
    #1

    Hi all, I am trying to get the string supplied as a param in this function to be displayed as window title when executed but I am gettin compiler error. here is the code which is causing compiler error hwnd = CreateWindowEx( NULL, "AeroClass", "Aerobatics by Scody", WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 100, 100, 500, 500, NULL, NULL, hInstance, NULL); and the compiler error is c:\visual studio 2005\projects\aerobatics\aerobatics\aerobatics.cpp(132) : error C2440: '=' : cannot convert from 'const char [10]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast c:\visual studio 2005\projects\aerobatics\aerobatics\aerobatics.cpp(149) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [10]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Can anyone please help me in gettin this string displayed on the window title when executed. Thanks Scody

    M H S 3 Replies Last reply
    0
    • S scody

      Hi all, I am trying to get the string supplied as a param in this function to be displayed as window title when executed but I am gettin compiler error. here is the code which is causing compiler error hwnd = CreateWindowEx( NULL, "AeroClass", "Aerobatics by Scody", WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 100, 100, 500, 500, NULL, NULL, hInstance, NULL); and the compiler error is c:\visual studio 2005\projects\aerobatics\aerobatics\aerobatics.cpp(132) : error C2440: '=' : cannot convert from 'const char [10]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast c:\visual studio 2005\projects\aerobatics\aerobatics\aerobatics.cpp(149) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [10]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Can anyone please help me in gettin this string displayed on the window title when executed. Thanks Scody

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Your project settings are set to use Unicode, but you're passing single-byte strings. Either switch to the multi-byte character set or use the _T macro on your literals.

      --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

      1 Reply Last reply
      0
      • S scody

        Hi all, I am trying to get the string supplied as a param in this function to be displayed as window title when executed but I am gettin compiler error. here is the code which is causing compiler error hwnd = CreateWindowEx( NULL, "AeroClass", "Aerobatics by Scody", WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 100, 100, 500, 500, NULL, NULL, hInstance, NULL); and the compiler error is c:\visual studio 2005\projects\aerobatics\aerobatics\aerobatics.cpp(132) : error C2440: '=' : cannot convert from 'const char [10]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast c:\visual studio 2005\projects\aerobatics\aerobatics\aerobatics.cpp(149) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [10]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Can anyone please help me in gettin this string displayed on the window title when executed. Thanks Scody

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #3

        Use hwnd = CreateWindowEx( NULL, _T("AeroClass"), _T("Aerobatics by Scody"),...


        WhiteSky


        1 Reply Last reply
        0
        • S scody

          Hi all, I am trying to get the string supplied as a param in this function to be displayed as window title when executed but I am gettin compiler error. here is the code which is causing compiler error hwnd = CreateWindowEx( NULL, "AeroClass", "Aerobatics by Scody", WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 100, 100, 500, 500, NULL, NULL, hInstance, NULL); and the compiler error is c:\visual studio 2005\projects\aerobatics\aerobatics\aerobatics.cpp(132) : error C2440: '=' : cannot convert from 'const char [10]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast c:\visual studio 2005\projects\aerobatics\aerobatics\aerobatics.cpp(149) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [10]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast Can anyone please help me in gettin this string displayed on the window title when executed. Thanks Scody

          S Offline
          S Offline
          scody
          wrote on last edited by
          #4

          I changed my project settings to use multi-byte character set and it worked! Thanks very much! Scody

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups