通过GUI方式打印信息

由于更改入口后就不允许调用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;
}

转载于:https://www.cnblogs.com/microsoftxiao/archive/2007/05/14/746195.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值