YOU CAN CODE!

 

With The Case Of UCanCode.net  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Overview
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
Purchase
ActiveX COM Products
Overview
Download
Purchase
Technical Support
  General Q & A
Discussion Board
Contact Us

Links

Get Ready to Unleash the Power of UCanCode .NET

 


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"


VC++ Code: Change the font of window with SetFont and EnumChildWindows and CreateIconFromResource

 
 

Code Snippet

  • This article shows how to change the font for all child windows using only one line with a callback function.

    The idea is to create a callback function that is passed to Win32 API function ::EnumChildWindows(). Somewhere in the application, global CFont object is created. Pointer to this object is passed as a third argument in EnumChildWindows(). This argument is passed to a callback function together with a handle to a child window. Using these 2 arguments, the function changes the font for the child window.

    Using this technique, it is very easy to:

    • Change the font for main frame window, its child views and a status bar from CMainFrame::OnCreate().
    • Change the font for all dialog controls from OnInitDialog().

    The Callback function looks like this:

    Collapse Copy Code
    // lParam is a pointer to CFont object
    BOOL __stdcall SetChildFont(HWND hwnd, LPARAM lparam)
    {
       CFont *pFont = (CFont*)lparam;
       CWnd *pWnd = CWnd::FromHandle(hwnd);
       pWnd->SetFont(pFont);
       return TRUE;
    }

    This callback function is used from OnCreate() or OnInitDialog() in the following way:

    Collapse Copy Code
    ...
    // g_Font is an object of type CFont or derived from CFont
    EnumChildWindows(m_hWnd, ::SetChildFont, &g_Font);
    ...
     
    Load cursor from resource:
    //
    // LoadAnimatedCursor: Loads an animated gif from the resource as an cursor
    //
    HCURSOR LoadAniCursor(UINT nID)
    {
    	HINSTANCE hInst=AfxGetInstanceHandle();
    	HRSRC hRes=FindResource(hInst,MAKEINTRESOURCE(nID),"ANICURSORS");
    	DWORD dwSize=SizeofResource(hInst, hRes);
    	HGLOBAL hGlob=LoadResource(hInst, hRes);
    	LPBYTE pBytes=(LPBYTE)LockResource(hGlob); 
    	return (HCURSOR)CreateIconFromResource(pBytes,dwSize,FALSE,0x00030000);
    }
    
  •  

     

    Copyright ?1998-2024 UCanCode.Net Software , all rights reserved.
    Other product and company names herein may be the trademarks of their respective owners.

    Please direct your questions or comments to webmaster@ucancode.net