TOP Win32API

Dialog Application

ModalModaless
parentdisabledenabled
message loopintegratednot integrated
invokeDialogBox()CreateDialog()
closeEndDialog()DestroyWindow()
WM_DESTROY--PostQuitMessage()
TABnoyes

modal

BOOL CALLBACK DlgTest01Proc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam){
    UINT wID;
    switch(msg) {
        case WM_CLOSE:
            EndDialog(hWnd,IDOK);
            break;
        case WM_INITDIALOG:
            break;
        case WM_COMMAND: // handle menu message
            /*
            wID = LOWORD(wParam);
            switch (wID) {
                case 1:
                break;
                default:
                break;
            }
            */
        break; // end of WM_COMMAND
    }
    return FALSE;
}
int WINAPI WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance , PSTR lpCmdLine , int nCmdShow ) {
    DialogBox(hInstance, TEXT("DlgTest01"), NULL, DlgTest01Proc);
    return 0;
}

modeless

int WINAPU WinMain(HINSTANCE hInstance , HINSTANCE hPrevInstance , PSTR lpCmdLine , int nCmdShow ) {
    DLGPROC lpProc = (DLGPROC)MakeProcInstance((FARPROC)dlg_proc, hInstance);
    HWND hDlg=CreateDialog(hInstance, "DlgProc", NULL, lpProc);
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0)) { 
        if (!IsDialogMessage(hDlg, &msg)){ /* tab,cr */
            TranslateMessage(&msg);
            DispatchMessage(&msg); 
        }
    }
    FreeProcInstance((FARPROC)lpProc);
    return 0;
}

管理人/副管理人のみ編集できます