​​

Dialog

//resource.h

#define IDD_DIALOG_MAIN 101
#define IDI_ICON_SMALL 102
#define IDI_ICON_BIG 103
#define IDC_EDIT_UserName 1000
#define IDC_EDIT_PassWord 1001
#define IDC_BUTTON_OK 1002
#define IDC_BUTTON_ERROR 1003


// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1008
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif



//
DiaLogBox.cpp : Defines the entry point for the application. // #include "stdafx.h" #include"resource.h" BOOL CALLBACK DialogProc( HWND hwndDlg, // handle to dialog box UINT uMsg, // message WPARAM wParam, // first message parameter LPARAM lParam // second message parameter ) { HWND hEditUser = NULL; HWND hEditPass = NULL; switch(uMsg) { case WM_INITDIALOG :

      hSmallIcon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_ICON_SMALL));
      hBigIcon = LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_ICON_BIG));

      SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (DWORD)hSmallIcon);
      SendMessage(hwndDlg, WM_SETICON, ICON_BIG, (DWORD)hBigIcon);

return TRUE ;                            
                                    
    case  WM_COMMAND:                                
                                    
        switch (LOWORD (wParam))                            
        {                            
        case   IDC_BUTTON_OK :                            
            hEditUser = GetDlgItem(hwndDlg, IDC_EDIT_UserName);    //获取编辑框的句柄
            hEditPass = GetDlgItem(hwndDlg, IDC_EDIT_PassWord);

            TCHAR szUserBuffer[0x50];
            TCHAR szPassBuffer[0x50];

            GetWindowText(hEditUser, szUserBuffer, 0x50);        //获取编辑框的内容
            GetWindowText(hEditPass, szPassBuffer, 0x50);

            MessageBox(NULL,TEXT("IDC_BUTTON_OK"),TEXT("OK"),MB_OK);                        
                                    
            return TRUE;                        
                                    
        case   IDC_BUTTON_ERROR:                            
                                    
            MessageBox(NULL,TEXT("IDC_BUTTON_ERROR"),TEXT("ERROR"),MB_OK);                        
                                    
            EndDialog(hwndDlg, 0);                        
                                    
            return TRUE;                        //处理过的消息返回TRUE, 否则返回FALSE
        }                            
        break ;                            
    }                                    
                                    
    return FALSE ;                                
}                                    


int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
     DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG_MAIN), NULL, DialogProc);
    return 0;
}

 

posted @ 2020-09-15 15:43  w_athena  阅读(183)  评论(0)    收藏  举报