• Win32 SDK(对话框程序)


    #include <Windows.h>
    #include <tchar.h>
    #include "resource.h"

    TCHAR DlgName[]=TEXT("MyDialog");
    TCHAR AppName[]=TEXT("Dialog");;
    //TCHAR TestString[]=TEXT("hello world");

    TCHAR buffer1[512];
    TCHAR buffer2[512];
    TCHAR *buffer3=NULL;
    int a=0,b=0,c=0;
    HINSTANCE g_hInstance;

    INT_PTR CALLBACK WinProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam);

    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
    {
    g_hInstance=hInstance;
    DialogBoxParam(hInstance,DlgName,NULL,(DLGPROC)WinProc,NULL);
    return 0;
    }

    INT_PTR CALLBACK WinProc(HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam)
    {
    switch(Msg)
    {
    case WM_INITDIALOG:
    SetFocus(GetDlgItem(hWnd,IDC_EDIT1));
    break;
    case WM_COMMAND:
    if (lParam==0)
    {
    switch(wParam)
    {
    case ID_TESTCONTROL_GETTEXT:
    GetDlgItemText(hWnd,IDC_EDIT1,buffer3,512);
    MessageBox(hWnd,buffer3,AppName,MB_OK);
    break;
    case ID_TESTCONTROL_CLEARTEXT:
    SetDlgItemText(hWnd,IDC_EDIT1,NULL);
    SetDlgItemText(hWnd,IDC_EDIT2,NULL);
    SetDlgItemText(hWnd,IDC_EDIT3,NULL);
    break;
    case ID_TESTCONTROL_EXIT:
    EndDialog(hWnd,NULL);
    break;
    }
    }
    else
    {
    if (HIWORD(wParam)==BN_CLICKED)
    {
    switch(LOWORD(wParam))
    {
    case IDOK:
    GetDlgItemText(hWnd,IDC_EDIT1,buffer1,512);
    GetDlgItemText(hWnd,IDC_EDIT2,buffer2,512);
    a=_ttoi(buffer1);
    b=_ttoi(buffer2);
    c=a+b;
    // buffer3=;
    SetDlgItemText(hWnd,IDC_EDIT3,buffer3);
    break;
    case IDCANCEL:
    EndDialog(hWnd,NULL);
    break;
    }

    }
    }
    break;
    default:
    return FALSE;
    }
    return TRUE;


    }

    ***.rc:

    MYDIALOG DIALOGEX 0, 0, 419, 204
    STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
    CAPTION "Dialog"
    MENU IDR_MENU2
    FONT 8, "MS Shell Dlg", 400, 0, 0x1
    BEGIN
    DEFPUSHBUTTON "确定",IDOK,181,10,50,14
    PUSHBUTTON "取消",IDCANCEL,185,31,50,14
    EDITTEXT IDC_EDIT1,27,9,50,17,ES_AUTOHSCROLL
    EDITTEXT IDC_EDIT2,101,8,52,18,ES_AUTOHSCROLL
    EDITTEXT IDC_EDIT3,63,35,51,17,ES_AUTOHSCROLL
    CONTROL "",IDC_STATIC,"Static",SS_BLACKFRAME,101,71,175,110
    END


    /////////////////////////////////////////////////////////////////////////////
    //
    // Menu
    //

    IDR_MENU2 MENU
    BEGIN
    POPUP "test control"
    BEGIN
    MENUITEM "get text", ID_TESTCONTROL_GETTEXT
    MENUITEM "clear text", ID_TESTCONTROL_CLEARTEXT
    MENUITEM "exit", ID_TESTCONTROL_EXIT
    END
    END

    ***.h:

    #define IDD_DIALOG1                     101
    #define IDR_MENU1 102
    #define IDR_MENU2 103
    #define IDC_EDIT1 1001
    #define IDC_EDIT2 1002
    #define IDC_EDIT3 1003
    #define ID_TESTCONTROL_GETTEXT 40001
    #define ID_TESTCONTROL_CLEARTEXT 40002
    #define ID_TESTCONTROL_EXIT 40003

    // Next default values for new objects
    //
    #ifdef APSTUDIO_INVOKED
    #ifndef APSTUDIO_READONLY_SYMBOLS
    #define _APS_NEXT_RESOURCE_VALUE 104
    #define _APS_NEXT_COMMAND_VALUE 40004
    #define _APS_NEXT_CONTROL_VALUE 1004
    #define _APS_NEXT_SYMED_VALUE 101
    #endif
    #endif




  • 相关阅读:
    css盒模型不同浏览器下解释不同 解决办法
    【META http-equiv="Content-Type" Content="text/html; Charset=*】意义详解
    淘宝2015年秋招在线笔试题
    mouseleave mouseout时候悬浮框不应该消失的时候消失了 css 解决办法
    ACM知识点分类
    2019牛客多校第九场 B.Quadratic equation
    扫描线算法
    可持久化数据结构(模板)
    luogu SP3267 DQUERY
    luogu2633 Count on a tree(树上LCA+主席树求区间第k小)
  • 原文地址:https://www.cnblogs.com/tiandsp/p/2400494.html
Copyright © 2020-2023  润新知