A simple question about Static Controls
-
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
-
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
-
To avoid confusion, in the original snippet the class declared in the CreateWindow is "Static", and not "Label" as stated . Sorry for the mistake .
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)
-
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
-
hLabelPath = CreateWindow ((LPCWSTR)"LABEL", ...
You cannot use a cast to convert an ASCII string to Unicode. Use the correct form, either
L"string value"
orTEXT("string value")
.