修改我的第一個項目(Visual C++ 6.0)

第一步:打開我創建的.cpp文件

第二步:用下面的代碼替換頭文件

在這裏插入圖片描述

#include "stdafx.h"
#include <tchar.h>
#include<stdlib.h>
#include<string.h>
#include <Windows.h>
#include<stdio.h>
#include"resource.h" 
#include <Windowsx.h>
#include<commdlg.h>
#include<mmsystem.h>
#pragma comment(lib, "winmm")
#define MAX_LOADSTRING 100

第三步:用下面的代碼替換 WinMain( ) 函數

在這裏插入圖片描述

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	MSG msg;
// 創建主對話框,用CreateDialog創建的是非模態對話框,而DialogBox則是模態對話框,自己參考MSDN
	HWND hMain = NULL;
	hMain = CreateDialog( hInstance, (LPCTSTR)( IDD_ABOUTBOX ), NULL, (DLGPROC)About );
	::SetWindowPos( hMain, HWND_TOP, 250,200, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
	// ShowWindow( hMain, SW_SHOW) //?有了上邊一句,這個就不用啦
	::UpdateWindow( hMain );

	if( NULL == hMain )
	{
		::MessageBox( NULL, "CreateWindow error", "error", MB_OK );
		return -1;
	}
	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if( !::IsDialogMessage( hMain, &msg ) )
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
	return msg.wParam;
	}

第四步:到最後的地方修改一條語句(終止對話框)

在這裏插入圖片描述

ok了 隨後編譯運行一下即可

在這裏插入圖片描述
將出來這個東西:這可是我們自己寫的對話框哦!
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章