Make UI development easy and enjoyable, and use the SONICUI engine to achieve common UI effects

Source: Internet
Author: User
Tags control characters resource

As a Windows engineer, UI development is an unavoidable task, whether you are writing a supply and marketing system, or a chat Im,ui development will always occupy you a lot of time. Some time ago in the company development project, with a bit of selfishness to achieve a concept for a longer time UI engine, since the use of the process feel greatly accelerated the efficiency of UI development, I hope to share with you, and the suggestions to continue to improve.

Next, we will take a few examples of common UI development issues in the actual work, and introduce the implementation methods and effects, and believe that these problems can arouse the sympathy of the client UI development colleagues.

1. Multi-format Picture support

2. Text and hyperlinks

3. Self-painting button

4. Dirty Handling and area Refresh

5. Irregular form (including pixel-level transparent shaped form)

1. Multi-format Picture support

UI development is inseparable from pictures, Windows API provides some ways to load pictures, such as commonly used loadimage, easy to use. But its function is also as simple as its usage, can only load bmp,ico and so on several formats. As we all know, BMP is not with alpha channel, once you need to implement the effect of shadow and other alpha gradients, the system provides a little bit of the API. Of course, many people will think of the famous cximage, which is also a good choice. I am inside is also encapsulated cximage to help load and save the picture, but after loading the image processing is a self processing, because cximage in processing RGB to HSL, rotation and other special effects when a large number of use of floating-point operations, efficiency can not make people very satisfied. I have all the floating-point operations into plastic operations, and a lot of use of SSE2 instructions to optimize, measured in rotation, HSL conversion, ashing and other effects, the efficiency can be increased 4-10 times (CPU for T2330 1.6GHz). Picture loading supports three ways: from file; from resource to DC. What you need to describe is to name the resource type image when loading from a resource.

The demo code is as follows:

//GetSonicUI是引擎导出的唯一函数,是类厂和引擎总控,负责创建对象和销毁对象等。
ISonicImage * pImg = GetSonicUI()->CreateImage();
pImg->Load("C:\\1.png");
pImg->Draw(hdc, 10, 10);
GetSonicUI()->DestroyObject(pImg);

OK, a transparent channel with the PNG picture is finished, it is not easy and comfortable.

2. Text and hyperlinks

UI development process is often the most troublesome is to draw text, you need to constantly initialize the font, set font properties, if the product personnel requirements of the text in a certain format typesetting or output color text, it is our nightmare. And in their own interface to add hyperlinks, the internet has a lot of demo code, but I believe that isonicstring is a simpler implementation. Isonicstring is a UI component object that can be used for message interaction. Just like HTML language to add some similar control characters, you can arbitrarily control the size of the font color, hyperlinks and other properties, very convenient.

ISonicString * pStr = GetSonicUI()->CreateString();
pStr->Format("/c=%x, a='http://hi.csdn.net/zskof', font, font_height=16/点我打开链接", RGB(0, 0, 255));
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
  PAINTSTRUCT ps;
  HDC hdc;
  switch (message)
  {
  case WM_PAINT:
    {
      hdc = BeginPaint(hWnd, &ps);
      pStr->TextOut(hdc, 0, 0, hWnd);
      EndPaint(hWnd, &ps);
    }
    break;
  }
  .
  .
  .
}

How, just create, and then format a string like CString, output in the WM_PAINT response, just three steps, and you get a line of blue full-featured hyperlinks, isn't it convenient. By controlling the characters, you can also set the underline style, the mouse shape, in response to the mouse color and other details, see ISonicUI.h in the comments can be.

Isonicstring can also mix text and pictures to output, or make pictures with hyperlink properties, you need to use the ' P ' control character to specify a Isonicimage ID:

ISonicImage * pImg = GetSonicUI()->CreateImage();
pImg->Load("C:\\1.png");
ISonicString * pStr = GetSonicUI()->CreateString();
pStr->Format("/c=%x/你好吗,朋友/p=%d, a='http://hi.csdn.net/zskof'/", RGB(0, 0, 255), pImg->GetObjectId());

This will be like writing a Web page in your interface for text and pictures of the mixed typesetting output.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.