Thread: Initializing My Control

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    73

    Initializing My Control

    I am having problems linking to Comctl32.dll used for the common control API. How do I go about importing the information from the file?
    Last edited by ElWhapo; 03-31-2005 at 01:03 AM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Did you link to the lib file?
    Also to ensure that the compiler links the lib file you should call InitCommonControls or InitCommonControlsEx
    Last edited by Quantum1024; 03-31-2005 at 01:10 AM.

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    73
    I am using InitCommonControlsEx. I am unsure how to link to the lib file. That is the problem I'm having.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    You can do it with this
    Code:
    #pragma comment(lib,"COMCTL32.LIB").
    or if your using devc++ I think the library is named COMCTL32.A

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    73
    It still does not recognize my common control functions. What am I doing wrong?
    Code:
    // Example Shows How To Create A Basic Animation Control
    #include <windows.h>
    
    #pragma comment(lib,"COMCTL32.LIB")
    
    #define WIDTH 500
    #define HEIGHT 350
    
    void CreateMyWindow();
    LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
    void CreateMyAnimation();
    void InitializeMyCommonControls();
    
    char szClassName[ ] = "Animation";
    
    HWND hWnd;
    HINSTANCE hInstance;
    HWND hWndAnim;
    
    // Main Window Procedure
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
    				   LPSTR iCmdLine, int iCmdShow)
    {
    	CreateMyWindow();
    	ShowWindow(hWnd, iCmdShow);
    
    	MSG Msg;
    	while (GetMessage (&Msg, NULL, 0, 0))
        {
            TranslateMessage(&Msg);
            DispatchMessage(&Msg);
        }
    }
    
    // Message Queue Procedure
    LRESULT CALLBACK WndProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(Msg)
    	{
    		case WM_CREATE:
    			InitializeMyCommonControls();
    			CreateMyAnimation();
    			break;
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			break;
    		default:
    			return DefWindowProc(hWnd, Msg, wParam, lParam);
    	}
    
    	return 0;
    }
    
    // Animation Control Creation Procedure
    void CreateMyAnimation()
    {
    	hWndAnim = Animate_Create(hWnd, 1, WS_BORDER | WS_CHILD, hInstance);
    }
    
    // Initialization of Common Controls Procedure
    void InitializeMyCommonControls()
    {
    	LPINITCOMMONCONTROLSEX lpInitCommonControlsEx;
    
    	lpInitCommonControlsEx.dwSize = (LPINITCOMMONCONTROLSEX);
    	lpInitCommonControlsEx.dwICC = ICC_ANIMATE_CLASS;
    
    	InitCommonControlsEx(lpInitCommonControlsEx);
    }
    
    // Window Creation Procedure
    void CreateMyWindow()
    {
    	WNDCLASSEX wndClassEx;
    
    	wndClassEx.cbSize = sizeof(WNDCLASSEX);
    	wndClassEx.style = CS_HREDRAW | CS_VREDRAW;
    	wndClassEx.lpfnWndProc = WndProc;
    	wndClassEx.cbClsExtra = 0;
    	wndClassEx.cbWndExtra = 0;
    	wndClassEx.hInstance = hInstance;
    	wndClassEx.hIcon = LoadIcon(NULL, IDI_WINLOGO);
    	wndClassEx.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wndClassEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    	wndClassEx.lpszMenuName = 0;
    	wndClassEx.lpszClassName = szClassName;
    	wndClassEx.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
    
    	RegisterClassEx(&wndClassEx);
    
    	hWnd = CreateWindowEx(0, szClassName, "Animation Control", WS_OVERLAPPEDWINDOW,
    						  CW_USEDEFAULT, CW_USEDEFAULT, WIDTH, HEIGHT, 0, 0, hInstance, 0);
    
    }
    Last edited by ElWhapo; 03-31-2005 at 10:09 AM.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    You also need to include the header file.
    Code:
    #include <COMMCTRL.H>

  7. #7
    Registered User
    Join Date
    Dec 2004
    Posts
    73
    Thanks I got it now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (Multiline) Edit Control Limit
    By P4R4N01D in forum Windows Programming
    Replies: 9
    Last Post: 05-17-2008, 11:56 AM
  2. line number on a rich edit control
    By rakan in forum Windows Programming
    Replies: 1
    Last Post: 02-18-2008, 07:58 AM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  4. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM