Console APP&&WIN32 APP
2010-12-01 23:24
127 查看
http://www.codeproject.com/KB/winsdk/winconsole.aspx
今天在code project上看到了一篇感觉有趣的小代码,分享一下给大家,上面是连接谢谢原作者,感觉这个程序能给人inspiration~~嘿嘿~~
这个对话框并没有定义定义成员数据,其实从本质上说明了一个完整程序的组成:消息循环、主函数、线程、消息处理函数。有人说console app和win32 app最大的区别就是console app没有消息循环。我们也可以根据这个例子来写自己的隐藏进程(for virus?),只要把显示对话框改成别的就行了。
今天在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"); } } |
相关文章推荐
- FTP客户端:FTP Client:win32 console appplication
- .net Lock(this),Lock(obj),Lock("string") console app demo,线程安全
- VS2010+OpenCV2.3.1创建win32 console App 来显示一副图像
- API日志3 (Difs from Win32ap&Win32 Console)
- win32 Console App的多线程小例子
- 基于windows win32 Console App的多线程小例子
- 让 win32 程序也可以从 console 输出信息
- Android APP BlackContact 信息转存<1>
- Android ApiDemos示例解析(36):App->Search->Invoke Search
- 个人APP开发者现状:处于过渡阶段&nbsp;…
- Android App 注射&&Drozer Use
- pywin32-217 安装异常解决 No files match 'pythonwin\pywin\*.cfg
- "AppDelegate.h" 和"AppDelegate.cpp" 分析
- 让Win32程序也可以从console输出信息
- webapp mui & HTML5+ (四) 之 窗口(页面初始化、跳转、传参)
- Android ApiDemos示例解析(31):App->Preferences->Launching preferences
- Adding appsettings.json to a .NET Core console app
- Weblogic Console Fails to Start Managed Servers With<BEA-000286> <Failed to invoke startup class
- 'Could not load NIB in bundle: 'NSBundle < /Bundle/Application/ .app> (loaded)' with name 'Car
- Error:Could not read entry ':app:processDebugManifest' from cache taskArtifacts.bin