打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
如何在win32控制台加入MFC对话框(Adding Windows To Your Console Application)
[c-sharp] view plaincopy
  1. // define _MT so that _beginthread( ) is available   
  2. #ifndef _MT   
  3. #define _MT   
  4. #endif   
  5.  
  6. #include "stdio.h"   
  7. #include "windows.h"   
  8. #include "process.h"   
  9. #include "resource.h"   
  10.   
  11. // global flag   
  12. bool bDone = false;   
  13.   
  14. // this function is called by a new thread   
  15. void InputThreadProc( void *dummy )   
  16. {   
  17.     // create the dialog window   
  18.     HWNDhWnd = ::CreateDialog(NULL,  
  19.         MAKEINTRESOURCE(IDD_DIALOG),NULL,NULL);   
  20.     if ( hWnd!=NULL )   
  21.     {   
  22.         // show dialog   
  23.         ::ShowWindow(hWnd,SW_SHOW);   
  24.     }   
  25.     else   
  26.     {   
  27.         printf("Failed to create dialog/n");   
  28.         bDone = true;   
  29.         return;   
  30.     }   
  31.     // message loop to process user input   
  32.     MSG msg;   
  33.     while(1)   
  34.     {   
  35.         if ( ::PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE) )   
  36.         {   
  37.             if ( msg.message==WM_KEYUP )   
  38.             {   
  39.                 int nVirtKey = (int) msg.wParam;   
  40.                 // if the user pressed the ESCAPE key, then   
  41.                 // print the text the user entered and quit   
  42.                 if ( nVirtKey==VK_ESCAPE )   
  43.                 {   
  44.                     // get the edit control   
  45.                     HWND hEdit = ::GetDlgItem(hWnd,IDC_EDIT);   
  46.                     if ( hEdit )   
  47.                     {   
  48.                         // get the input text the user entered   
  49.                         // and print it to the console window   
  50.                         char pText[3201];   
  51.                         int nSize = ::GetWindowText( hEdit,   
  52.                             pText, 3200 );   
  53.                         pText[nSize] = 0;   
  54.                         printf("/nYou have entered the ");   
  55.                         printf("following text in a second ");  
  56.                         printf("thread:/n/n%s/n/n",pText);  
  57.                     }   
  58.                     else   
  59.                     {   
  60.                         printf("Failed to get edit control/n");   
  61.                     }   
  62.                     // destroy the dialog and get out of  
  63.                     // the message loop   
  64.                     ::DestroyWindow(hWnd);   
  65.                     bDone = true;   
  66.                     break;   
  67.                 }   
  68.             }   
  69.             // process message   
  70.             ::TranslateMessage(&msg);   
  71.             ::DispatchMessage(&msg);   
  72.         }   
  73.         else   
  74.         {   
  75.             // if there is no message to process,   
  76.             // then sleep for a while to avoid burning   
  77.             // too much CPU cycles   
  78.             ::Sleep(100);   
  79.         }   
  80.     }   
  81. }   
  82.   
  83. void main( int argc, char** argv )   
  84. {   
  85.     printf("Hello, world of console apps/n");   
  86.     // create a new thread to allow user input   
  87.     if( _beginthread(InputThreadProc, 0, NULL )==-1)   
  88.     {   
  89.         printf("Failed to create thread");   
  90.         return;   
  91.     }   
  92.     // wait for the new thread to finish   
  93.     while ( !bDone )   
  94.     {   
  95.         // sleep 3 seonds   
  96.         ::Sleep(3000);   
  97.         printf("main thread running/n");   
  98.     }   
  99. }   
  100.   
  101. /************************** end ************************/   
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
电脑操作必会的21个神技巧
这3种记忆方法,可以让你过目不忘
女人聊“暗号”,你知道多少,收藏起来看看吧
月球上遍地是氦
高中数学149个解题方法
梦在,情在,何惧岁月老
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服