现在的位置: 首页 > 综合 > 正文

通过GUI方式打印信息

2013年02月16日 ⁄ 综合 ⁄ 共 1222字 ⁄ 字号 评论关闭

由于更改入口后就不允许调用CRT运行时库了,所以不得以改为使用
图形方式输出了。

更好的方式是采用Dialog加编辑框方式。
#include <windows.h>
#include <iostream>
using namespace std;

#pragma comment(linker, "/subsystem:WINDOWS")
#pragma comment(linker, "/ENTRY:main")

int main();

void EntryPoint()
{
      main();
}

#define SAFE_DELAPIHEAP(M_HDL,p) { if((p)!=NULL) { HeapFree((M_HDL), 0, (void*)(p)); }}

char* g_szBuf = NULL;
int   g_bufSize = 260;
const int   g_GUILines = 50;

void GetStrText(HANDLE param_hdl, char* szText)
{
     int size = lstrlen(szText);
  g_bufSize = g_bufSize + size;

  char* buf = NULL;
     buf = (char*)HeapAlloc(param_hdl, 0, g_bufSize);
  if(buf != NULL)
  {
      lstrcpy(buf, g_szBuf);
   lstrcat(buf, szText);

      // Ò»´ÎÐÔÌî³äµ½È«¾Ö»º³åÇø
   SAFE_DELAPIHEAP(param_hdl, g_szBuf);
      g_szBuf = (char*)HeapAlloc(param_hdl, 0, g_bufSize);
   if(g_szBuf!=NULL){
     lstrcpy(g_szBuf, buf);
   }
  }
     // ɾ³ýÁÙʱ¿Õ¼ä
  SAFE_DELAPIHEAP(param_hdl, buf);    
}

 

int main()
{
 HANDLE hdl = GetProcessHeap();
 g_szBuf = (char*)HeapAlloc(hdl, 0, g_bufSize);
    lstrcpy(g_szBuf, " ");
 
    GetStrText(hdl, "Hello World");
 GetStrText(hdl ," IBM\n");
 GetStrText(hdl, "Thank you all the same\n");
   
 for(int i=0;i<g_GUILines;++i) {
  char tmpBuf[260] = {0};
  wsprintf(tmpBuf, "%s\n", "Hello World");
  GetStrText(hdl, tmpBuf);
 }

    MessageBox(NULL, g_szBuf, 0, 0);
   
 SAFE_DELAPIHEAP(hdl, g_szBuf);
 
 return 0;
}

抱歉!评论已关闭.