&与&& 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这些对象 ...
随机推荐
- oracle关键字(保留字)
其实这个东西可以在oracle 上输入一个sql语句就可以得到: select * from v$reserved_words order by keyword asc; //order 后边不是 ...
- Failed to install *.apk on device 'emulator-5554': timeout
错误提示: Failed to install helloworld.apk on device 'emulator-5554': timeout 或者 the user data image is ...
- 职业定位(移动端、ios开发、Android开发)
移动端 移动端webapp开发必备知识:http://www.chinaz.com/manage/2012/1128/283974.shtml 设计一款好的移动App,有哪些基本规则?http://w ...
- Jenkins搭建Windows slave 环境
因为之前的接口测试平台是在windows上,后来换了linux,花了半天时间也没有成功,就想着建立一个windows的节点曲线救国 创建WindowsSlave 首先要保证windows和sl ...
- 1.4.2.2. PATHS(Core Data 应用程序实践指南)
持久化存储文件在文件系统中的位置 先获取应用程序文档目录的路径 #pragma mark - PATHS - (NSString *)applicationDocumentsDirectory { ) ...
- jQuery 的 ready 函数是如何工作的?(源码分析)
如果你使用过 jQuery , 就必然使用过 ready 函数,它用来注册当页面准备好之后可以执行的函数. 问题来啦,我们的页面什么时候准备好了呢? 1. onload 事件 最基本的处理方式就是页面 ...
- js原生继承之——构造函数式继承实例
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- 星级评分条(RatingBar)的功能和用法
星级评分条与拖动条有相同的父类:AbsSeekBar,因此它们十分相似.实际上星级评分条与拖动条的用法.功能都十分接近:它们都是允许用户通过拖动条来改变进度.RatingBar与SeekBar最大区别 ...
- U盘安装系统
http://www.ushendu.com/usdpzxt/1566.html http://www.ushendu.com/plus/view.php?aid=1571 http://www.ud ...
- C#综合揭秘——细说进程、应用程序域与上下文之间的关系
引言 本文主要是介绍进程(Process).应用程序域(AppDomain)..NET上下文(Context)的概念与操作.虽然在一般的开发当中这三者并不常用,但熟悉三者的关系,深入了解其作用,对提高 ...