Windows Mobile 6.5 控件风格(listview,menu,

Windows Mobile 6.5 控件风格

引:在做Windows Mobile 6.5自绘listview时,当菜单选中时,为达到与WM6.5统一的风格,在文档中没有找到相应绘制listview 选中状态的函数。通过分析,绘制函数必定在coredll中,查找coredll.def文件,发现三个函数。

关于设置默认listview控件的方法见如下:

The secret is in the extended style LVS_EX_THEME that needs to be applied to a ListView. It could be done by sending LVM_SETEXTENDEDLISTVIEWSTYLE to the control. I've wrapped appropriate P/Invoke calls in the following extention method:

 const int LVS_EX_THEME = 0x02000000;

/// <summary>

/// Sets theme style to a listview

/// </summary>

/// <param name="listView">ListView instance</param>

public static void SetThemeStyle(this ListView listView)

{

     // Retreive the current extended style

     int currentStyle = SendMessage(listView.Handle,

                                  (uint)LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);

     // Assign the LVS_EX_THEM style

     SendMessage(listView.Handle, (uint)LVM_SETEXTENDEDLISTVIEWSTYLE, 0,

currentStyle | LVS_EX_THEME);

           

}

But wait there's more... While looking up the values for the P/Invoke messages in the commctrl.h, my eyes cought the forgotten LVM_SETBKIMAGE message which could be used to assign a background image to a ListView. This is how another extention method would look like:

/// <summary>

/// Sets background image to a listview

/// </summary>

/// <param name="listView">ListView instance.</param>

/// <param name="path">string path to an image.</param>

public static void SetBackgroundImage(this ListView listView, string path)

{

      // Create bitmap

      Bitmap bitmap = new Bitmap(path);

      // Retrieve HBITMAP

      IntPtr hBitmap = bitmap.GetHbitmap();

      // Dispose the managed bitmap

      bitmap.Dispose();

      // Prepare structure

      LVBKIMAGE lvImage = new LVBKIMAGE();

      lvImage.hbm = hBitmap;

      lvImage.ulFlags = LVBKIF_SOURCE_HBITMAP;

      // Assign an image

      SendMessage(listView.Handle, LVM_SETBKIMAGE, 0, ref lvImage);

 

 }

UpdateThemePrimitives

DrawThemePrimitive

ThemePrimitiveExists

使用方法很简单,见头文件。

typedef enum tagThemePrimitiveType
{
 ThemePrimitive_Invalid = -1,
 ThemePrimitive_Bubble_Border,
 ThemePrimitive_Bubble_Title,
 ThemePrimitive_ListView_Selector,
 ThemePrimitive_Menu_Border,
 ThemePrimitive_Menu_UpArrowBackground,
 ThemePrimitive_Menu_UpArrow,
 ThemePrimitive_Menu_UpArrowDisabled,
 ThemePrimitive_Menu_DownArrowBackground,
 ThemePrimitive_Menu_DownArrow,
 ThemePrimitive_Menu_DownArrowDisabled,
 ThemePrimitive_Menu_Selector,
 ThemePrimitive_MessageBox_Border,
 ThemePrimitive_MessageBox_Caption,
 ThemePrimitive_ScrollBar_Vertical_Track,
 ThemePrimitive_ScrollBar_Vertical_Thumb,
 ThemePrimitive_ScrollBar_Vertical_UpArrowButton,
 ThemePrimitive_ScrollBar_Vertical_UpArrowButtonSelected,
 ThemePrimitive_ScrollBar_Vertical_UpArrowButtonDisabled,
 ThemePrimitive_ScrollBar_Vertical_DownArrowButton,
 ThemePrimitive_ScrollBar_Vertical_DownArrowButtonSelected,
 ThemePrimitive_ScrollBar_Vertical_DownArrowButtonDisabled,
 ThemePrimitive_ScrollBar_Horizontal_Track,
 ThemePrimitive_ScrollBar_Horizontal_Thumb,
 ThemePrimitive_ScrollBar_Horizontal_LeftArrowButton,
 ThemePrimitive_ScrollBar_Horizontal_LeftArrowButtonSelected,
 ThemePrimitive_ScrollBar_Horizontal_LeftArrowButtonDisabled,
 ThemePrimitive_ScrollBar_Horizontal_RightArrowButton,
 ThemePrimitive_ScrollBar_Horizontal_RightArrowButtonSelected,
 ThemePrimitive_ScrollBar_Horizontal_RightArrowButtonDisabled,
 ThemePrimitive_SoftKeyBar_Background,
 ThemePrimitive_SoftKeyBar_SoftKeyHighlight,
 ThemePrimitive_SoftKeyBar_SipHighlight,
 ThemePrimitive_TabView_Edge,
 ThemePrimitive_TabView_Edge_Shadow,
 ThemePrimitive_TaskBar_Background,
 ThemePrimitive_TaskBar_Highlight,
 ThemePrimitive_Toast_Border,
 ThemePrimitive_Toast_Title,
 ThemePrimitive_Toast_LeftArrowSpinner,
 ThemePrimitive_Toast_RightArrowSpinner,
 ThemePrimitive_UpDownControl_LeftArrowButton,
 ThemePrimitive_UpDownControl_LeftArrowButtonSelected,
 ThemePrimitive_UpDownControl_RightArrowButton,
 ThemePrimitive_UpDownControl_RightArrowButtonSelected,
 ThemePrimitive_UpDownControl_UpArrowButton,
 ThemePrimitive_UpDownControl_UpArrowButtonSelected,
 ThemePrimitive_UpDownControl_DownArrowButton,
 ThemePrimitive_UpDownControl_DownArrowButtonSelected,
 ThemePrimitive_Count
} THEMEPRIMITIVETYPE;

/*
* Theme primitive APIs
*/

// Updates all the theme primitives
WINUSERAPI
void
WINAPI
UpdateThemePrimitives(
       void
       );

// Draw a theme primitive (specified by its index) into a specified RECT area of a DC
// Note: if the DC passed in is NULL, this method fills bitmap rect info to  prc, then
// return TRUE.
WINUSERAPI
BOOL
WINAPI
DrawThemePrimitive(
       THEMEPRIMITIVETYPE tpt,
       HDC hdc,
       LPRECT prc
       );

// Returns TRUE if the theme primitive (specified by its index) exists and is enabled.
// A theme primitive exists if it has a non-zero HDC. Theme primitives are disabled if
// layered windows are disabled.
WINUSERAPI
BOOL
WINAPI
ThemePrimitiveExists(
      THEMEPRIMITIVETYPE tpt
      );

由于没有提供相应的lib,需要GetProcAddress来得到函数地址

typedef void (* PUpdateThemePrimitives)(void);
typedef BOOL (* PDrawThemePrimitive)(THEMEPRIMITIVETYPE tpt, HDC hdc, LPRECT prc);
typedef BOOL (* PThemePrimitiveExists)(THEMEPRIMITIVETYPE tpt);

PUpdateThemePrimitives fnUpdateThemePrimitives = NULL;
PDrawThemePrimitive fnDrawThemePrimitive = NULL;
PThemePrimitiveExists fnThemePrimitiveExists = NULL;

// Updates all the theme primitives
WINUSERAPI
void
WINAPI
UpdateThemePrimitives(
       void
       )
{
 if(!fnUpdateThemePrimitives)
 {
  HINSTANCE hDll = LoadLibrary(L"coredll.dll");
  fnUpdateThemePrimitives = (PUpdateThemePrimitives)GetProcAddress(hDll, MAKEINTRESOURCE(2720));
  FreeLibrary(hDll);
 }
 
 if(fnUpdateThemePrimitives)
  fnUpdateThemePrimitives();
}

// Draw a theme primitive (specified by its index) into a specified RECT area of a DC
// Note: if the DC passed in is NULL, this method fills bitmap rect info to  prc, then
// return TRUE.
WINUSERAPI
BOOL
WINAPI
DrawThemePrimitive(
       THEMEPRIMITIVETYPE tpt,
       HDC hdc,
       LPRECT prc
       )
{
 if(!fnDrawThemePrimitive)
 {
  HINSTANCE hDll = LoadLibrary(L"coredll.dll");
  fnDrawThemePrimitive = (PDrawThemePrimitive)GetProcAddress(hDll, MAKEINTRESOURCE(2718));
  FreeLibrary(hDll);
 }
 if(fnDrawThemePrimitive)
  return fnDrawThemePrimitive(tpt, hdc, prc);
 return FALSE;
}

// Returns TRUE if the theme primitive (specified by its index) exists and is enabled.
// A theme primitive exists if it has a non-zero HDC. Theme primitives are disabled if
// layered windows are disabled.
WINUSERAPI
BOOL
WINAPI
ThemePrimitiveExists(
      THEMEPRIMITIVETYPE tpt
      )
{
 if(!fnThemePrimitiveExists)
 {
  HINSTANCE hDll = LoadLibrary(L"coredll.dll");
  fnThemePrimitiveExists = (PThemePrimitiveExists)GetProcAddress(hDll, MAKEINTRESOURCE(2718));
  FreeLibrary(hDll);
 }
 if(fnThemePrimitiveExists)
  return fnThemePrimitiveExists(tpt);
 return FALSE;
}

你可能感兴趣的:(windows,ListView,mobile,border,menu,Primitive)