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顺眼多了

  • 相关阅读:
    [Agc081F/At2699] Flip and Rectangles
    [CF1216C] White Sheet
    stegsolve使用探究
    栅栏密码
    wireshark常用命令
    某团队线下赛AWD writeup&Beescms_V4.0代码审计
    某线下赛AWD
    BBScan — 一个信息泄漏批量扫描脚本
    ISG2018 web题Writeup
    巅峰极客第二场CTF部分writeup
  • 原文地址:https://www.cnblogs.com/wonderKK/p/2240252.html
Copyright © 2011-2022 走看看