您正在查看: 2017年1月

Win32如何获取Windows的屏幕宽和高

函数原型:获取一些设备数据

// By MoreWindows( http://blog.csdn.NET/MoreWindows )
int GetDeviceCaps(

   HDChdc,     // handle to DC
   int nIndex   // index of capability

);

参数说明:

第一个参数表示设备环境的HDC句柄。

第二个参数与GetSystemMetrics函数的参数类似,常用的有二个:

HORZSIZE

           Width, in millimeters, of the physical screen.

VERTSIZE

           Height, in millimeters, of the physical screen.

由GetDeviceCaps函数的介绍可知获取屏幕的物理大小非常简单,下面给出完整的源代码:

// 获取屏幕大小 物理大小

#include <stdio.h>
#include <windows.h>
int main()
{
     
    int nScreenWidth, nScreenHeight;
    HDC hdcScreen = GetDC(NULL);   //获取屏幕的HDC
    nScreenWidth = GetDeviceCaps(hdcScreen, HORZSIZE);
    nScreenHeight = GetDeviceCaps(hdcScreen, VERTSIZE);
    printf("屏幕大小 宽:%d 高:%d\n", nScreenWidth, nScreenHeight);
    return 0;
}

第二种方法:

要获取屏幕的像素大小要还可以使用GetSystemMetrics函数。

函数功能:用于得到被定义的系统数据或者系统配置信息

函数原型:

int WINAPI GetSystemMetrics(

   int nIndex

);

参数说明:

这个函数只有一个参数,不过这个参数可以取很多值。在WINUSER.H中有:

/*

  • GetSystemMetrics() codes

*/

#define SM_CXSCREEN             0

#define SM_CYSCREEN             1

#define SM_CXVSCROLL            2

#define SM_CYHSCROLL            3

#define SM_CYCAPTION            4

#define SM_CXBORDER             5

#define SM_CYBORDER             6

#define SM_CXDLGFRAME           7

#define SM_CYDLGFRAME           8

#define SM_CYVTHUMB             9

#define SM_CXHTHUMB             10

#define SM_CXICON               11

#define SM_CYICON               12

#define SM_CXCURSOR             13

#define SM_CYCURSOR             14

#define SM_CYMENU               15

#define SM_CXFULLSCREEN         16

#define SM_CYFULLSCREEN         17

#define SM_CYKANJIWINDOW        18

#define SM_MOUSEPRESENT         19

#define SM_CYVSCROLL            20

#define SM_CXHSCROLL            21

#define SM_DEBUG                22

#define SM_SWAPBUTTON           23

#define SM_RESERVED1            24

#define SM_RESERVED2            25

#define SM_RESERVED3            26

#define SM_RESERVED4            27

#define SM_CXMIN                28

#define SM_CYMIN                29

#define SM_CXSIZE               30

#define SM_CYSIZE               31

#define SM_CXFRAME              32

#define SM_CYFRAME              33

#define SM_CXMINTRACK           34

#define SM_CYMINTRACK           35

#define SM_CXDOUBLECLK          36

#define SM_CYDOUBLECLK          37

#define SM_CXICONSPACING        38

#define SM_CYICONSPACING        39

#define SM_MENUDROPALIGNMENT    40

#define SM_PENWINDOWS           41

#define SM_DBCSENABLED          42

#define SM_CMOUSEBUTTONS        43

 

#if(WINVER >= 0x0400)

#define SM_CXFIXEDFRAME           SM_CXDLGFRAME  /* ;win40 name change */

#define SM_CYFIXEDFRAME           SM_CYDLGFRAME  /* ;win40 name change */

#define SM_CXSIZEFRAME            SM_CXFRAME     /* ;win40 name change */

#define SM_CYSIZEFRAME            SM_CYFRAME     /* ;win40 name change */

 

#define SM_SECURE               44

#define SM_CXEDGE               45

#define SM_CYEDGE               46

#define SM_CXMINSPACING         47

#define SM_CYMINSPACING         48

#define SM_CXSMICON             49

#define SM_CYSMICON             50

#define SM_CYSMCAPTION          51

#define SM_CXSMSIZE             52

#define SM_CYSMSIZE             53

#define SM_CXMENUSIZE           54

#define SM_CYMENUSIZE           55

#define SM_ARRANGE              56

#define SM_CXMINIMIZED          57

#define SM_CYMINIMIZED          58

#define SM_CXMAXTRACK           59

#define SM_CYMAXTRACK           60

#define SM_CXMAXIMIZED          61

#define SM_CYMAXIMIZED          62

#define SM_NETWORK              63

#define SM_CLEANBOOT            67

#define SM_CXDRAG               68

#define SM_CYDRAG               69

#endif /* WINVER >= 0x0400 */

#define SM_SHOWSOUNDS           70

#if(WINVER >= 0x0400)

#define SM_CXMENUCHECK          71   /* Use instead of GetMenuCheckMarkDimensions()! */

#define SM_CYMENUCHECK          72

#define SM_SLOWMACHINE          73

#define SM_MIDEASTENABLED       74

#endif /* WINVER >= 0x0400 */

#if (WINVER >= 0x0500) || (_win32_WINNT >= 0x0400)

#define SM_MOUSEWHEELPRESENT    75

#endif

#if(WINVER >= 0x0500)

#define SM_XVIRTUALSCREEN       76

#define SM_YVIRTUALSCREEN       77

#define SM_CXVIRTUALSCREEN      78

#define SM_CYVIRTUALSCREEN      79

#define SM_CMONITORS            80

#define SM_SAMEDISPLAYFORMAT    81

#endif /* WINVER >= 0x0500 */

 

#if (WINVER < 0x0500) && (!defined(_win32_WINNT) || (_WIN32_WINNT < 0x0400))

#define SM_CMETRICS             76

#else

#define SM_CMETRICS             83

#endif



#include <stdio.h>
#include <windows.h>
int main()
{
    printf("    获取屏幕大小 像素大小\n");        

    int nScreenWidth, nScreenHeight;
    nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
    nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
    printf("屏幕大小 宽:%d 高:%d\n", nScreenWidth, nScreenHeight);
    return 0;
}

linux编译时出现 fatal error: SDL/SDL.h: No such file or directory怎么办?

如果编译时出现以下信息,说明没有安装SDL
fatal error: SDL/SDL.h: No such file or directory
#include <SDL/SDL.h>

这时只需要

sudo yum install SDL-devel  SDL-static

Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile

  • base: ftp.sjtu.edu.cn
  • extras: centos.ustc.edu.cn
  • updates: ftp.tc.edu.tw
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package SDL-devel.x86_64 0:1.2.14-7.el6_7.1 will be installed
    --> Processing Dependency: alsa-lib-devel for package: SDL-devel-1.2.14-7.el6_7.1.x86_64
    ---> Package SDL-static.x86_64 0:1.2.14-7.el6_7.1 will be installed
    --> Running transaction check
    ---> Package alsa-lib-devel.x86_64 0:1.1.0-4.el6 will be installed
    --> Processing Dependency: alsa-lib = 1.1.0-4.el6 for package: alsa-lib-devel-1.1.0-4.el6.x86_64
    --> Running transaction check
    ---> Package alsa-lib.x86_64 0:1.0.22-3.el6 will be updated
    ---> Package alsa-lib.x86_64 0:1.1.0-4.el6 will be an update
    --> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================================================
Installing:
SDL-devel x86_64 1.2.14-7.el6_7.1 base 362 k
SDL-static x86_64 1.2.14-7.el6_7.1 base 214 k
Installing for dependencies:
alsa-lib-devel x86_64 1.1.0-4.el6 base 1.1 M
Updating for dependencies:
alsa-lib x86_64 1.1.0-4.el6 base 389 k

Transaction Summary

Install 3 Package(s)
Upgrade 1 Package(s)

Total download size: 2.1 M
Is this ok [y/N]: y
Downloading Packages:
(1/4): SDL-devel-1.2.14-7.el6_7.1.x86_64.rpm | 362 kB 00:03
(2/4): SDL-static-1.2.14-7.el6_7.1.x86_64.rpm | 214 kB 00:02
(3/4): alsa-lib-1.1.0-4.el6.x86_64.rpm | 389 kB 00:02
(4/4): alsa-lib-devel-1.1.0-4.el6.x86_64.rpm | 1.1 MB 00:06


Total 142 kB/s | 2.1 MB 00:15
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : alsa-lib-1.1.0-4.el6.x86_64 1/5
Installing : alsa-lib-devel-1.1.0-4.el6.x86_64 2/5
Installing : SDL-devel-1.2.14-7.el6_7.1.x86_64 3/5
Installing : SDL-static-1.2.14-7.el6_7.1.x86_64 4/5
Cleanup : alsa-lib-1.0.22-3.el6.x86_64 5/5
Verifying : alsa-lib-1.1.0-4.el6.x86_64 1/5
Verifying : alsa-lib-devel-1.1.0-4.el6.x86_64 2/5
Verifying : SDL-static-1.2.14-7.el6_7.1.x86_64 3/5
Verifying : SDL-devel-1.2.14-7.el6_7.1.x86_64 4/5
Verifying : alsa-lib-1.0.22-3.el6.x86_64 5/5

Installed:
SDL-devel.x86_64 0:1.2.14-7.el6_7.1 SDL-static.x86_64 0:1.2.14-7.el6_7.1

Dependency Installed:
alsa-lib-devel.x86_64 0:1.1.0-4.el6

Dependency Updated:
alsa-lib.x86_64 0:1.1.0-4.el6

Complete!

有些软件编译找不到有些文件。 这时就可以执行:
sudo yum install XXX-devel
或进
yum serach XXX查找一下

linux下如何使用rdesktop连接window电脑桌面

如果想用linux连接window电脑,可以试用一下rdesktop.
项目地址:https://github.com/rdesktop/rdesktop

1、编译源码
下载 git clone https://github.com/rdesktop/rdesktop
执行./bootstrap

./configure --prefix=/usr/local/rdesktop

make

编译过程中可能会有一些libgssglue-devel,pcsc-lite-devel需要安装一下。
直接用
yum install libgssglue-devel

yum install pcsc-lite-devel

如果不确定需要安装那一个用yum serach pcsc搜索一下

make install

2、连接电脑桌面
cd /usr/local/rdesktop
./bin/rdesktop windows电脑的IP地址 如10.207.1.16
./bin/rdesktop 10.207.1.16

Autoselected keyboard map en-us
ERROR: connect: Connection refused
 出现以上信息连接失败了,需要把window电脑的远程控制打开
打开控制面板->系统->高级系统设置->远程->远程协助勾选上,远程桌面选择一个允许选项
如果提示需要防火墙,请到控制面板->管理工具->服务->Windows Firewall打开这个服务

rdesktop有很多选项:如果需要什么加在rdesktop后面就可以了

rdesktop: A Remote Desktop Protocol client.
Version 1.8.3post. Copyright (C) 1999-2016 Matthew Chapman et al.
See http://www.rdesktop.org/ for more information.

Usage: ./rdesktop [options] server[:port]
-u: user name
-d: domain
-s: shell / seamless application to start remotely
-c: working directory
-p: password (- to prompt)
-n: client hostname
-k: keyboard layout on server (en-us, de, sv, etc.)
-g: desktop geometry (WxH)
-i: enables smartcard authentication, password is used as pin
-f: full-screen mode
-b: force bitmap updates
-L: local codepage
-A: path to SeamlessRDP shell, this enables SeamlessRDP mode
-B: use BackingStore of X-server (if available)
-e: disable encryption (French TS)
-E: disable encryption from client to server
-m: do not send motion events
-C: use private colour map
-D: hide window manager decorations
-K: keep window manager key bindings
-S: caption button size (single application mode)
-T: window title
-t: disable use of remote ctrl
-N: enable numlock syncronization
-X: embed into another window with a given id.
-a: connection colour depth
-z: enable rdp compression
-x: RDP5 experience (m[odem 28.8], b[roadband], l[an] or hex nr.)
-P: use persistent bitmap caching
-r: enable specified device redirection (this flag can be repeated)
'-r comport:COM1=/dev/ttyS0': enable serial redirection of /dev/ttyS0 to COM1
or COM1=/dev/ttyS0,COM2=/dev/ttyS1
'-r disk:floppy=/mnt/floppy': enable redirection of /mnt/floppy to 'floppy' share
or 'floppy=/mnt/floppy,cdrom=/mnt/cdrom'
'-r clientname=': Set the client name displayed
for redirected disks
'-r lptport:LPT1=/dev/lp0': enable parallel redirection of /dev/lp0 to LPT1
or LPT1=/dev/lp0,LPT2=/dev/lp1
'-r printer:mydeskjet': enable printer redirection
or mydeskjet="HP LaserJet IIIP" to enter server driver as well
'-r sound:[local[:driver[:device]]|off|remote]': enable sound redirection
remote would leave sound on server
available drivers for 'local':
oss: OSS output driver, default device: /dev/dsp or $AUDIODEV
'-r clipboard:[off|PRIMARYCLIPBOARD|CLIPBOARD]': enable clipboard
redirection.
'PRIMARYCLIPBOARD' looks at both PRIMARY and CLIPBOARD
when sending data to server.
'CLIPBOARD' looks at only CLIPBOARD.
'-r scard[:"Scard Name"="Alias Name[;Vendor Name]"[,...]]
example: -r scard:"eToken PRO 00 00"="AKS ifdh 0"
"eToken PRO 00 00" -> Device in linux/Unix enviroment
"AKS ifdh 0" -> Device shown in Windows enviroment
example: -r scard:"eToken PRO 00 00"="AKS ifdh 0;AKS"
"eToken PRO 00 00" -> Device in Linux/Unix enviroment
"AKS ifdh 0" -> Device shown in Windows enviroment
"AKS" -> Device vendor name
-0: attach to console
-4: use RDP version 4
-5: use RDP version 5 (default)
-o: name=value: Adds an additional option to rdesktop.
sc-csp-name Specifies the Crypto Service Provider name which
is used to authenticate the user by smartcard
sc-container-name Specifies the container name, this is usally the username
sc-reader-name Smartcard reader name to use
sc-card-name Specifies the card name of the smartcard to use

g++编译出现a.out: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by a.out)如何解决

linux centos编译cpp文件,出现

a.out: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by a.out)

解决办法如下:

在编译时使用静态链接标准库的方法, 编译时添加 -static-libstdc++选项

g++ stl.cpp  -static-libstdc++

如何配置每天自动切割nginx日志脚本

第一步:在nginx.conf里面把pid配置一下

第二步编写脚本:

/usr/local/nginx/sbin/cut_nginx_log.sh
#!/bin/bash 
# This script run at 00:00 
# The Nginx logs path 
 logs_path="/usr/local/nginx/logs/"
 logs_bak_path="/data/logs/nginx/"
 mkdir -p ${logs_bak_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
 cp ${logs_path}access.log ${logs_bak_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
 rm -rf ${logs_path}*.log
 kill -USR1 `cat /var/run/nginx.pid`

第三步加入到Crond里面

0 0 * * * *  sh /usr/local/nginx/sbin/cut_nginx_log.sh