Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Trang 1 của 2 12 CuốiCuối
Kết quả 1 đến 10 của 13
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    Window và Dialog khác nhau chỗ nào ?

    Tớ thấy có 2 cách tạo cửa sổ:
    Một là dùng lệnh CreateWindow
    Hai là dùng lệnh ShowDialog, thiết kế cái dialog ở trong file Resource.
    Hai cái này có giống nhau không. Nếu không thì chúng khác nhau như thế nào
    Cảm ơn trước

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    1 cái của MFC 1 cái của win32API

  3. #3
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Trích dẫn Gửi bởi Cpro
    1 cái của MFC 1 cái của win32API
    Cái Dialog cũng dùng trong WinAPI được mà.[IMG]images/smilies/laughing.gif[/IMG]

  4. #4
    Ngày tham gia
    Sep 2015
    Đang ở
    hà nội
    Bài viết
    0
    nhưng mà showdilog có trong win32API đâu

  5. #5
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Trích dẫn Gửi bởi Cpro
    1 cái của MFC 1 cái của win32API
    Cứ Dialog là MFC à.
    MFC không từ WinAPI à ?

    [IMG]images/smilies/21.gif[/IMG] mình kém quá, giờ mình mới biết cái này. Mở mang tầm mắt.
    Thank anh Pro [IMG]images/smilies/2.gif[/IMG]

  6. #6
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Trích dẫn Gửi bởi Cpro
    nhưng mà showdilog có trong win32API đâu
    Cãi nhau với ông này chán quá.
    Mã nguồn PHP:
    // Thu3.cpp : Defines the entry point for the application.//#include "stdafx.h"#include "resource.h"#define MAX_LOADSTRING 100// Global Variables:HINSTANCE hInst; // current instanceTCHAR szTitle[MAX_LOADSTRING]; // The title bar textTCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text// Foward declarations of functions included in this code module:ATOM MyRegisterClass(HINSTANCE hInstance);BOOL InitInstance(HINSTANCE, int);LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ // TODO: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_THU3, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_THU3); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam;}//// FUNCTION: MyRegisterClass()//// PURPOSE: Registers the window class.//// COMMENTS://// This function and its usage is only necessary if you want this code// to be compatible with Win32 systems prior to the 'RegisterClassEx'// function that was added to Windows 95. It is important to call this function// so that the application will get 'well formed' small icons associated// with it.//ATOM MyRegisterClass(HINSTANCE hInstance){ WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_THU3); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = (LPCSTR)IDC_THU3; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex);}//// FUNCTION: InitInstance(HANDLE, int)//// PURPOSE: Saves instance handle and creates main window//// COMMENTS://// In this function, we save the instance handle in a global variable and// create and display the main program window.//BOOL InitInstance(HINSTANCE hInstance, int nCmdShow){ HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE;}//// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)//// PURPOSE: Processes messages for the main window.//// WM_COMMAND - process the application menu// WM_PAINT - Paint the main window// WM_DESTROY - post a quit message and return////LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_DIALOG1, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... RECT rt; GetClientRect(hWnd, &rt); DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); EndPaint(hWnd, &ps); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0;}// Mesage handler for about box.LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){ switch (message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; } return FALSE;}  
    Chép nguyên cái ứng dụng WinAPI mẫu trong VC++ 6 ra đó, xem đi [IMG]images/smiliesot_talking.gif[/IMG]
    Nhầm: Lệnh DialogBox [IMG]images/smilies/biggrin.png[/IMG]

  7. #7
    Trích dẫn Gửi bởi dungcoi
    Cứ Dialog là MFC à.
    MFC không từ WinAPI à ?

    [IMG]images/smilies/21.gif[/IMG] mình kém quá, giờ mình mới biết cái này. Mở mang tầm mắt.
    Thank anh Pro [IMG]images/smilies/2.gif[/IMG]
    win32 đương nhiên là có dialog mà bạn,éc éc,mình nói lại là Hàm ShowDialog nằm trong class Cdialog của MFC,win32API khong có hàm này,nếu ai dùng win32API để tạo dialog phải sử dụng hàm CreateWindow để tạo dialog,còn các hàm API sử dụng trong MFC thì rất thoải mái,chỉ cần thêm dấu :: là OK



    Chép nguyên cái ứng dụng WinAPI mẫu trong VC++ 6 ra đó, xem đi
    Nhầm: Lệnh DialogBox
    cậu đưa cái source này lên làm gì,đây là tạo dialog trong win32API ai mà chả biết,giỏi thì gọi hàm Showdialog mà không sử dụng thư viện afxwin.h xem

  8. #8
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Trích dẫn Gửi bởi vduck
    Tớ thấy có 2 cách tạo cửa sổ:
    Một là dùng lệnh CreateWindow
    Hai là dùng lệnh DialogBox, thiết kế cái dialog ở trong file Resource.
    Hai cái này có giống nhau không. Nếu không thì chúng khác nhau như thế nào
    Cảm ơn trước
    Đây là câu hỏi của mình [IMG]images/smiliesot_talking.gif[/IMG]

  9. #9
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Theo ý kiến của mình:
    40px
    Mã:
    Tớ thấy có 2 cách tạo cửa sổ:
    Một là dùng lệnh CreateWindow
    Hai là dùng lệnh DialogBox, thiết kế cái dialog ở trong file Resource.
    Hai cái này có giống nhau không. Nếu không thì chúng khác nhau như thế nào
    Cảm ơn trước
    Thực ra có nhiều hơn 2 [IMG]images/smilies/biggrin.png[/IMG]
    Hai lệnh này khác nhau:
    CreateWindow có thể tạo ra nhiều "thứ" khác nữa trong khi DialogBox chỉ hiển thị 1 dialog đã được thiết kế và lưu trong resource ra màn hình.

  10. #10
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Khác nhau ở chỗ dialogbox thiết kế ở resource nên dễ làm hơn, còn CreateWindow thì phải tự định vị trí các kiểu mệt lắm, và quan trọng nhất là với CreateWindow thì có 1 cái tên class do mình đặt, còn dialogbox thì tên class duy nhất là "#32770" [IMG]images/smilies/biggrin.png[/IMG]

 

 
Trang 1 của 2 12 CuốiCuối

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •