Console APP&&WIN32 APP
来源:互联网 发布:软件开发报价单模板 编辑:程序博客网 时间:2024/04/20 11:12
http://www.codeproject.com/KB/winsdk/winconsole.aspx
今天在code project上看到了一篇感觉有趣的小代码,分享一下给大家,上面是连接谢谢原作者,感觉这个程序能给人inspiration~~嘿嘿~~
//resource.h
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by test.rc
//
#define IDD_DIALOG 101
#define IDC_EDIT 1001
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
//main.cpp
// define _MT so that _beginthread( ) is available
#ifndef _MT
#define _MT
#endif
#include
#include
#include
#include "resource.h"
// global flag
bool bDone = false;
// this function is called by a new thread
void InputThreadProc( void *dummy )
{
// create the dialog window
HWND hWnd = ::CreateDialog(NULL,MAKEINTRESOURCE(IDD_DIALOG),NULL,NULL);
if(hWnd!=NULL)
{
// show dialog
::ShowWindow(hWnd,SW_SHOW);
}
else
{
printf("Failed to create dialog/n");
bDone = true;
return;
}
// message loop to process user input
MSG msg;
while(1)
{
if(::PeekMessage(&msg,hWnd,0,0,PM_REMOVE))
{
if(msg.message==WM_KEYUP)
{
int nVirtKey = (int)msg.wParam;
// if the user pressed the ESCAPE key, then
// print the text the user entered and quit
if(nVirtKey==VK_ESCAPE)
{
// get the edit control
HWND hEdit = ::GetDlgItem(hWnd,IDC_EDIT);
if(hEdit)
{
// get the input text the user entered and print
// it to the console window
char pText[3201];
int nSize = ::GetWindowText(hEdit,pText,3200);
pText[nSize] = 0;
printf("/nYou have entered the following text in a second thread:/n/n%s/n/n",pText);
}
else
{
printf("Failed to get edit control/n");
}
// destroy the dialog and get out of the message loop
::DestroyWindow(hWnd);
bDone = true;
break;
}
}
// process message
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
else
{
// if there is no message to process,
// then sleep for a while to avoid burning
// too much CPU cycles
::Sleep(100);
}
}
}
void main( int argc, char** argv )
{
printf("Hello, world of console apps/n");
// create a new thread to allow user input
if(_beginthread(InputThreadProc, 0, NULL )==-1)
{
printf("Failed to create thread");
return;
}
// wait for the new thread to finish
while(!bDone)
{
// sleep 3 seonds
::Sleep(3000);
printf("main thread running/n");
}
}
这个对话框并没有定义定义成员数据,其实从本质上说明了一个完整程序的组成:消息循环、主函数、线程、消息处理函数。有人说console app和win32 app最大的区别就是console app没有消息循环。我们也可以根据这个例子来写自己的隐藏进程(for virus?),只要把显示对话框改成别的就行了。
- Console APP&&WIN32 APP
- win32 Console App的多线程小例子
- 基于windows win32 Console App的多线程小例子
- VS2010+OpenCV2.3.1创建win32 console App 来显示一副图像
- Win32 app 概念程序
- Symfony2 app console 命令收集
- C#-电话本-Console App---ShinePans
- Get the command parameters in Win app and Console app
- First WCF App (Host in Console Application)
- 在console.app中查看crash log
- Maven项目管理实战(一)--Console App
- [c# metro app] debug output to console
- win32 console
- App
- app
- app
- App
- app
- 几个重要的算法设计技术
- 整数溢出
- 资料..
- 正则表达式验证日期(YYYY/MM/DD HH)
- zoj 2777 || poj 3090 Visible Lattice Points
- Console APP&&WIN32 APP
- 使用光盘+winpe
- VC创建删除线程
- php正则取img标记中alt src width heigh属性
- 光脚丫学LINQ(041):使用对象关系设计器修改映射关系
- Linux系统自动化管理: 远程登录
- 使用log4net记录日志到数据库(含有自定义属性)
- Expect 在网络管理中发挥着重要作用
- Struts2 错误Unable to load configuration. - action