Programming Windows

Drawing Dots and Lines

x(t) = (1 - t)3 x0 + 3t (1 - t)2 x1 + 3t2 (1 - t) x2 + t3 x3

y(t) = (1 - t)3 y0 + 3t (1 - t)2 y1 + 3t2 (1 - t) y2 + t3 y3

Drawing Filled Areas

Alternate and Winding modes

At first, the difference between alternate and winding modes seems rather simple. For alternate mode, you can imagine a line drawn from a point in an enclosed area to infinity. The enclosed area is filled only if that imaginary line crosses an odd number of boundary lines. This is why the points of the star are filled but the center is not.

The example of the five-pointed star makes winding mode seem simpler than it actually is. When you're drawing a single polygon, in most cases winding mode will cause all enclosed areas to be filled. But there are exceptions.

To determine whether an enclosed area is filled in winding mode, you again imagine a line drawn from a point in that area to infinity. If the imaginary line crosses an odd number of boundary lines, the area is filled, just as in alternate mode. If the imaginary line crosses an even number of boundary lines, the area can either be filled or not filled. The area is filled if the number of boundary lines going in one direction (relative to the imaginary line) is not equal to the number of boundary lines going in the other direction. 

viewport & window

The GDI Mapping Mode

The viewport is specified in terms of device coordinates (pixels). Most often the viewport is the same as the client area, but it can also refer to whole-window coordinates or screen coordinates if you've obtained a device context from GetWindowDC or CreateDC . The point (0, 0) is the upper left corner of the client area (or the whole window or the screen). Values of x increase to the right, and values of y increase going down.

The window is specified in terms of logical coordinates, which might be pixels, millimeters, inches, or any other unit you want. You specify logical window coordinates in the GDI drawing functions.

keystroke

The six keystroke-message fields of the lParam variable:
31 30 29 28 27 26 25 24 23 ... 16 15 ... 00
31 : Transition State
30 : Previous Key State
29 : Context Code
24 : Extended Key Flag
16 - 23 : 8-Bit OEM Scan Code
00 - 15 : 16-Bit Repeat Count

WM_TIMER

void RotatePoint (POINT pt[], int iNum, int iAngle)
{
     int   i ;
     POINT ptTemp ;
    
     for (i = 0 ; i < iNum ; i++)
     {
          ptTemp.x = (int) (pt[i].x * cos (TWOPI * iAngle / 360) +
               pt[i].y * sin (TWOPI * iAngle / 360)) ;
         
          ptTemp.y = (int) (pt[i].y * cos (TWOPI * iAngle / 360) -
               pt[i].x * sin (TWOPI * iAngle / 360)) ;
         
          pt[i] = ptTemp ;
     }
}

Using the Timer for a Clock

x' = x * cos (a) + y * sin (a)

y' = y * cos (a) - x * sin (a)

CreateIC

// Invert the rectangle if the button is selected
if (pdis->itemState & ODS_SELECTED)
    InvertRect (pdis->hDC, &pdis->rcItem) ;

Resource
Icons, Cursors, Strings, and Custom ResourceshIcon = LoadIcon (hInstance, MAKEINTRESOURCE (125)) ;
The obscure method is this:
hIcon = LoadIcon (hInstance, TEXT ("#125")) ;
Windows recognizes the initial # character as prefacing a number in ASCII form.
ID numbers you use to add commands to the system menu must be lower than 0xF000
MapDialogRect
wndclass.cbWndExtra = DLGWINDOWEXTRA ; // Note!

Clipboard

GMEM_MOVEABLE flag allows Windows to move a memory block in virtual memory. This doesn't necessarily mean that the memory block will be moved in physical memory, but the address that the application uses to read and write to the block can change. Like the relation between Handle & Pointer
OpenClipboard (hwnd) ;
EmptyClipboard () ;
SetClipboardData (CF_TEXT, hGlobalText) ;
SetClipboardData (CF_BITMAP, hBitmap) ;
SetClipboardData (CF_METAFILEPICT, hGlobalMFP) ;
CloseClipboard () ;
Delayed Rendering
After you call SetClipboardData , don't continue to use the memory block. It no longer belongs to your program, and you should treat the handle as invalid.
Delayed Rendering
OpenClipboard (hwnd) ;
EmptyClipboard () ;
SetClipboardData (iFormat, NULL) ;
CloseClipboard () ;

WM_RENDERFORMAT , WM_RENDERALLFORMATS ( used when terminate), and WM_DESTROYCLIPBOARD
case WM_RENDERALLFORMATS :
     OpenClipboard (hwnd) ;
     EmptyClipboard () ;
                              // fall through
case WM_RENDERFORMAT :
     [put text into global memory block]
     SetClipboardData (CF_TEXT, hGlobal) ;

     if (message == WM_RENDERALLFORMATS)
          CloseClipboard () ;
     return 0 ;
delayed rendering must process three messages in its window procedure: WM_RENDERFORMAT, WM_RENDERALLFORMATS, and WM_DESTROYCLIPBOARD. Windows sends your window procedure a WM_RENDERFORMAT message when another program calls GetClipboardData . The value of wParam is the format requested. When you process the WM_RENDERFORMAT message, don't open and empty the clipboard. Simply create a global memory block for the format given by wParam , transfer the data to it, and call SetClipboardData with the correct format and the global handle. Obviously, you'll need to retain information in your program to construct this data properly when processing WM_RENDERFORMAT. When another program calls EmptyClipboard , Windows sends your program a WM_DESTROYCLIPBOARD message. This tells you that the information to construct the clipboard data is no longer needed. You are no longer the clipboard owner.  WM_RENDERALLFORMATS message is one of the last messages your window procedure receives
Private Data Formats
The easiest involves data that is ostensibly in one of the standard clipboard formats (that is, text, bitmap, or metafile)
The second way to use private formats involves the CF_OWNERDISPLAY flag.
The third way to use private clipboard data formats is to register your own clipboard format name.
WM_DRAWCLIPBOARD and WM_PAINTCLIPBOARD messages. The WM_PAINTCLIPBOARD message is sent by a clipboard viewer to programs that use the CF_OWNERDISPLAY clipboard format. The WM_ DRAWCLIPBOARD message is sent by Windows to the current clipboard viewer
ChangeClipboardChain (hwnd, hwndNextViewer) ;

PATPAINT
The PATPAINT raster operation involves a more complex operation. The result is equal to a bitwise OR operation between the pattern, the destination, and the inverse of the source.
The 15 ROP codes that have names are shown here.

Pattern (P): 1 1 1 1 0 0 0 0


Source (S): 1 1 0 0 1 1 0 0


Destination (D): 1 0 1 0 1 0 1 0 Boolean Operation ROP Code Name
Result:0 0 0 0 0 0 0 000x000042BLACKNESS

0 0 0 1 0 0 0 1~ (S ¦ D)0x1100A6NOTSRCERASE

0 0 1 1 0 0 1 1~S0x330008NOTSRCCOPY

0 1 0 0 0 1 0 0S & ~D0x440328SRCERASE

0 1 0 1 0 1 0 1~D0x550009DSTINVERT

0 1 0 1 1 0 1 0P ^ D0x5A0049PATINVERT

0 1 1 0 0 1 1 0S ^ D0x660046SRCINVERT

1 0 0 0 1 0 0 0S & D0x8800C6SRCAND

1 0 1 1 1 0 1 1~S ¦ D0xBB0226MERGEPAINT

1 1 0 0 0 0 0 0P & S0xC000CAMERGECOPY

1 1 0 0 1 1 0 0S0xCC0020SRCCOPY

1 1 1 0 1 1 1 0S ¦ D0xEE0086SRCPAINT

1 1 1 1 0 0 0 0P0xF00021PATCOPY

1 1 1 1 1 0 1 1P ¦ ~S ¦ D0xFB0A09PATPAINT

1 1 1 1 1 1 1 110xFF0062WHITENESS

PatBlt
Besides BitBlt and StretchBlt , Windows also includes a function called PatBlt ("pattern block transfer"). This is the simplest of the three "blt" functions. Unlike BitBlt and StretchBlt , it uses only a destination device context.

Pattern (P): 1 1 0 0


Destination (D): 1 0 1 0 Boolean Operation ROP Code Name
Result:0 0 0 000x000042BLACKNESS

0 0 0 1~(P ¦ D)0x0500A9

0 0 1 0~P & D0x0A0329

0 0 1 1~P0x0F0001

0 1 0 0P & ~D0x500325

0 1 0 1~D0x550009DSTINVERT

0 1 1 0P ^ D0x5A0049PATINVERT

0 1 1 1~(P & D)0x5F00E9

1 0 0 0P & D0xA000C9

1 0 0 1~(P ^ D)0xA50065

1 0 1 0D0xAA0029

1 0 1 1~P ¦ D0xAF0229

1 1 0 0P 0xF00021PATCOPY

1 1 0 1P ¦ ~D0xF50225

1 1 1 0P ¦ D0xFA0089

1 1 1 110xFF0062WHITENESS

DDB
iWidthBytes = (cx * cBitsPixel + 15) & ~15) >> 3 ;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
内容简介   《MFC Windows程序设计(第2版)》是对其极为经典的第1版的全面更新,本书不仅扩展了已被认为是权威的关于Microsoft用于Windows API的功能强大的C++类库的阐述,还新增了有关COM、OLE和ActiveX的内容。本书的作者,Jeff Prosise,用其无与伦比的技巧向读者讲述了MFC程序设计中的基本概念和主要技术——再次阐释了在32位Windows平台上进行了快速的面向对象开发的完美方法。   本书涵盖了以下专题:   事件驱动程序设计和MPC的基础知识   文档/视图体系结构   位图、调色板和区域   多线程和线程同步   MFC与组件对象模型(COM)   ActiveX控件 作者简介   Jeff Prosise是一位作者、教员和讲师,他以Windows编程和教授别人如何进行Windows为生。作为一位在Windows程序设计、MFC和COM领域世界知名的权威,他还是《PC Magazinge》和《Microsoft Systems Journal》杂志的组稿编辑。 目录   序言   第Ⅰ部分 Windows和MFC基础   第1章 Hello,MFC   第2章 在窗口中绘图   第3章 鼠标和键盘   第4章 菜单   第5章 MFC集合数   第6章 文件I/O和串行化   第7章 控件   第8章 对话框和属性表   第Ⅱ部分 文档/视图体系结构   第9章 文档、视图和单文档界面   第10章 滚动视图、HTML视图以及其他视图类型   第11章 多文档和多视图   第12章 工具栏、状态栏和组合栏   第13章 打印和打印预览   第Ⅲ部分 高级篇   第14章 计时器和空闲处理   第15章 位图、调色板以及区域   第16章 公用控件   第17章 线程和线程同步化   第Ⅳ部分 COM,OLE和ActiveX   第18章 MFC和组件对象模型   第19章 剪贴板和OLE拖放   第20章 Automation   第21章 ActiveX控件

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值