我想让已开始的窗口就是对话框怎么作
谢谢

解决方案 »

  1.   

    如果你用SDK的话之需要更改BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)函数,把CreateWindow改为CreateDialog,别的地方做相应的改变
    应该就可以了
      

  2.   

    在WinZard-Step1选对话框不就得了
      

  3.   

    先建立一个对话框资源,并放置必要的控件,然后调用DialogBox函数显示这个对话框,并提供一个对话框的窗口过程参数
      

  4.   

    #include "resource.h"
    #include <windowsx.h>
    #include <windows.h>BOOL CALLBACK DialogProc(HWND, UINT, WPARAM, LPARAM);//1 入口
    int WINAPI WinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
       LPSTR lpCmdLine,
       int nCmdShow)
    {
        HWND hDialog=0;  //2 createDialog
      hDialog = CreateDialog(hInstance,
                         //identifies dialog box template name
                         MAKEINTRESOURCE (IDD_DEMO),
     // handle to owner window
                             0,
     // pointer to dialog box procedure
                             DialogProc);
      if (!hDialog)
      {
         char buf[100];
     //formats and stores a series of characters and values in a buffer
         wsprintf (buf,"Error x%x", GetLastError());
         MessageBox(0,buf,"CreateDialog",MB_ICONEXCLAMATION | MB_OK);
         return 1;
      }  MSG msg;
      int status;
      //3 消息循环
      //If message other than WM_QUIT, the return value is nonzero.
      //If the WM_QUIT message, the return value is 0. 
      //If there is an error, the return value is -1. 
      while ((status=GetMessage(&msg,0,0,0))!=0)
      {
        if (status==-1)
          return -1;
    //whether a message is intended for the specified dialog box,
    //and if it is, processes the message to the Dialog procedure. 
    //else ,process the message as usual.
        if (!IsDialogMessage(hDialog,&msg))
        {
          TranslateMessage(&msg);
          DispatchMessage(&msg);
        }
      }
      return msg.wParam;
    } //4 dialog procedure
    BOOL CALLBACK DialogProc(HWND hDlg,
     UINT message,
     WPARAM wParam,
     LPARAM lParam)
    {
    switch (message) 
    {
    // inite dialog
        case WM_INITDIALOG:
    break; 

            //close the dialog
            case WM_CLOSE:
                DestroyWindow(hDlg); //send WM_DESTROY
        break;

    //destroy the window
    case WM_DESTROY:
        PostQuitMessage(0); //send WM_QUIT,then GetMessage is broken
    break;

    case WM_COMMAND:
    switch (GET_WM_COMMAND_ID(wParam,lParam))     
    {
        case IDCANCEL:
    MessageBox(hDlg,"you click cancel, Dialog will close.\n\n 下次再见!","Dialog test",0);
    EndDialog(hDlg,TRUE);
        DestroyWindow(hDlg); //send WM_QUIT,then GetMessage is broken
    break;    

    case IDOK:
    char szText[128],buf[256];
    GetDlgItemText(hDlg,IDC_TXT,szText,sizeof(szText));
    wsprintf(buf,"Hello! you click OK.\n\n text is:%s",szText);
    MessageBox(hDlg,buf,"Dialog test",0);
    break; }
    break; default:
    return FALSE;
    }

    return TRUE;
    }     
      

  5.   

    #include "resource.h"
    #include <windows.h>BOOL CALLBACK DialogProc(HWND,UINT,WPARAM,LPARAM);int WINAPI WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
    {
        DialogBox(hInstance,(LPCTSTR)IDD_TEST,NULL,(DLSPROC)DialogProc);
        return FALSE;
    }BOOL CALLBACK DialogProc(HWND hDlg,
    UINT message,
    WPARAM wParam,
    LPARAM lParam)
    {
        switch(message)
        {
        case WM_INITDIALOG:
            return TRUE;    case WM_COMMAND:
            switch(LOWORD(wParam))
            {
            case IDOK:
            case IDCANCEL:
                EndDialog(hDlg,LOWORD(wParam));
                break;
            }
            return TRUE;    default:
            break;
        }    return FALSE;
    }
      

  6.   

    更正:
        DialogBox(hInstance,(LPCTSTR)IDD_TEST,NULL,(DLSPROC)DialogProc);
                                                      ^
    为:
        DialogBox(hInstance,(LPCTSTR)IDD_TEST,NULL,(DLGPROC)DialogProc);
                                                      ^