⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 复件 (3) 新建 文本文档 (2).txt

📁 金融证券行业用的网络递交业务程序
💻 TXT
📖 第 1 页 / 共 5 页
字号:
GRAYS1.C
        
/*---------------------------------------------------------------------------
        
  GRAYS1.C --   Gray Shades
        
                                                         (c) Charles Petzold, 1998
        
-----------------------------------------------------------------------------*/
        
#include <windows.h>
        
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
        
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
        
                          PSTR szCmdLine, int iCmdShow)
        
{
        
           static TCHAR szAppName[] = TEXT ("Grays1") ;
        
           HWND                          hwnd ;
        
           MSG                           msg ;
        
           WNDCLASS                      wndclass ;
        

           wndclass.style                               = CS_HREDRAW | CS_VREDRAW ;
        
           wndclass.lpfnWndProc                         = WndProc ;
        
           wndclass.cbClsExtra                          = 0 ;
        
           wndclass.cbWndExtra                          = 0 ;
        
           wndclass.hInstance                           =      hInstance ;
        
           wndclass.hIcon                              =      LoadIcon (NULL, IDI_APPLICATION) ;
        
           wndclass.hCursor                             =      LoadCursor (NULL, IDC_ARROW) ;
        
           wndclass.hbrBackground               =      (HBRUSH) GetStockObject (WHITE_BRUSH) ;
        
          wndclass.lpszMenuName                =      NULL ;
        
           wndclass.lpszClassName               =      szAppName ;
        

           if (!RegisterClass (&wndclass))
        
           {
        
                          MessageBox (  NULL, TEXT ("This program requires Windows NT!"),
        
                                         szAppName, MB_ICONERROR) ;
        
                        return 0 ;
        
           }
        
   
        
           hwnd = CreateWindow (szAppName, TEXT ("Shades of Gray #1"),
        
                              WS_OVERLAPPEDWINDOW,
        
                           CW_USEDEFAULT, CW_USEDEFAULT,
        
                           CW_USEDEFAULT, CW_USEDEFAULT,           
        
                          NULL, NULL, hInstance, NULL) ;
        
   
        
           ShowWindow (hwnd, iCmdShow) ;
        
           UpdateWindow (hwnd) ;
        
   
        
           while (GetMessage (&msg, NULL, 0, 0))
        
           {
        
                          TranslateMessage (&msg) ;
        
                          DispatchMessage (&msg) ;
        
         }
        
           return msg.wParam ;
        
}
        

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam)
        
{
        
           static int            cxClient, cyClient ;
        
           HBRUSH                hBrush ;
        
           HDC                   hdc ;
        
           int                   i ;
        
           PAINTSTRUCT           ps ;
        
          RECT                  rect ;
        
   
        
           switch (message)
        
           {
        
           case   WM_SIZE:
        
                          cxClient = LOWORD (lParam) ;
        
                          cyClient = HIWORD (lParam) ;
        
                          return 0 ;
        
        
        
           case   WM_PAINT:
        
                          hdc = BeginPaint (hwnd, &ps) ;
        

                                                // Draw the fountain of grays
        

                          for (i = 0 ; i < 65 ; i++)
        
                          {
        
                                                 rect.left             = i * cxClient / 65 ;
        
                                                 rect.top              = 0 ;
        
                                                 rect.right            = (i + 1) * cxClient / 65 ;
        
                                                 rect.bottom           = cyClient ;
        

                                  hBrush = CreateSolidBrush (RGB(min (255, 4 * i),    
        
                                                          min (255, 4 * i),
        
                                                          min (255, 4 * i))) ;
        
                                                 FillRect (hdc, &rect, hBrush) ;
        
                                                 DeleteObject (hBrush) ;
        
                         }
        
                          EndPaint (hwnd, &ps) ;
        
                          return 0 ;
        

           case   WM_DESTROY:
        
                          PostQuitMessage (0) ;
        
                          return 0 ;
        
           }
        
           return DefWindowProc (hwnd, message, wParam, lParam) ;
        
}
        
在WM_PAINT消息处理期间,程序呼叫了65次FillRect函数,每次都使用不同灰阶建立的画刷。灰阶值是RGB值(0,0,0)、(4,4,4)、(8,8,8)等等,直到最后一个值(255,255,255)。最后一个值来自CreateSolidBrush函数中的min宏。

如果在256色显示模式下执行该程序,您将看到从黑到白的65种灰阶,而且它们几乎都用混色着色。纯颜色只有黑色、暗灰色(128,128,128)、亮灰色(192,192,192)和白色。其它颜色是混合了这些纯颜色的多位模式。如果我们在显示行或文字,而不是用这65种灰阶填充区域,Windows将不使用混色而只使用这四种纯色。如果我们正在显示位图,则图像将用20种标准Windows颜色近似。这时正如同您在执行最后一章中的程序的同时又加载了彩色或灰阶DIB所见到的一样。通常,Windows在位图中不使用混色。

程序16-2所示的GRAYS2程序用较少的外部程序代码验证了调色盘管理器中最重要的函数和消息。

程序16-2 GRAYS2 
        
GRAYS2.C
        
/*---------------------------------------------------------------------------
        
  GRAYS2.C --   Gray Shades Using Palette Manager
        
                                                        (c) Charles Petzold, 1998
        
-----------------------------------------------------------------------------*/
        
#include <windows.h>
        
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
        
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
        
                                                                PSTR szCmdLine, int iCmdShow)
        
{
        
           static TCHAR szAppName[] = TEXT ("Grays2") ;
        
           HWND                          hwnd ;
        
           MSG                           msg ;
        
           WNDCLASS                      wndclass ;
        

           wndclass.style                               = CS_HREDRAW | CS_VREDRAW ;
        
           wndclass.lpfnWndProc                         = WndProc ;
        
           wndclass.cbClsExtra                          = 0 ;
        
           wndclass.cbWndExtra                          = 0 ;
        
           wndclass.hInstance                           = hInstance ;
        
           wndclass.hIcon                               = LoadIcon (NULL, IDI_APPLICATION) ;
        
           wndclass.hCursor                             = LoadCursor (NULL, IDC_ARROW) ;
        
           wndclass.hbrBackground              = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
        
           wndclass.lpszMenuName                = NULL ;
        
           wndclass.lpszClassName               = szAppName ;
        

           if     (!     RegisterClass (&wndclass))
        
           {
        
                          MessageBox (  NULL, TEXT ("This program requires Windows NT!"),
        
                                         szAppName, MB_ICONERROR) ;
        
                   return 0 ;
        
           }
        
   
        
           hwnd = CreateWindow ( szAppName, TEXT ("Shades of Gray #2"),
        
                                 WS_OVERLAPPEDWINDOW,
        
                                  CW_USEDEFAULT, CW_USEDEFAULT,
        
                                  CW_USEDEFAULT, CW_USEDEFAULT,           
        
                                  NULL, NULL, hInstance, NULL) ;
        
   
        
           ShowWindow (hwnd, iCmdShow) ;
        
           UpdateWindow (hwnd) ;
        
           while (GetMessage (&msg, NULL, 0, 0))
        
           {
        
                          TranslateMessage (&msg) ;
        
                          DispatchMessage (&msg) ;
        
           }
        
           return msg.wParam ;
        
}
        

LRESULT CALLBACK WndProc ( HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam)
        
{
        
           static HPALETTE               hPalette ;
        
           static int                    cxClient, cyClient ;
        
           HBRUSH                        hBrush ;
        
           HDC                           hdc ;
        
           int                           i ;
        
           LOGPALETTE                    *      plp ;
        
           PAINTSTRUCT                   ps ;
        
           RECT                          rect ;
        
   
        
           switch (message)
        
           {
        
           case   WM_CREATE:
        
                                         // Set up a LOGPALETTE structure and create a palette
        

                          plp = malloc (sizeof (LOGPALETTE) + 64 * sizeof (PALETTEENTRY)) ;
        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -