Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

C Snippet #8(¹æ¶¨Ê±¼äÊäÈ룬·ñÔòĬÈÏÌøתµÄʵÏÖ)

http://www.ddj.com/cpp/221600722
Q: HOW DO I... put timers with default actions in my C code?
A: Many times, we need to write programs that will only wait a certain specified amount of time for a user to do something. After that time, we need to assume that the user isn't going to do anything and move on to some specified default action. This Snippet works exactly like the get_ch() function in most PC C compiler libraries, except that it will only wait as long as you tell it for the user to hit a key. If no key is pressed within the time limit, the function returns with an EOF. As usual, a test harness has been added to allow for stand-alone testing. To compile the stand-alone test, simply define the TEST macro.
/*
** TIMEGETC.C - waits for a given number of seconds for the user to press
** a key. Returns the key pressed, or EOF if time expires
**
** Public domain by Bob Jarvis
** Test harness added by Bob Stout
**
** Note: This relies on the non-standard kbhit() function, which is available
** in all Windows PC compilers - including MinGW32 (gcc).
*/
#include <stdio.h>
#include <time.h>
#include <conio.h>
int timed_getch(int n_seconds)
{
time_t start, now;
start = time(NULL);
now = start;
while(difftime(now, start) < (double)n_seconds && !kbhit())
{
now = time(NULL);
}
if(kbhit())
return getch();
else return EOF;
}
#ifdef TEST
main()
{
int c;
const char *ctrlchars[] =
{
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
"BS_", "HT_", "LF_", "VT_", "FF_", "CR_", "SO_", "SI_",
"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
"CAN", "EM_", "SUB", "ESC", "FS_", "GS_", "RS_", "US_"
};

printf("Starting a 5 second delay...\n");
c = timed_getch(5);
if(c == EOF)
printf("Timer expired\n


Ïà¹ØÎĵµ£º

C++³ÌÐòµ÷ÓÃCº¯Êý

ÕâÖÖÐèÇóºÜ¶à,ÓÖÒòΪC++ºÍCÊÇÁ½ÖÖÍêÈ«²»Í¬µÄ±àÒëÁ´½Ó´¦Àí·½Ê½,ËùÒÔÒªÉÔ¼Ó´¦Àí.×ܽá´óÖÂÓÐÁ½´óÀàʵÏÖ·½·¨.
ÎÄÖиø³öµÄÊÇÍêÕûµÄ,¾ßÌåµÄ,µ«ÓÖ×î»ù±¾×î¼òµ¥µÄʵÏÖ,ÖÁÓÚÀíÂÛÐԵĶ«Î÷ÔÚÍøÉϺÜÈÝÒ×ËÑË÷µÄµ½.
Ò».ͨ¹ý´¦Àí±»µ÷ÓõÄCÍ·Îļþ
a.h:
#ifndef __A_H
#define __A_H
#ifdef __cplusplus
extern "C" {
#endif
int Th ......

C Sharp ÏÞÖÆÐÞÊηû

public¿ÉÒÔ±»ÈÎÒâ´æÈ¡£»
protectedÖ»¿ÉÒÔ±»±¾ÀàºÍÆä¼Ì³Ð×ÓÀà´æÈ¡£»
internalÖ»¿ÉÒÔ±»±¾×éºÏÌ壨Assembly£©ÄÚËùÓеÄÀà´æÈ¡£¬×éºÏÌåÊÇC#ÓïÑÔÖÐÀà±»×éºÏºóµÄÂß¼­µ¥Î»ºÍÎïÀíµ¥Î»£¬Æä±àÒëºóµÄÎļþÀ©Õ¹ÃûÍùÍùÊÇ“.DLL”»ò“.EXE”¡£
protected internalΨһµÄÒ»ÖÖ×éºÏÏÞÖÆÐÞÊηû£¬ËüÖ»¿ÉÒÔ±»±¾×éºÏÌåÄÚ ......

C/C++»ù±¾Êý¾ÝÀàÐÍ

ѧÁËCÈ»ºóC++£¬È»ºóMFC/Windows,È»ºóÊÇC#,ÆäÖÐÊý¾ÝÀàÐͺܶ࣬ÓÉ»ù±¾ÀàÐÍÑÜÉúµÄtypedefÀàÐÍÒ²N¶à¡£ÊìÖª»ù±¾Êý¾ÝÀàÐÍÊÇÎÒÃÇÕýÈ·±í´ïʵ¼ÊÎÊÌâÖи÷ÖÖÊý¾ÝµÄÇ°ÌᣬÒò´ËÎÒ·ÖÀà×ܽáÁËÒ»ÏÂC/C++/Windows /C#»ù±¾Êý¾ÝÀàÐÍ£¬ÒÔ±ãÈÕºó²éÔÄ¡£
         ANSI C/C++»ù±¾Êý¾ÝÀàÐÍ£º
Type
Size ......

C#ÀàºÍC#½á¹¹ÌåµÄ¹Øϵ

C#ÀࣺÀàÊÇC# Öй¦ÄÜ×îΪǿ´óµÄÊý¾ÝÀàÐÍ£¬ÀàÒ²¶¨ÒåÁËÊý¾ÝÀàÐ͵ÄÊý¾ÝºÍÐÐΪ¡£È»ºó£¬³ÌÐòÔ±¿ÉÒÔ´´½¨×÷Ϊ´ËÀàµÄʵÀýµÄ¶ÔÏó¡£
C#½á¹¹Ì壺½á¹¹ÌåÊÇÇáÁ¿Ð͵ÄÀ࣬ʹÓÿªÏúÏà¶ÔÓÚÀà½ÏС¡£
C#ÀàºÍC#½á¹¹ÌåÁ½ÕߵĹØϵ£º
1.Êý¾ÝÀàÐÍ£ºÀàºÍ½á¹¹Ì嶼ÊÇÊý¾ÝÀàÐÍ£¬ÀàÊÇÒýÓÃÀàÐÍ£¬½á¹¹ÌåÊÇÖµÀàÐÍ¡£
2.¼Ì³ÐÐÔ£ºÀà¿ÉÒԼ̳кͱ»¼Ì³Ð£¬¶ø½á¹ ......

ÔÚÆÁÄ»ÉÏ»­Í¼µÄC££ÊµÏÖ´úÂë


DllImportËùÔÚµÄÃû×Ö¿Õ¼ä using System.Runtime.InteropServices;
[DllImport("User32.dll")]
        public extern static System.IntPtr GetDC(System.IntPtr hWnd);   
        private void button19_Click(obj ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ