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. A simple question about Static Controls

A simple question about Static Controls

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++json
5 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.
  • T Offline
    T Offline
    tiwal
    wrote on last edited by
    #1

    Hello, I have been using controls in VC++ 6.0 for years without any particular problem. This time I wanted to shift to VC++ under VS2008, using unmanaged code . I thought the same code that creates a trivial main window, and then the simplest Static control in the main window, would work well with VS2008 too. It doesn't seem so . I am wondering what's wrong with the following snippet :

    hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

    if (!hWnd)
    {
    return FALSE;
    }

    hLabelPath = CreateWindow ((LPCWSTR)"LABEL", (LPCWSTR)"Path", WS_CHILD | WS_BORDER | SS_OWNERDRAW, 10, 10, 100, 100, hWnd, 0, hInstance, &DIS);

    i = GetLastError ();
    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);

    I can see the main window appearing with the menu and all the rest, but the Static control doesn't appear. I get a NULL handle as a return from its CreateWindow (). The error code is 1407, appearently meaning that the control class ("Static") is unknown. I have been seaching all the MSDN documentation without finding an useful hint. What's even stranger , the above code works perfectly under VC++ 6.0. Any idea ? Thanks

    T L 2 Replies Last reply
    0
    • T tiwal

      Hello, I have been using controls in VC++ 6.0 for years without any particular problem. This time I wanted to shift to VC++ under VS2008, using unmanaged code . I thought the same code that creates a trivial main window, and then the simplest Static control in the main window, would work well with VS2008 too. It doesn't seem so . I am wondering what's wrong with the following snippet :

      hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

      if (!hWnd)
      {
      return FALSE;
      }

      hLabelPath = CreateWindow ((LPCWSTR)"LABEL", (LPCWSTR)"Path", WS_CHILD | WS_BORDER | SS_OWNERDRAW, 10, 10, 100, 100, hWnd, 0, hInstance, &DIS);

      i = GetLastError ();
      ShowWindow(hWnd, nCmdShow);
      UpdateWindow(hWnd);

      I can see the main window appearing with the menu and all the rest, but the Static control doesn't appear. I get a NULL handle as a return from its CreateWindow (). The error code is 1407, appearently meaning that the control class ("Static") is unknown. I have been seaching all the MSDN documentation without finding an useful hint. What's even stranger , the above code works perfectly under VC++ 6.0. Any idea ? Thanks

      T Offline
      T Offline
      tiwal
      wrote on last edited by
      #2

      To avoid confusion, in the original snippet the class declared in the CreateWindow is "Static", and not "Label" as stated . Sorry for the mistake .

      _ 1 Reply Last reply
      0
      • T tiwal

        To avoid confusion, in the original snippet the class declared in the CreateWindow is "Static", and not "Label" as stated . Sorry for the mistake .

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        You cannot simply use typecasting. Try L"Static".

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++) (October 2009 - September 2013)

        Polymorphism in C

        1 Reply Last reply
        0
        • T tiwal

          Hello, I have been using controls in VC++ 6.0 for years without any particular problem. This time I wanted to shift to VC++ under VS2008, using unmanaged code . I thought the same code that creates a trivial main window, and then the simplest Static control in the main window, would work well with VS2008 too. It doesn't seem so . I am wondering what's wrong with the following snippet :

          hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
          CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

          if (!hWnd)
          {
          return FALSE;
          }

          hLabelPath = CreateWindow ((LPCWSTR)"LABEL", (LPCWSTR)"Path", WS_CHILD | WS_BORDER | SS_OWNERDRAW, 10, 10, 100, 100, hWnd, 0, hInstance, &DIS);

          i = GetLastError ();
          ShowWindow(hWnd, nCmdShow);
          UpdateWindow(hWnd);

          I can see the main window appearing with the menu and all the rest, but the Static control doesn't appear. I get a NULL handle as a return from its CreateWindow (). The error code is 1407, appearently meaning that the control class ("Static") is unknown. I have been seaching all the MSDN documentation without finding an useful hint. What's even stranger , the above code works perfectly under VC++ 6.0. Any idea ? Thanks

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          hLabelPath = CreateWindow ((LPCWSTR)"LABEL", ...

          You cannot use a cast to convert an ASCII string to Unicode. Use the correct form, either L"string value" or TEXT("string value").

          T 1 Reply Last reply
          0
          • L Lost User

            hLabelPath = CreateWindow ((LPCWSTR)"LABEL", ...

            You cannot use a cast to convert an ASCII string to Unicode. Use the correct form, either L"string value" or TEXT("string value").

            T Offline
            T Offline
            tiwal
            wrote on last edited by
            #5

            Thank you both Superman and Richard ... now the Static appears correctly ...:thumbsup:

            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