yz454170989 2015-08-19 01:51 采纳率: 52.6%
浏览 1763
已采纳

这个l两windows程序如何在vs2013中运行

一本老书附带的 刚开始看,运行不了它的程序
怎样可以在vs中运行,我需要学些什么可以搞定它
#include

//-----------------------------------------------------------------------
//

// Name: HelloWorld example project
//

// Author: Mat Buckland 2002
//
// Desc: HelloWorld in a dialogue box
//
//------------------------------------------------------------------------

int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MessageBox(NULL, "Hello World!", "MsgBox", 0);

return 0;

}

#include

#include "defines.h"

//-----------------------------------------------------------------------
//

// Name: HelloWorld2 example project
//

// Author: Mat Buckland 2002
//
// Desc: Demonstration of (useless) window creation!
//
//------------------------------------------------------------------------
//--------------------------------- Globals ------------------------------
//
//------------------------------------------------------------------------

char* g_szApplicationName = "Hello World!";
char* g_szWindowClassName = "MyWindowClass";

//---------------------------- WindowProc ---------------------------------
//

// This is the callback function which handles all the windows messages.
// I'll be talking about this function in much more detail when we get
// to the HelloWorld3 example. All you neeed to know for now is that this
// function has to exist for this example to run!
//-------------------------------------------------------------------------

LRESULT CALLBACK WindowProc (HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{

     return DefWindowProc (hwnd, msg, wParam, lParam);

}

//-------------------------------- WinMain -------------------------------
//
// The entry point of the windows program
//------------------------------------------------------------------------
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR szCmdLine,
int iCmdShow)
{
//handle to our window
HWND hWnd;

     //our window class structure
     WNDCLASSEX     winclass;

 // first fill in the window class stucture
   winclass.cbSize        = sizeof(WNDCLASSEX);
   winclass.style         = CS_HREDRAW | CS_VREDRAW;
 winclass.lpfnWndProc   = WindowProc;
 winclass.cbClsExtra    = 0;
 winclass.cbWndExtra    = 0;
 winclass.hInstance     = hInstance;
 winclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
 winclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
 winclass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
 winclass.lpszMenuName  = NULL;
 winclass.lpszClassName = g_szWindowClassName;
   winclass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

     //register the window class
    if (!RegisterClassEx(&winclass))
    {
        MessageBox(NULL, "Class Registration Failed!", "Error", 0);

        //exit the application
        return 0;
    }

     //create the window and assign its ID to hwnd    
 hWnd = CreateWindowEx (NULL,                 // extended style
                        g_szWindowClassName,  // window class name
                        g_szApplicationName,  // window caption
                        WS_OVERLAPPEDWINDOW,  // window style
                        0,                    // initial x position
                        0,                    // initial y position
                        WINDOW_WIDTH,         // initial x size
                        WINDOW_HEIGHT,        // initial y size
                        NULL,                 // parent window handle
                        NULL,                 // window menu handle
                        hInstance,            // program instance handle
                        NULL);                // creation parameters

 //make sure the window creation has gone OK
 if(!hWnd)
 {
   MessageBox(NULL, "CreateWindowEx Failed!", "Error!", 0);
 }

 //make the window visible
     ShowWindow (hWnd, iCmdShow);

 UpdateWindow(hWnd);

 UnregisterClass( g_szWindowClassName, winclass.hInstance );

 return 0;

}

  • 写回答

1条回答 默认 最新

  • oyljerry 2015-08-19 06:45
    关注

    主要是Unicode字符集的问题,所以字符串的地方用_T()

     MessageBox(NULL, _T("Hello World!")", _T("MsgBox"), 0);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码