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 File Content
! Include $ (ntmakeenv) \ makefile. Def
Makefile content
Resource. h file
// {No_dependencies }}
// Microsoft Visual C ++ generated include file.
// Used by DLG. RC
//
# Define idd_dialog1 101
# Define idr_menu 102
# Define id1_check 40001
# Define id1_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 file content
Bytes --------------------------------------------------------------------------------------------
// Microsoft Visual C ++ generated resource script.
//
# Include "resource. H"
# Include <windows. h>
//////////////////////////////////////// /////////////////////////////////////
//
// Dialog
//
Idd_dialog1 dialogex0, 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
BOT margin, 176
End
End
# Endif // apstudio_invoked
//////////////////////////////////////// /////////////////////////////////////
//
// Menu
//
Idr_menu menu
Begin
Popup ""
Begin
Menuitem "check", id1_check
Menuitem "exit", id1_exit
End
End
//////////////////////////////////////// /////////////////////////////////////
DLG. cpp source file content:
Bytes --------------------------------------------------------------------------------------------------------------------
# Include "resource. H"
Hinstance g_hinstance;
Int_ptr callback dialogproc (
Hwnd hwnddlg,
Uint umsg,
Wparam,
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; // menu Template
Hmenu hmenutrackpopup; // shortcut cut menu
// Load the menu template containing the shortcut cut menu from
// Application's resources.
Hmenu = loadmenu (g_hinstance, makeintresource (idr_menu ));
If (hmenu = NULL)
Return false;
// Get the first shortcut cut menu in the menu template. This is
// Menu that trackpopupmenu displays.
Hmenutrackpopup = getsubmenu (hmenu, 0 );
// Trackpopup uses screen coordinates, so convert
// 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 hprevinstance,
Lpstr lpcmdline,
Int ncmdshow
)
{
G_hinstance = hinstance;
Int_ptr hdlg = dialogbox (hinstance, makeintresource (idd_dialog1), null, dialogproc );
Return 0;
}
You have time to learn the syntax for learning resource files. Save the preceding points as sources and makefile., Resource. h, DLG. RC, DLG. cpp put in the same directory, open the wdk compiling environment switch to the file storage directory, enter the command buid
-C can compile a dialog box program.