How to use Dialog resources in Win32?

Without resources, I can set up your interface with an array of sophisticated CreateWindow()and CreateWindowEx()and WndProc()to process my experiences.

I noticed that if I right-click in the resource view and click "add resource", I can draw a dialog box with all the controls. This will save me a huge amount of time if I can draw the interface, as usual, with C #.

After I drew the interface with the resource editor, how do I create a window from the code? Can someone present a simple example using a button and show how to handle the WM_COMMAND event on this button, please?

Also, usually do people create a graphical interface? Is there any loss in flexibility for this? Even in C #, I often have to supplement the user interface created by the designer with my own user interface with code code, but most of the time I am very happy to use the constructor.

+5
source share
2 answers

CreateDialog ( , , CreateWindow) DialogBox ( ; , , ), . , proc RegisterClass, proc . DialogProc :

BOOL DialogProc( HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam ){
    switch( iMessage ){
    case WM_COMMAND:
        switch( LOWORD( wParam ) ){
        case BTOK:
            MessageBox( hDlg, "Hello, World!", NULL, NULL );
            return TRUE;
            break;
        }
        break;
    }
    return FALSE;
}

. , (, ..) ++ MFC.

+5

- - , . OnCommand , .

:

//CDialog_ControlDlg is my Dialog class derived from CDialog

//IDC_BUTTON_SAMPLE is the ID of the button which was palced on the dialog in the resource Editor..

BOOL CDialog_ControlDlg::OnCommand(WPARAM wParam,LPARAM lparam){
      int iNotiFicationMsg=HIWORD(wParam);//This is thenotification Msg from the child control
      int iCommandId=LOWORD(wParam);//And Control ID of the Child control which caused that Msg
      BOOL result=FALSE;
      switch(iCommandId){
    case IDC_BUTTON_SAMPLE:
        if(iNotiFicationMsg==BN_CLICKED)
        {
         //Your Code for handling this type of Msg for this control..

        }
        break;
    default:
    {
        //Specific Code;

    }

    return result;
}

}
+1

All Articles