zoukankan      html  css  js  c++  java
  • 基于wnidowAPI的对话框应用程序框架

    #include "resource.h"


    LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);

    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;
    }






    // 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));//只用这个的话,只会关闭对话框,但是没有关闭应用程序
    PostQuitMessage( 0 );
    return TRUE;
    }
    break;
    }
    return FALSE;
    }


    实在不怎么喜欢MFC。。API顺眼多了

  • 相关阅读:
    jquery之实例应用
    jquery之文档操作
    jquery之css操作
    jquery属性的操作
    jquery筛选器
    jquery选择器之表单选择表单对象属性
    jquery选择器之属性选择器
    jquery选择器之子元素
    数位dp基础
    Leetcode 5195. 最长快乐字符串(贪心)
  • 原文地址:https://www.cnblogs.com/wonderKK/p/2240252.html
Copyright © 2011-2022 走看看