使用WDK编译环境编译应用程序build命令(对话框程序)

TARGETNAME=Dlg
TARGETTYPE=PROGRAM

SOURCES=Dlg.cpp \
        Dlg.rc

UMENTRY=winmain
USE_MSVCRT = 1

UMTYPE=windows
UMLIBS=$(SDK_LIB_PATH)\gdi32.lib    \
       $(SDK_LIB_PATH)\user32.lib   \
       $(SDK_LIB_PATH)\kernel32.lib \

  $(SDK_LIB_PATH)\Ntdll.lib \

sources文件内容


!INCLUDE $(NTMAKEENV)\makefile.def

makefile文件内容




resource.h文件

//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Dlg.rc
//
#define IDD_DIALOG1                     101
#define IDR_MENU                        102
#define ID__CHECK                       40001
#define ID__EXIT                        40002


// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        102
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1001
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif


Dlg.rc文件内容

--------------------------------------------------------------------------------------------

// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#include <windows.h>


/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//


IDD_DIALOG1 DIALOGEX 0, 0, 316, 183
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,205,162,50,14
    PUSHBUTTON      "Cancel",IDCANCEL,259,162,50,14
END




/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//


#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
    IDD_DIALOG1, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 309
        TOPMARGIN, 7
        BOTTOMMARGIN, 176
    END
END
#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Menu
//


IDR_MENU MENU
BEGIN
    POPUP ""
    BEGIN
        MENUITEM "Check",                       ID__CHECK
        MENUITEM "Exit",                        ID__EXIT
    END
END


/////////////////////////////////////////////////////////////////////////////



Dlg.cpp源文件内容:

--------------------------------------------------------------------------------------------------------------------

#include "resource.h"


HINSTANCE g_hInstance;


INT_PTR CALLBACK DialogProc(
HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_INITDIALOG:
//MessageBox(hwndDlg, TEXT(""), TEXT(""), MB_OK);
break;
case WM_COMMAND:
{
if(wParam == IDOK)
{
EndDialog(hwndDlg, 0);
}
else if(wParam == IDCANCEL)
{
EndDialog(hwndDlg, 0);
}
}
break;
case WM_CONTEXTMENU:
{
HMENU hmenu;            // menu template          
HMENU hmenuTrackPopup;  // shortcut menu   


//  Load the menu template containing the shortcut menu from the 
//  application's resources. 


hmenu = LoadMenu(g_hInstance, MAKEINTRESOURCE(IDR_MENU)); 
if (hmenu == NULL) 
return FALSE; 


// Get the first shortcut menu in the menu template. This is the 
// menu that TrackPopupMenu displays. 


hmenuTrackPopup = GetSubMenu(hmenu, 0); 


// TrackPopup uses screen coordinates, so convert the 
// coordinates of the mouse click to screen coordinates. 
POINT pt;

pt.x = (SHORT)LOWORD(lParam);
pt.y = (SHORT)HIWORD(lParam);


ScreenToClient(hwndDlg, (LPPOINT) &pt); 

// Draw and track the shortcut menu.  
TrackPopupMenu(hmenuTrackPopup, TPM_LEFTALIGN | TPM_LEFTBUTTON, 
pt.x, pt.y, 0, hwndDlg, NULL); 


// Destroy the menu. 
DestroyMenu(hmenu); 


break;
}
break;
}
return 0;
}


int WINAPI WinMain(          
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
g_hInstance = hInstance;
INT_PTR hDlg = DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DialogProc);
return 0;
}


有时间学习学习学习资源文件的语法,将上面的分另保存为: sources、makefile、resource.h、Dlg.rc、Dlg.cpp放到同一目录下,打开WDK编译环境切换到文件存放目录下,输入命令buid -c就可以编译出一个对话框程序。

你可能感兴趣的:(使用WDK编译环境编译应用程序build命令(对话框程序))