&与&& C语言
&是一个位运算符,就是将两个二进制的数逐位相与,就是都是1才是1,只要有一个为0则为0,结果是相与之后的结果。
&&是一个逻辑运算符,就是判断两个表达式的真假性,只有两个表达式同时为真才为真,有一个为假则为假,具有短路性质。
/*-------------------------------------------------
CHECKER4.C -- Mouse Hit-Test Demo Program No. 4
(c) Charles Petzold, 1998
-------------------------------------------------*/ #include <windows.h> #define DIVISIONS 5 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
LRESULT CALLBACK ChildWndProc (HWND, UINT, WPARAM, LPARAM) ; int idFocus = ;
TCHAR szChildClass[] = TEXT ("Checker4_Child") ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("Checker4") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = ;
wndclass.cbWndExtra = ;
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 ("Program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return ;
} wndclass.lpfnWndProc = ChildWndProc ;
wndclass.cbWndExtra = sizeof (long) ;
wndclass.hIcon = NULL ;
wndclass.lpszClassName = szChildClass ; RegisterClass (&wndclass) ; hwnd = CreateWindow (szAppName, TEXT ("Checker4 Mouse Hit-Test Demo"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ; ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, , ))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
} LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndChild[DIVISIONS][DIVISIONS] ;
int cxBlock, cyBlock, x, y ; switch (message)
{
case WM_CREATE :
for (x = ; x < DIVISIONS ; x++)
for (y = ; y < DIVISIONS ; y++)
hwndChild[x][y] = CreateWindow (szChildClass, NULL,
WS_CHILDWINDOW | WS_VISIBLE,
, , , ,
hwnd, (HMENU) (y << | x),
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE),
NULL) ;
return ; case WM_SIZE :
cxBlock = LOWORD (lParam) / DIVISIONS ;
cyBlock = HIWORD (lParam) / DIVISIONS ; for (x = ; x < DIVISIONS ; x++)
for (y = ; y < DIVISIONS ; y++)
MoveWindow (hwndChild[x][y],
x * cxBlock, y * cyBlock,
cxBlock, cyBlock, TRUE) ;
return ; case WM_LBUTTONDOWN :
MessageBeep () ;
return ; // On set-focus message, set focus to child window case WM_SETFOCUS:
SetFocus (GetDlgItem (hwnd, idFocus)) ;
return ; // On key-down message, possibly change the focus window case WM_KEYDOWN:
x = idFocus & 0xFF ;
y = idFocus >> ; switch (wParam)
{
case VK_UP: y-- ; break ;
case VK_DOWN: y++ ; break ;
case VK_LEFT: x-- ; break ;
case VK_RIGHT: x++ ; break ;
case VK_HOME: x = y = ; break ;
case VK_END: x = y = DIVISIONS - ; break ;
default: return ;
} x = (x + DIVISIONS) % DIVISIONS ;
y = (y + DIVISIONS) % DIVISIONS ; idFocus = y << | x ; SetFocus (GetDlgItem (hwnd, idFocus)) ;
return ; case WM_DESTROY :
PostQuitMessage () ;
return ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
} LRESULT CALLBACK ChildWndProc (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ; switch (message)
{
case WM_CREATE :
SetWindowLong (hwnd, , ) ; // on/off flag
return ; case WM_KEYDOWN:
// Send most key presses to the parent window if (wParam != VK_RETURN && wParam != VK_SPACE)
{
SendMessage (GetParent (hwnd), message, wParam, lParam) ;
return ;
}
// For Return and Space, fall through to toggle the square case WM_LBUTTONDOWN :
SetWindowLong (hwnd, , ^ GetWindowLong (hwnd, )) ;
SetFocus (hwnd) ;
InvalidateRect (hwnd, NULL, FALSE) ;
return ; // For focus messages, invalidate the window for repaint case WM_SETFOCUS:
idFocus = GetWindowLong (hwnd, GWL_ID) ; // Fall through case WM_KILLFOCUS:
InvalidateRect (hwnd, NULL, TRUE) ;
return ; case WM_PAINT :
hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ;
Rectangle (hdc, , , rect.right, rect.bottom) ; // Draw the "x" mark if (GetWindowLong (hwnd, ))
{
MoveToEx (hdc, , , NULL) ;
LineTo (hdc, rect.right, rect.bottom) ;
MoveToEx (hdc, , rect.bottom, NULL) ;
LineTo (hdc, rect.right, ) ;
} // Draw the "focus" rectangle if (hwnd == GetFocus ())
{
rect.left += rect.right / ;
rect.right -= rect.left ;
rect.top += rect.bottom / ;
rect.bottom -= rect.top ; SelectObject (hdc, GetStockObject (NULL_BRUSH)) ;
SelectObject (hdc, CreatePen (PS_DASH, , )) ;
Rectangle (hdc, rect.left, rect.top, rect.right, rect.bottom) ;
DeleteObject (SelectObject (hdc, GetStockObject (BLACK_PEN))) ;
} EndPaint (hwnd, &ps) ;
return ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
/*-------------------------------------------------
CHECKER4.C -- Mouse Hit-Test Demo Program No. 4
(c) Charles Petzold, 1998
-------------------------------------------------*/ #include <windows.h> #define DIVISIONS 5 LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
LRESULT CALLBACK ChildWndProc (HWND, UINT, WPARAM, LPARAM) ; int idFocus = ;
TCHAR szChildClass[] = TEXT ("Checker4_Child") ; int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("Checker4") ;
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ; wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = ;
wndclass.cbWndExtra = ;
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 ("Program requires Windows NT!"),
szAppName, MB_ICONERROR) ;
return ;
} wndclass.lpfnWndProc = ChildWndProc ;
wndclass.cbWndExtra = sizeof (long) ;
wndclass.hIcon = NULL ;
wndclass.lpszClassName = szChildClass ; RegisterClass (&wndclass) ; hwnd = CreateWindow (szAppName, TEXT ("Checker4 Mouse Hit-Test Demo"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL) ; ShowWindow (hwnd, iCmdShow) ;
UpdateWindow (hwnd) ; while (GetMessage (&msg, NULL, , ))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
} LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static HWND hwndChild[DIVISIONS][DIVISIONS] ;
int cxBlock, cyBlock, x, y ; switch (message)
{
case WM_CREATE :
for (x = ; x < DIVISIONS ; x++)
for (y = ; y < DIVISIONS ; y++)
hwndChild[x][y] = CreateWindow (szChildClass, NULL,
WS_CHILDWINDOW | WS_VISIBLE,
, , , ,
hwnd, (HMENU) (y << | x),
(HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE),
NULL) ;
return ; case WM_SIZE :
cxBlock = LOWORD (lParam) / DIVISIONS ;
cyBlock = HIWORD (lParam) / DIVISIONS ; for (x = ; x < DIVISIONS ; x++)
for (y = ; y < DIVISIONS ; y++)
MoveWindow (hwndChild[x][y],
x * cxBlock, y * cyBlock,
cxBlock, cyBlock, TRUE) ;
return ; case WM_LBUTTONDOWN :
MessageBeep () ;
return ; // On set-focus message, set focus to child window case WM_SETFOCUS:
SetFocus (GetDlgItem (hwnd, idFocus)) ;
return ; // On key-down message, possibly change the focus window case WM_KEYDOWN:
x = idFocus & 0xFF ;
y = idFocus >> ; switch (wParam)
{
case VK_UP: y-- ; break ;
case VK_DOWN: y++ ; break ;
case VK_LEFT: x-- ; break ;
case VK_RIGHT: x++ ; break ;
case VK_HOME: x = y = ; break ;
case VK_END: x = y = DIVISIONS - ; break ;
default: return ;
} x = (x + DIVISIONS) % DIVISIONS ;
y = (y + DIVISIONS) % DIVISIONS ; idFocus = y << | x ; SetFocus (GetDlgItem (hwnd, idFocus)) ;
return ; case WM_DESTROY :
PostQuitMessage () ;
return ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
} LRESULT CALLBACK ChildWndProc (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
RECT rect ; switch (message)
{
case WM_CREATE :
SetWindowLong (hwnd, , ) ; // on/off flag
return ; case WM_KEYDOWN:
// Send most key presses to the parent window if (wParam != VK_RETURN && wParam != VK_SPACE)
{
SendMessage (GetParent (hwnd), message, wParam, lParam) ;
return ;
}
// For Return and Space, fall through to toggle the square case WM_LBUTTONDOWN :
SetWindowLong (hwnd, , ^ GetWindowLong (hwnd, )) ;
SetFocus (hwnd) ;
InvalidateRect (hwnd, NULL, FALSE) ;
return ; // For focus messages, invalidate the window for repaint case WM_SETFOCUS:
idFocus = GetWindowLong (hwnd, GWL_ID) ; // Fall through case WM_KILLFOCUS:
InvalidateRect (hwnd, NULL, TRUE) ;
return ; case WM_PAINT :
hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ;
Rectangle (hdc, , , rect.right, rect.bottom) ; // Draw the "x" mark if (GetWindowLong (hwnd, ))
{
MoveToEx (hdc, , , NULL) ;
LineTo (hdc, rect.right, rect.bottom) ;
MoveToEx (hdc, , rect.bottom, NULL) ;
LineTo (hdc, rect.right, ) ;
} // Draw the "focus" rectangle if (hwnd == GetFocus ())
{
rect.left += rect.right / ;
rect.right -= rect.left ;
rect.top += rect.bottom / ;
rect.bottom -= rect.top ; SelectObject (hdc, GetStockObject (NULL_BRUSH)) ;
SelectObject (hdc, CreatePen (PS_DASH, , )) ;
Rectangle (hdc, rect.left, rect.top, rect.right, rect.bottom) ;
DeleteObject(SelectObject (hdc, GetStockObject (BLACK_PEN))) ;
} EndPaint (hwnd, &ps) ;
return ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
&与&& C语言的更多相关文章
- C语言 · 高精度加法
问题描述 输入两个整数a和b,输出这两个整数的和.a和b都不超过100位. 算法描述 由于a和b都比较大,所以不能直接使用语言中的标准数据类型来存储.对于这种问题,一般使用数组来处理. 定义一个数组A ...
- Windows server 2012 添加中文语言包(英文转为中文)(离线)
Windows server 2012 添加中文语言包(英文转为中文)(离线) 相关资料: 公司环境:亚马孙aws虚拟机 英文版Windows2012 中文SQL Server2012安装包,需要安装 ...
- iOS开发系列--Swift语言
概述 Swift是苹果2014年推出的全新的编程语言,它继承了C语言.ObjC的特性,且克服了C语言的兼容性问题.Swift发展过程中不仅保留了ObjC很多语法特性,它也借鉴了多种现代化语言的特点,在 ...
- C语言 · Anagrams问题
问题描述 Anagrams指的是具有如下特性的两个单词:在这两个单词当中,每一个英文字母(不区分大小写)所出现的次数都是相同的.例如,"Unclear"和"Nuclear ...
- C语言 · 字符转对比
问题描述 给定两个仅由大写字母或小写字母组成的字符串(长度介于1到10之间),它们之间的关系是以下4中情况之一: 1:两个字符串长度不等.比如 Beijing 和 Hebei 2:两个字符串不仅长度相 ...
- JAVA语言中的修饰符
JAVA语言中的修饰符 -----------------------------------------------01--------------------------------------- ...
- Atitit 项目语言的选择 java c#.net php??
Atitit 项目语言的选择 java c#.net php?? 1.1. 编程语言与技术,应该使用开放式的目前流行的语言趋势1 1.2. 从个人职业生涯考虑,java优先1 1.3. 从项目实际来 ...
- 【开源】简单4步搞定QQ登录,无需什么代码功底【无语言界限】
说17号发超简单的教程就17号,qq核审通过后就封装了这个,现在放出来~~ 这个是我封装的一个开源项目:https://github.com/dunitian/LoTQQLogin ————————— ...
- InstallShield 脚本语言学习笔记
InstallShield脚本语言是类似C语言,利用InstallShield的向导或模板都可以生成基本的脚本程序框架,可以在此基础上按自己的意愿进行修改和添加. 一.基本语法规则 ...
- 用C语言封装OC对象(耐心阅读,非常重要)
用C语言封装OC对象(耐心阅读,非常重要) 本文的主要内容来自这里 前言 做iOS开发的朋友,对OC肯定非常了解,那么大家有没有想过OC中NSInteger,NSObject,NSString这些对象 ...
随机推荐
- FTP-使用记录
1.磁盘配额不够用 Could not write to transfer socket: ECONNABORTED - 连接中止 452-Maximum disk quota limited to ...
- IOS开发-UI学习-沙盒机制&文件操作
苹果为软件的运行提供了一个沙盒机制 每个沙盒含有3个文件夹:Documents, Library 和 tmp.因为应用的沙盒机制,应用只能在几个目录下读写文件 Documents:苹果建议将程序中 ...
- C++ 虚基类表指针字节对齐
下面博客转载自别人的,我也是被这个问题坑了快两天了,关于各种虚基类,虚继承,虚函数以及数据成员等引发的一系列内存对齐的问题再次详细描述 先看下面这片代码.在这里我使用了一个空类K,不要被这个东西所迷惑 ...
- 使用React Native来撰写跨平台的App
React Native 是一个 JavaScript 的框架,用来撰写实时的.可原生呈现 iOS 和 Android 的应用.其是基于 React的,而 React 是 Facebook 的用于构建 ...
- TSP问题[动态规划]
分析: 有用的量:城市集合V={a,b,c,d,--} 所以我们用 T(i,V) 表示从 城市 i 出发遍历集合 V 中的城市一遍且仅一遍后回到 i 所用的最少费用(这里可能表达不好,底下会看到,但是 ...
- .net学习路线
http://www.cnblogs.com/huangmeimujin/archive/2011/08/08/2131242.html http://jingyan.baidu.com/articl ...
- Java经典案例之-“统计英文字母、空格、数字和其它字符的个数”
/** * 描述:输入一行字符串,并且统计出其中英文字母.空格.数字和其它字符的个数. * 分析:利用for语句,条件为输入的字符不为 '\n ' * 作者:徐守威 */ package com.xu ...
- mysql数据库锁定机制
前言 为了保证数据的一致完整性,任何一个数据库都存在锁定机制.锁定机制的优劣直接应想到一个数据库系统的并发处理能力和性能,所以锁定机制的实现也就 成为了各种数据库的核心技术之一.本章将对MySQL中两 ...
- 关于P,NP,NPC和NP-hard的通俗解释
这些概念以前老是犯糊涂,今天整清楚.摘要:P: Polynomial SolvableNP: Non-determinstic Polynomial Solvable 0)词语解释:Polynomia ...
- jquery $.getJSON()跨域请求
以前总是没搞明白是怎么回事,现在是迫不得已,就仔细看了看说明文档,终于测试成功了,记下 1,同一域名下和其他的请求可以是一样的 js: 代码如下: var url="http://loc ...