Source code:
#include
#include
//Dinh nghia cac icon cua cac nut tren menu
#define IDM_EXIT 6000
#define IDM_OPEN 6001
#define IDM_NEW 6002
#define IDM_SAVE 6003
#define IDM_PRINT 6004
#define IDM_HELP 6005
#define IDM_ABOUT 6006
#define IDC_STATUS 4000
#define IDC_TOOLBAR 4001
#ifndef không quyết định
#define không quyết định (a) (sizeof (a) / sizeof (a [0]))
#endif
//Khai bao ten cho window
const char g_szClassName [] = "myWindowClass";
//Khai bao cac opstion trong window
HWND hStatus, hToolbar;
//Khai bao menu cha va menu con
HMenu hMenu, hMenuT;
// Popup menu Ham
HMenu MakeMenubar (HWND hWnd)
{
HMenu hMenu, hMenuT, hMenuT2;
hMenu = CreateMenu ();
hMenuT = CreatePopupMenu ();
hMenuT2 = CreatePopupMenu ();
AppendMenu (hMenuT, MF_ENABLED | MF_STRING, IDM_OPEN, TEXT ("& Open"));
AppendMenu (hMenuT, MF_ENABLED | MF_STRING, IDM_EXIT, TEXT ("& Exit"));
AppendMenu (hMenu, MF_ENABLED | MF_POPUP, (UINT) hMenuT, TEXT ("& File"));
AppendMenu (hMenuT2, MF_ENABLED | MF_STRING, IDM_ABOUT, TEXT ("& About"));
AppendMenu (hMenu, MF_ENABLED | MF_POPUP, (UINT) hMenuT2, TEXT ("& Help"));
SetMenu (hWnd, hMenu);
trở hMenu;
}
Ham tao // Statusbar
HWND MakeStatusbar (HWND hWnd, UINT WID)
{
HWND hStatus = CreateStatusWindow (WS_CHILD | WS_VISIBLE, // | SBARS_SIZEGRIP,
NULL, hWnd, WID);
trở hStatus;
}
// Ham man Toolbar
HWND MakeToolbar (HWND hWnd, UINT WID)
{
TBBUTTO các Seek [] = {
// {STD_, IDM_, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, 0},
{STD_FILENEW, IDM_NEW, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{STD_FILEOPEN, IDM_OPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{STD_FILESAVE, IDM_SAVE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{STD_PRINTPRE, IDM_PRINT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
// {STD_HELP, IDM_HELP, TBSTATE_ENABLED, TBSTYLE_BUTTON,, 0} 0L,
};
HWND hToolbar = CreateToolbarEx (hWnd,
WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT
, WID, 0, HINST_COMMCTRL, IDB_STD_SMALL_COLOR,
Hãy tìm kiếm, NELEMS (TBB), 100, 0, 30, 30, sizeof (TBBUTTO của));
trở hToolbar;
}
//Ham khoi tao cac menu
BOOL OnCreate (HWND hwnd, LPCREATESTRUCT lpCreateStruct)
{
InitCommonControls ();
hToolbar = MakeToolbar (hwnd, IDC_TOOLBAR);
hStatus = MakeStatusbar (hwnd, IDC_STATUS);
hMenu = MakeMenubar (hwnd);
return 0;
}
// Ham bỏ đơn
khoảng trống OnDestroy (HWND hwnd)
{
(0) PostQuitMessage;
}
//Ham trong muc about
trống theo yêu cầu (HWND hwnd, int id, hwndCtl HWND, mã UINT notifycenter)
{
switch (id) {
trường hợp IDM_ABOUT:
MessageBox (hwnd, "Created by: Xuân Quynh\nFacebook:https://www.facebook.com/groups/learningcplusplus\nEmail:Cplusitech@gmail.com","Athor",MB_OK|MB_ICONINFORMATION);
phá vỡ;
trường hợp IDM_EXIT:
PostMessage (hwnd, WM_CLOSE, 0, 0L);
trở lại;
}
}
// Bước 4: Ham Quy trình Window
LRESULT gọi lại WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
trường hợp WM_COMMAND:
trả lại theo yêu cầu (hwnd, (int) (LOWORD (wParam)) (HWND) (lParam), (UINT) HIWORD (wParam)), 0;
trường hợp WM_LBUTTONDOWN: // hoặc WM_RBUTTONDOWN, WM_MBUTTONDOWN
{// Bắt đầu khối mã
char szFileName [MAX_PATH];
HINSTANCE hInstance = GetModuleHandle (NULL);
GetModuleFileName (hInstance, szFileName, MAX_PATH);
MessageBox(hwnd,szFileName,"Chuong trinh:",MB_OK|MB_ICONINFORMATION);
} // Khối mã cuối
phá vỡ;
trường hợp WM_CLOSE:
DestroyWindow (hwnd);
phá vỡ;
trường hợp điệp WM_DESTROY:
// PostQuitMessage (0);
trở OnDestroy (hwnd), 0;
phá vỡ;
// Thêm sự kiện mới
trường hợp WM_CREATE: trở OnCreate (hwnd, (LPCREATESTRUCT) (lParam)), 0;
phá vỡ;
mặc định:
trả lại hàm DefWindowProc (hwnd, msg, wParam, lParam);
phá vỡ;
}
return 0;
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX nhà vệ sinh;
HWND hwnd;
MSG Msg;
// Bước 1: Đăng ký lớp Window
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (null, IDI_APPLICATION);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = g_szClassName;
wc.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
if (! RegisterClassEx (& wc))
{
MessageBox (NULL, "Cửa sổ đăng ký không thành công!", "Lỗi!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
// Bước 2: Tạo Window
hwnd = CreateWindowEx (
WS_EX_CLIENTEDGE,
g_szClassName,
"Tiêu đề của cửa sổ của tôi",
WS_OVERAPPEDWINDOW,
CW_USEDEFLAULT, CW_USEDEFLAULT, 640, 460,
NULL, NULL, hInstance, NULL);
if (hwnd == NULL)
{
MessageBox (NULL, "Window Creation Không!", "Lỗi!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow (hwnd, nCmdShow);
UpdateWindow (hwnd);
// Bước 3: The Message Vòng
while (GetMessage (& Msg, NULL, 0, 0)> 0)
{
TranslateMessage (& Msg);
DispatchMessage (& Msg);
}
trở Msg.wParam;
}
0 comments:
Post a Comment