Win32 SDK (dialog box Program)

Source: Internet
Author: User
#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 "OK", idok, 181,10, 50,14
Pushbutton "cancel", idcancel
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, 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.