-
May 19th, 2011, 04:57 PM
#1
Problem with Common Controls
Hey,
I want to give my applications the modern look of windows. I tried manifest files and c++ functions but when I use one of them the window does not show my button at all.
Here is the code:
Code:
#pragma comment( lib, "ComCtl32.lib" )
#define UNICODE
#include <Windows.h>
#include <CommCtrl.h>
InitCommonControls( );
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "12_child_windows.manifest"
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam );
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iShowingMode );
HINSTANCE hPublicInstance;
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iShowingMode )
{
HWND hWnd;
MSG msg;
WNDCLASSW wndClass;
hPublicInstance = hInstance;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH );
wndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
wndClass.hIcon = LoadIcon ( NULL, IDI_WINLOGO );
wndClass.hInstance = hInstance;
wndClass.lpfnWndProc = WndProc;
wndClass.lpszClassName = L"Child Window";
wndClass.lpszMenuName = NULL;
wndClass.style = CS_VREDRAW | CS_HREDRAW;
if( !RegisterClassW( &wndClass ) )
{
MessageBoxW( NULL, L"The program could not start!", L"Error", MB_OK );
return -1;
}
hWnd = CreateWindow( L"Child Window",
L"Child Windows",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow ( hWnd, iShowingMode );
UpdateWindow( hWnd );
while( GetMessageW( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage ( &msg );
}
return msg.lParam;
}
LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
static HWND hWndChild;
switch( msg )
{
case WM_CREATE:
hWndChild = CreateWindow( L"Button",
L"Button",
WS_CHILDWINDOW | WS_VISIBLE | BS_PUSHBUTTON,
10,
10,
50,
50,
hWnd,
NULL,
hPublicInstance,
NULL
);
return 0;
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
}
return DefWindowProcW( hWnd, msg, wParam, lParam );
}
And here are the errors I get:
Code:
------ Build started: Project: 12_child_windows, Configuration: Debug Win32 ------
main.cpp
c:\c++\12_child_windows\12_child_windows\main.cpp(8): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\c++\12_child_windows\12_child_windows\main.cpp(8): error C2556: 'int InitCommonControls(void)' : overloaded function differs only by return type from 'void InitCommonControls(void)'
c:\program files\microsoft sdks\windows\v7.0a\include\commctrl.h(135) : see declaration of 'InitCommonControls'
c:\c++\12_child_windows\12_child_windows\main.cpp(8): error C2373: 'InitCommonControls' : redefinition; different type modifiers
c:\program files\microsoft sdks\windows\v7.0a\include\commctrl.h(135) : see declaration of 'InitCommonControls'
c:\c++\12_child_windows\12_child_windows\main.cpp(10): error C2226: syntax error : unexpected type 'LPWSTR'
c:\c++\12_child_windows\12_child_windows\main.cpp(31): error C2065: 'WndProc' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Does anybody know what I am doing wrong?
(I am using Visual Studio 2010)
Niklas
-
May 20th, 2011, 08:02 AM
#2
Re: Problem with Common Controls
The first problem I see is that your line
Code:
InitCommonControls( );
should be in a function. Here it is hanging in cyberspace and will never be called.
For instance, call that function when your window is created, e.g. after WM_CREATE
Code:
case WM_CREATE:
InitCommonControls( );
-
June 7th, 2011, 08:09 PM
#3
Re: Problem with Common Controls
Originally Posted by olivthill2
For instance, call that function when your window is created, e.g. after WM_CREATE
I would recommend calling InitCommonControls() before any windows are created or window classes registered, i.e. as the first line in WinMain:
Code:
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iShowingMode )
{
HWND hWnd;
MSG msg;
WNDCLASSW wndClass;
InitCommonControls();
-
June 7th, 2011, 08:13 PM
#4
Re: Problem with Common Controls
I've just noticed another problem. The line:
Code:
CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "12_child_windows.manifest"
...should be in a resource script file (*.rc), not in a C/C++ module. That line will not only have no effect, I would expect it would also produce a compiler error.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|