&与&& C语言

&是一个位运算符,就是将两个二进制的数逐位相与,就是都是1才是1,只要有一个为0则为0,结果是相与之后的结果。&&是一个逻辑运算符,就是判断两个表达式的真假性,只有两个表达式同时为真才为真,有一个为假则为假,具有短路性质。

  1 /*-------------------------------------------------
  2    CHECKER4.C -- Mouse Hit-Test Demo Program No. 4
  3                  (c) Charles Petzold, 1998
  4   -------------------------------------------------*/
  5
  6 #include <windows.h>
  7
  8 #define DIVISIONS 5
  9
 10 LRESULT CALLBACK WndProc   (HWND, UINT, WPARAM, LPARAM) ;
 11 LRESULT CALLBACK ChildWndProc (HWND, UINT, WPARAM, LPARAM) ;
 12
 13 int   idFocus = 0 ;
 14 TCHAR szChildClass[] = TEXT ("Checker4_Child") ;
 15
 16 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
 17                     PSTR szCmdLine, int iCmdShow)
 18 {
 19      static TCHAR szAppName[] = TEXT ("Checker4") ;
 20      HWND         hwnd ;
 21      MSG          msg ;
 22      WNDCLASS     wndclass ;
 23
 24      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
 25      wndclass.lpfnWndProc   = WndProc ;
 26      wndclass.cbClsExtra    = 0 ;
 27      wndclass.cbWndExtra    = 0 ;
 28      wndclass.hInstance     = hInstance ;
 29      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
 30      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
 31      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
 32      wndclass.lpszMenuName  = NULL ;
 33      wndclass.lpszClassName = szAppName ;
 34
 35      if (!RegisterClass (&wndclass))
 36      {
 37           MessageBox (NULL, TEXT ("Program requires Windows NT!"),
 38                       szAppName, MB_ICONERROR) ;
 39           return 0 ;
 40      }
 41
 42      wndclass.lpfnWndProc   = ChildWndProc ;
 43      wndclass.cbWndExtra    = sizeof (long) ;
 44      wndclass.hIcon         = NULL ;
 45      wndclass.lpszClassName = szChildClass ;
 46
 47      RegisterClass (&wndclass) ;
 48
 49      hwnd = CreateWindow (szAppName, TEXT ("Checker4 Mouse Hit-Test Demo"),
 50                           WS_OVERLAPPEDWINDOW,
 51                           CW_USEDEFAULT, CW_USEDEFAULT,
 52                           CW_USEDEFAULT, CW_USEDEFAULT,
 53                           NULL, NULL, hInstance, NULL) ;
 54
 55      ShowWindow (hwnd, iCmdShow) ;
 56      UpdateWindow (hwnd) ;
 57
 58      while (GetMessage (&msg, NULL, 0, 0))
 59      {
 60           TranslateMessage (&msg) ;
 61           DispatchMessage (&msg) ;
 62      }
 63      return msg.wParam ;
 64 }
 65
 66 LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 67 {
 68      static HWND hwndChild[DIVISIONS][DIVISIONS] ;
 69      int         cxBlock, cyBlock, x, y ;
 70
 71      switch (message)
 72      {
 73      case WM_CREATE :
 74           for (x = 0 ; x < DIVISIONS ; x++)
 75                for (y = 0 ; y < DIVISIONS ; y++)
 76                     hwndChild[x][y] = CreateWindow (szChildClass, NULL,
 77                               WS_CHILDWINDOW | WS_VISIBLE,
 78                               0, 0, 0, 0,
 79                               hwnd, (HMENU) (y << 8 | x),
 80                               (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE),
 81                               NULL) ;
 82           return 0 ;
 83
 84      case WM_SIZE :
 85           cxBlock = LOWORD (lParam) / DIVISIONS ;
 86           cyBlock = HIWORD (lParam) / DIVISIONS ;
 87
 88           for (x = 0 ; x < DIVISIONS ; x++)
 89                 for (y = 0 ; y < DIVISIONS ; y++)
 90                     MoveWindow (hwndChild[x][y],
 91                                 x * cxBlock, y * cyBlock,
 92                                 cxBlock, cyBlock, TRUE) ;
 93           return 0 ;
 94
 95      case WM_LBUTTONDOWN :
 96           MessageBeep (0) ;
 97           return 0 ;
 98
 99           // On set-focus message, set focus to child window
100
101      case WM_SETFOCUS:
102           SetFocus (GetDlgItem (hwnd, idFocus)) ;
103           return 0 ;
104
105           // On key-down message, possibly change the focus window
106
107      case WM_KEYDOWN:
108           x = idFocus & 0xFF ;
109           y = idFocus >> 8 ;
110
111           switch (wParam)
112           {
113           case VK_UP:    y-- ;                    break ;
114           case VK_DOWN:  y++ ;                    break ;
115           case VK_LEFT:  x-- ;                    break ;
116           case VK_RIGHT: x++ ;                    break ;
117           case VK_HOME:  x = y = 0 ;              break ;
118           case VK_END:   x = y = DIVISIONS - 1 ;  break ;
119           default:       return 0 ;
120           }
121
122           x = (x + DIVISIONS) % DIVISIONS ;
123           y = (y + DIVISIONS) % DIVISIONS ;
124
125           idFocus = y << 8 | x ;
126
127           SetFocus (GetDlgItem (hwnd, idFocus)) ;
128           return 0 ;
129
130      case WM_DESTROY :
131           PostQuitMessage (0) ;
132           return 0 ;
133      }
134      return DefWindowProc (hwnd, message, wParam, lParam) ;
135 }
136
137 LRESULT CALLBACK ChildWndProc (HWND hwnd, UINT message,
138                                WPARAM wParam, LPARAM lParam)
139 {
140      HDC         hdc ;
141      PAINTSTRUCT ps ;
142      RECT        rect ;
143
144      switch (message)
145      {
146      case WM_CREATE :
147           SetWindowLong (hwnd, 0, 0) ;       // on/off flag
148           return 0 ;
149
150      case WM_KEYDOWN:
151                // Send most key presses to the parent window
152
153           if (wParam != VK_RETURN && wParam != VK_SPACE)
154           {
155                SendMessage (GetParent (hwnd), message, wParam, lParam) ;
156                return 0 ;
157           }
158                // For Return and Space, fall through to toggle the square
159
160      case WM_LBUTTONDOWN :
161           SetWindowLong (hwnd, 0, 1 ^ GetWindowLong (hwnd, 0)) ;
162           SetFocus (hwnd) ;
163           InvalidateRect (hwnd, NULL, FALSE) ;
164           return 0 ;
165
166                // For focus messages, invalidate the window for repaint
167
168      case WM_SETFOCUS:
169           idFocus = GetWindowLong (hwnd, GWL_ID) ;
170
171                // Fall through
172
173      case WM_KILLFOCUS:
174           InvalidateRect (hwnd, NULL, TRUE) ;
175           return 0 ;
176
177      case WM_PAINT :
178           hdc = BeginPaint (hwnd, &ps) ;
179
180           GetClientRect (hwnd, &rect) ;
181           Rectangle (hdc, 0, 0, rect.right, rect.bottom) ;
182
183                // Draw the "x" mark
184
185           if (GetWindowLong (hwnd, 0))
186           {
187                MoveToEx (hdc, 0,          0, NULL) ;
188                LineTo   (hdc, rect.right, rect.bottom) ;
189                MoveToEx (hdc, 0,          rect.bottom, NULL) ;
190                LineTo   (hdc, rect.right, 0) ;
191           }
192
193                // Draw the "focus" rectangle
194
195           if (hwnd == GetFocus ())
196           {
197                rect.left   += rect.right / 10 ;
198                rect.right  -= rect.left ;
199                rect.top    += rect.bottom / 10 ;
200                rect.bottom -= rect.top ;
201
202                SelectObject (hdc, GetStockObject (NULL_BRUSH)) ;
203                SelectObject (hdc, CreatePen (PS_DASH, 0, 0)) ;
204                Rectangle (hdc, rect.left, rect.top, rect.right, rect.bottom) ;
205                DeleteObject (SelectObject (hdc, GetStockObject (BLACK_PEN))) ;
206           }
207
208           EndPaint (hwnd, &ps) ;
209           return 0 ;
210      }
211      return DefWindowProc (hwnd, message, wParam, lParam) ;
212 }


  1 /*-------------------------------------------------
  2    CHECKER4.C -- Mouse Hit-Test Demo Program No. 4
  3                  (c) Charles Petzold, 1998
  4   -------------------------------------------------*/
  5
  6 #include <windows.h>
  7
  8 #define DIVISIONS 5
  9
 10 LRESULT CALLBACK WndProc   (HWND, UINT, WPARAM, LPARAM) ;
 11 LRESULT CALLBACK ChildWndProc (HWND, UINT, WPARAM, LPARAM) ;
 12
 13 int   idFocus = 0 ;
 14 TCHAR szChildClass[] = TEXT ("Checker4_Child") ;
 15
 16 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
 17                     PSTR szCmdLine, int iCmdShow)
 18 {
 19      static TCHAR szAppName[] = TEXT ("Checker4") ;
 20      HWND         hwnd ;
 21      MSG          msg ;
 22      WNDCLASS     wndclass ;
 23
 24      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
 25      wndclass.lpfnWndProc   = WndProc ;
 26      wndclass.cbClsExtra    = 0 ;
 27      wndclass.cbWndExtra    = 0 ;
 28      wndclass.hInstance     = hInstance ;
 29      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
 30      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
 31      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
 32      wndclass.lpszMenuName  = NULL ;
 33      wndclass.lpszClassName = szAppName ;
 34
 35      if (!RegisterClass (&wndclass))
 36      {
 37           MessageBox (NULL, TEXT ("Program requires Windows NT!"),
 38                       szAppName, MB_ICONERROR) ;
 39           return 0 ;
 40      }
 41
 42      wndclass.lpfnWndProc   = ChildWndProc ;
 43      wndclass.cbWndExtra    = sizeof (long) ;
 44      wndclass.hIcon         = NULL ;
 45      wndclass.lpszClassName = szChildClass ;
 46
 47      RegisterClass (&wndclass) ;
 48
 49      hwnd = CreateWindow (szAppName, TEXT ("Checker4 Mouse Hit-Test Demo"),
 50                           WS_OVERLAPPEDWINDOW,
 51                           CW_USEDEFAULT, CW_USEDEFAULT,
 52                           CW_USEDEFAULT, CW_USEDEFAULT,
 53                           NULL, NULL, hInstance, NULL) ;
 54
 55      ShowWindow (hwnd, iCmdShow) ;
 56      UpdateWindow (hwnd) ;
 57
 58      while (GetMessage (&msg, NULL, 0, 0))
 59      {
 60           TranslateMessage (&msg) ;
 61           DispatchMessage (&msg) ;
 62      }
 63      return msg.wParam ;
 64 }
 65
 66 LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 67 {
 68      static HWND hwndChild[DIVISIONS][DIVISIONS] ;
 69      int         cxBlock, cyBlock, x, y ;
 70
 71      switch (message)
 72      {
 73      case WM_CREATE :
 74           for (x = 0 ; x < DIVISIONS ; x++)
 75                for (y = 0 ; y < DIVISIONS ; y++)
 76                     hwndChild[x][y] = CreateWindow (szChildClass, NULL,
 77                               WS_CHILDWINDOW | WS_VISIBLE,
 78                               0, 0, 0, 0,
 79                               hwnd, (HMENU) (y << 8 | x),
 80                               (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE),
 81                               NULL) ;
 82           return 0 ;
 83
 84      case WM_SIZE :
 85           cxBlock = LOWORD (lParam) / DIVISIONS ;
 86           cyBlock = HIWORD (lParam) / DIVISIONS ;
 87
 88           for (x = 0 ; x < DIVISIONS ; x++)
 89                 for (y = 0 ; y < DIVISIONS ; y++)
 90                     MoveWindow (hwndChild[x][y],
 91                                 x * cxBlock, y * cyBlock,
 92                                 cxBlock, cyBlock, TRUE) ;
 93           return 0 ;
 94
 95      case WM_LBUTTONDOWN :
 96           MessageBeep (0) ;
 97           return 0 ;
 98
 99           // On set-focus message, set focus to child window
100
101      case WM_SETFOCUS:
102           SetFocus (GetDlgItem (hwnd, idFocus)) ;
103           return 0 ;
104
105           // On key-down message, possibly change the focus window
106
107      case WM_KEYDOWN:
108           x = idFocus & 0xFF ;
109           y = idFocus >> 8 ;
110
111           switch (wParam)
112           {
113           case VK_UP:    y-- ;                    break ;
114           case VK_DOWN:  y++ ;                    break ;
115           case VK_LEFT:  x-- ;                    break ;
116           case VK_RIGHT: x++ ;                    break ;
117           case VK_HOME:  x = y = 0 ;              break ;
118           case VK_END:   x = y = DIVISIONS - 1 ;  break ;
119           default:       return 0 ;
120           }
121
122           x = (x + DIVISIONS) % DIVISIONS ;
123           y = (y + DIVISIONS) % DIVISIONS ;
124
125           idFocus = y << 8 | x ;
126
127           SetFocus (GetDlgItem (hwnd, idFocus)) ;
128           return 0 ;
129
130      case WM_DESTROY :
131           PostQuitMessage (0) ;
132           return 0 ;
133      }
134      return DefWindowProc (hwnd, message, wParam, lParam) ;
135 }
136
137 LRESULT CALLBACK ChildWndProc (HWND hwnd, UINT message,
138                                WPARAM wParam, LPARAM lParam)
139 {
140      HDC         hdc ;
141      PAINTSTRUCT ps ;
142      RECT        rect ;
143
144      switch (message)
145      {
146      case WM_CREATE :
147           SetWindowLong (hwnd, 0, 0) ;       // on/off flag
148           return 0 ;
149
150      case WM_KEYDOWN:
151                // Send most key presses to the parent window
152
153           if (wParam != VK_RETURN && wParam != VK_SPACE)
154           {
155                SendMessage (GetParent (hwnd), message, wParam, lParam) ;
156                return 0 ;
157           }
158                // For Return and Space, fall through to toggle the square
159
160      case WM_LBUTTONDOWN :
161           SetWindowLong (hwnd, 0, 1 ^ GetWindowLong (hwnd, 0)) ;
162           SetFocus (hwnd) ;
163           InvalidateRect (hwnd, NULL, FALSE) ;
164           return 0 ;
165
166                // For focus messages, invalidate the window for repaint
167
168      case WM_SETFOCUS:
169           idFocus = GetWindowLong (hwnd, GWL_ID) ;
170
171                // Fall through
172
173      case WM_KILLFOCUS:
174           InvalidateRect (hwnd, NULL, TRUE) ;
175           return 0 ;
176
177      case WM_PAINT :
178           hdc = BeginPaint (hwnd, &ps) ;
179
180           GetClientRect (hwnd, &rect) ;
181           Rectangle (hdc, 0, 0, rect.right, rect.bottom) ;
182
183                // Draw the "x" mark
184
185           if (GetWindowLong (hwnd, 0))
186           {
187                MoveToEx (hdc, 0,          0, NULL) ;
188                LineTo   (hdc, rect.right, rect.bottom) ;
189                MoveToEx (hdc, 0,          rect.bottom, NULL) ;
190                LineTo   (hdc, rect.right, 0) ;
191           }
192
193                // Draw the "focus" rectangle
194
195           if (hwnd == GetFocus ())
196           {
197                rect.left   += rect.right / 10 ;
198                rect.right  -= rect.left ;
199                rect.top    += rect.bottom / 10 ;
200                rect.bottom -= rect.top ;
201
202                SelectObject (hdc, GetStockObject (NULL_BRUSH)) ;
203                SelectObject (hdc, CreatePen (PS_DASH, 0, 0)) ;
204                Rectangle (hdc, rect.left, rect.top, rect.right, rect.bottom) ;
205                DeleteObject(SelectObject (hdc, GetStockObject (BLACK_PEN))) ;
206           }
207
208           EndPaint (hwnd, &ps) ;
209           return 0 ;
210      }
211      return DefWindowProc (hwnd, message, wParam, lParam) ;
212 }

 
时间: 2024-10-06 17:15:50

&与&& C语言的相关文章

使用R语言计算均值,方差等

R语言对于数值计算很方便,最近用到了计算方差,标准差的功能,特记录. 数据准备 height <- c(6.00, 5.92, 5.58, 5.92) 1 计算均值 mean(height) [1] 5.855 2 计算中位数 median(height) [1] 5.92 3 计算标准差 sd(height) [1] 0.1871719 4 计算方差 var(height) [1] 0.03503333 5 计算两个变量之间的相关系数 cor(height,log(height)) [1] 0

GCC在C语言中内嵌汇编 asm __volatile__ 【转】

转自:http://blog.csdn.net/pbymw8iwm/article/details/8227839 在内嵌汇编中,可以将C语言表达式指定为汇编指令的操作数,而且不用去管如何将C语言表达式的值读入哪个寄存器,以及如何将计算结果写回C 变量,你只要告诉程序中C语言表达式与汇编指令操作数之间的对应关系即可, GCC会自动插入代码完成必要的操作. 1.简单的内嵌汇编 例: __asm__ __volatile__("hlt"); "__asm__"表示后面的

C语言轻松高效学习方法之:多种方法实现

多种方法实现同一个功能,可以调动你学的所有知识去做,有助于你学的融会贯通. 下面举例来看: 实现功能:求一个整数的位数: 实现语言:C语言: 开发环境:Visual Studio 2017 如:3215是4位数 实现原理: 3215/10 = 321 ----1位数 321/10 = 32 ----又是1位数 32/10 = 3 ----又是1位数 3/10 = 0 ----又是1位数 共4位数,且终止计算条件是/10结果为0的时候: 根据这个原理,先写一个最笨的原始方法: 效果: 这种实现方案

轻松学习C语言编程的秘诀:总结+灵感

目前在准备一套C语言的学习教程,所以我这里就以C语言编程的学习来讲.注意,讲的是"轻松学习",那种不注重方法,拼命玩命的方式也有其效果,但不是我提倡的.我讲究的是在方式方法对头.适合你.减轻你学习负担和心里压力的前提下,才适当的抓紧时间. 因此,探索一种很好的学习方法就是我所研究的主要内容. 众所周知,学习C语言并非易事,要学好它更是难上加难.这和你期末考试背会几个题目的答案考上满分没多大关系,也就是说你考试满分也说明不了你学好.学精通了C语言.那么怎么才算学精通C语言?闭着眼睛对自己

详解go语言的array和slice 【二】

上一篇  详解go语言的array和slice [一]已经讲解过,array和slice的一些基本用法,使用array和slice时需要注意的地方,特别是slice需要注意的地方比较多.上一篇的最后讲解到创建新的slice时使用第三个索引来限制slice的容量,在操作新slice时,如果新slice的容量大于长度时,添加新元素依然后使源的相应元素改变.这一篇里我会讲解到如何避免这些问题,以及迭代.和做为方法参数方面的知识点. slice的长度和容量设置为同一个值 如果在创建新的slice时我们把

自动生成小学四则运算题目(C语言)

这个简易四则运算是我在百度上找的博主叫53余雅诗的一篇c语言代码,网址为http://www.cnblogs.com/ys1101/p/4368103.html,功能是可以选择加减乘除进行简易的四则运算,判断对错.我在VS2017上编译没有bug,因为功能只有整数运算,所以我在此基础上加了真分数的四则运算以及统计得分等,最后成功运行程序.我把我的源代码放在github上,地址为https://github.com/xiaofancheng/helloworld.

PAT 1009 说反话 C语言

给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出. 输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串.字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用1个空格分开,输入保证句子末尾没有多余的空格. 输出格式:每个测试用例的输出占一行,输出倒序后的句子. 输入样例: Hello World Here I Come 输出样例: Come I Here World Hello 1 #include<stdio.h> 2 #

PAT 1006 换个格式输出 C语言

让我们用字母B来表示"百".字母S表示"十",用"12...n"来表示个位数字n(<10),换个格式来输出任一个不超过3位的正整数.例如234应该被输出为BBSSS1234,因为它有2个"百".3个"十".以及个位的4. 输入格式:每个测试输入包含1个测试用例,给出正整数n(<1000). 输出格式:每个测试用例的输出占一行,用规定的格式输出n. 输入样例1: 234 输出样例1: BBSSS1

Go语言 IDE之Gogland配置使用

Gogland 是 JetBrains 公司推出的 Go 语言集成开发环境.Gogland 同样基于 IntelliJ 平台开发,支持 JetBrains 的插件体系.目前正式版尚未发布.官方:https://www.jetbrains.com/go/.关于使用,即将开始咯! 一.安装Golang 1) 首先到https://golang.org/dl/选择适合你系统的安装包,(墙内:http://golangtc.com/download). 2)下载完成安装到指定目录即可.我这里是(D:\G

R语言快速上手入门

R语言快速上手入门 课程学习网址:http://www.xuetuwuyou.com/course/196 课程出自学途无忧网:http://www.xuetuwuyou.com 课程简介 本教程深入浅出地讲解如何使用R语言玩转数据.课程中涵盖R语言编程的方方面面,内容涉及R对象的类型.R的记号体系和环境系统.自定义函数.if else语句.for循环.S3类R的包系统以及调试工具等.本课程还通过示例演示如何进行向量化编程,从而对代码进行提速并尽可能地发挥R的潜能.本课程适合立志成为数据科学家的