Manifest

Manifest slúži k získaniu štýlu vzhľadu systému (XP/Vista/7).

1.možnosť:
za includované súbory vložme:

#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")

2.možnosť:
-v hlavnom adresári projektu (pri súboroch *.vcproj, *.cpp, *.h) vytvoríme súbor s názvom aplikácie.exe.manifest (napr.: program.exe.manifest) a do neho vložíme :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> 
<assemblyIdentity 
version="1.0.0.0" 
processorArchitecture="X86" 
name="Nejake meno"
type="win32" 
/> 
<description>Nejaky nazov</description> 
<dependency> 
<dependentAssembly> 
<assemblyIdentity 
type="win32" 
name="Microsoft.Windows.Common-Controls" 
version="6.0.0.0" 
processorArchitecture="X86" 
publicKeyToken="6595b64144ccf1df" 
language="*" 
/> 
</dependentAssembly> 
</dependency> 
</assembly> 

-Project -> Add existing item a pridáme tento súbor do projektu
-V InitApp() použijeme na začiatku funkciu InitCommonControlsEx

INITCOMMONCONTROLSEX icc;
icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
icc.dwICC = ICC_WIN95_CLASSES;
if ( !InitCommonControlsEx(&icc) )
  return FALSE; 

-do hlavičkového súboru (*.h) pridáme

#include <commctrl.h> 

-do projektu pridáme knižnicu comctl32.lib, ktorá je súčasťou balíka Windows SDK ( Project -> Add existing item )

3.možnosť
Vyššie uvedené XML distribuujeme spoločne s aplikáciou - XML súbor musí mať rovnaký názok ako aplikácia+.exe.manifest (napr.: program.exe.manifest)

--------------------------------------------------------
Ukážka druhej možnosti:
main.h

#include <windows.h>
#include <commctrl.h> 

main.cpp

#include "main.h"

#define _MainClassName TEXT("WinAPIMainClass")
#define _AppName TEXT("Manifest")


HINSTANCE g_hInstance;
HWND g_hwndMain;
HWND g_hwndButton1;

LRESULT CALLBACK WindowProcMain(HWND hwnd, UINT uMsg, WPARAM wParam, 
                  LPARAM lParam)
{
  switch ( uMsg )
  {
    case WM_DESTROY:
      PostQuitMessage(0);
      break;
  }
  return DefWindowProc(hwnd, uMsg, wParam, lParam);
}

BOOL InitApp()
{
	INITCOMMONCONTROLSEX icc;
icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
icc.dwICC = ICC_WIN95_CLASSES;
if ( !InitCommonControlsEx(&icc) )
  return FALSE;

  WNDCLASSEX wc;
  wc.cbSize = sizeof(WNDCLASSEX);
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  wc.hInstance = g_hInstance;
  wc.lpfnWndProc = WindowProcMain;
  wc.lpszClassName = _MainClassName;
  wc.lpszMenuName = NULL;
  wc.style = CS_HREDRAW | CS_VREDRAW;
  if ( !RegisterClassEx(&wc) )
    return FALSE;

  g_hwndMain = CreateWindowEx(0, _MainClassName,
    _AppName,
    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    100, 100, 450, 350,
    NULL, NULL, g_hInstance, NULL);
  if ( g_hwndMain == NULL )
    return FALSE;

  g_hwndButton1 = CreateWindowEx(0,
    TEXT("BUTTON"),
    TEXT("Button1"),
    WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
    10, 10, 75, 25,
    g_hwndMain,
    (HMENU)NULL,
    g_hInstance,
    NULL);
if ( g_hwndButton1 == NULL )
    return FALSE;

HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
SendMessage(g_hwndButton1, WM_SETFONT, (WPARAM)hFont, (LPARAM)TRUE);

  return TRUE;
}

MSG msg;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst, 
                    LPSTR lpCmdLine, int nShow)
{
  if ( !InitApp() )
    return FALSE;
  g_hInstance = hInstance;
  while ( GetMessage(&msg, NULL, 0, 0) )
  {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  return msg.wParam;
} 

Leave a Reply