Hello,

I made a small app and I wanted to include DialogBox
Here is a code:

#include <windows.h>

#include "resource.h"

const char g_szclassName[] = "myWindowClass";

BOOL CALLBACK WelcomeDDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
    return TRUE;
    case WM_COMMAND:
    switch(LOWORD(wParam)) 
    { 
        case IDD_WELCOMED: 
        {
            int ret = DialogBox(GetModuleHandle(NULL), 
                MAKEINTRESOURCE(IDD_WELCOMED), hwnd, WelcomeDDlgProc);
            if(ret == IDC_OK){ 
                MessageBox(hwnd, "Dialog exited with IDOK.", "Notice",
                    MB_OK | MB_ICONINFORMATION);
            }
            
            }
        }
        break;
         
    


}
return TRUE;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case WM_CREATE:
    Beep( 100, 0);
    //DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_WELCOMED), hwnd, WelcomeDDlgProc); 
    //MessageBox(NULL, "You will need pencil and some paper, or just some experience.", "What will you need", MB_OK | MB_ICONINFORMATION);
    break;

    

        
    case WM_LBUTTONDOWN:
        {    
            char fileName[MAX_PATH];
            HINSTANCE hInstance = GetModuleHandle(NULL);
            GetModuleFileName(hInstance, fileName, MAX_PATH);
            DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_WELCOMED), hwnd, WelcomeDDlgProc);
            MessageBox(NULL, "You will need pencil and some paper, or just some experience.", "What will you need", MB_OK | MB_ICONINFORMATION);
            MessageBox(hwnd, fileName, "The path is", MB_OK | MB_ICONINFORMATION);
            Beep(1000, 300);
     //code


        }
        break;
                case WM_COMMAND:
            switch(LOWORD(wParam)) 
            {
                case ID_FILE_EXIT: 
                    MessageBox(NULL, "Exit", "quit message", MB_OK | MB_ICONEXCLAMATION);
        DestroyWindow(hwnd);
               break;
               case ID_HELP_NEEDHELP: 
           
                    DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_WELCOMED), hwnd, WelcomeDDlgProc); 
               break;
               case ID_HELP_ABOUTUS: 
                   
              //code
               break;
               case ID_HELP_LICENCE: 
                 //code
               break;

                
            }
        break;
    case WM_CLOSE:
        MessageBox(NULL, "Exit", "quit message", MB_OK | MB_ICONEXCLAMATION);
        DestroyWindow(hwnd);

        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}



int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{

    WNDCLASSEX wc;
    HWND hwnd;
    MSG Msg;

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = 0;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
    wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, 0);
    wc.hInstance = hInstance;
    wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
    wc.lpfnWndProc = WndProc;
    wc.lpszClassName = g_szclassName;
    wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1); 
    wc.hCursor = LoadCursor(GetModuleHandle(NULL), MAKEINTRESOURCE(IDC_MYPOINTERC));
    

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Err: Error with registering class", "Error ",  MB_ICONERROR | MB_OK);
        return 0;
    }

    hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szclassName,
"TYCK: Beginner",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
600,
650,
NULL,NULL, hInstance, NULL);

    if(hwnd == NULL)
    {
        MessageBox(NULL,"ERROr", "HWND ERR", MB_OK | MB_ICONERROR);
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    return Msg.wParam;



}

But DIALOG BOX DIDNT work. It just applied inside the window, but I could do nothing (program stopped responding)

SO I tought is a WM_LBUTTONDOWN: problem and I tryed to make Two windows

#include <windows.h>

#include "resource.h"

const char g_szclassName[] = "myWindowClass";
const char g_szclassName2[] = "myWindowClassA";
BOOL CALLBACK WelcomeDDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_INITDIALOG:
    return TRUE;
    case WM_COMMAND:
    switch(LOWORD(wParam)) 
    { 
        case IDD_WELCOMED: 
        {
            int ret = DialogBox(GetModuleHandle(NULL), 
                MAKEINTRESOURCE(IDD_WELCOMED), hwnd, WelcomeDDlgProc);
            if(ret == IDC_OK){ 
                MessageBox(hwnd, "Dialog exited with IDOK.", "Notice",
                    MB_OK | MB_ICONINFORMATION);
            }
            
            }
        }
        break;
         
    


}
return TRUE;
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case WM_CREATE:
    Beep( 100, 0);
    //DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_WELCOMED), hwnd, WelcomeDDlgProc); 
    //MessageBox(NULL, "You will need pencil and some paper, or just some experience.", "What will you need", MB_OK | MB_ICONINFORMATION);
    break;

    

        
    case WM_LBUTTONDOWN:
        {    
            char fileName[MAX_PATH];
            HINSTANCE hInstance = GetModuleHandle(NULL);
            GetModuleFileName(hInstance, fileName, MAX_PATH);
            DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_WELCOMED), hwnd, WelcomeDDlgProc);
            MessageBox(NULL, "You will need pencil and some paper, or just some experience.", "What will you need", MB_OK | MB_ICONINFORMATION);
            MessageBox(hwnd, fileName, "The path is", MB_OK | MB_ICONINFORMATION);
            Beep(1000, 300);
            //to be continued


        }
        break;
                case WM_COMMAND:
            switch(LOWORD(wParam)) 
            {
                case ID_FILE_EXIT: 
                    MessageBox(NULL, "Exit", "quit message", MB_OK | MB_ICONEXCLAMATION);
        DestroyWindow(hwnd);
               break;
               case ID_HELP_NEEDHELP: 

                    DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_WELCOMED), hwnd, WelcomeDDlgProc); 
               break;
               case ID_HELP_ABOUTUS: 
                   //code
                  
               break;
               case ID_HELP_LICENCE: 
                   //code
               break;

                
            }
        break;
    case WM_CLOSE:
        MessageBox(NULL, "Exit", "quit message", MB_OK | MB_ICONEXCLAMATION);
        DestroyWindow(hwnd);

        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}
LRESULT CALLBACK WndProc2(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
    case WM_CREATE:
    Beep( 100, 0);
    //DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_WELCOMED), hwnd, WelcomeDDlgProc); 
    //MessageBox(NULL, "You will need pencil and some paper, or just some experience.", "What will you need", MB_OK | MB_ICONINFORMATION);
    break;

    

        
    case WM_LBUTTONDOWN:
        {    
            char fileName[MAX_PATH];
            HINSTANCE hInstance = GetModuleHandle(NULL);
            GetModuleFileName(hInstance, fileName, MAX_PATH);
            DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_WELCOMED), hwnd, WelcomeDDlgProc);
            MessageBox(NULL, "You will need pencil and some paper, or just some experience.", "What will you need", MB_OK | MB_ICONINFORMATION);
            MessageBox(hwnd, fileName, "The path is", MB_OK | MB_ICONINFORMATION);
            Beep(1000, 300);
            //to be continued


        }
        break;
                case WM_COMMAND:
            switch(LOWORD(wParam)) 
            {
                case ID_FILE_EXIT: 
                    MessageBox(NULL, "Exit", "quit message", MB_OK | MB_ICONEXCLAMATION);
        DestroyWindow(hwnd);
               break;
               case ID_HELP_NEEDHELP: 
 MB_ICONINFORMATION );
                    DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_WELCOMED), hwnd, WelcomeDDlgProc); 
               break;
               case ID_HELP_ABOUTUS: 
                   
//code
               break;
               case ID_HELP_LICENCE: 
//code
               break;

                
            }
        break;
    case WM_CLOSE:
        MessageBox(NULL, "Exit", "quit message", MB_OK | MB_ICONEXCLAMATION);
        DestroyWindow(hwnd);

        break;
    case WM_DESTROY:
        PostQuitMessage(0);
        break;
    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}




int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{

    WNDCLASSEX wc;
     WNDCLASSEX wcx  ;
    HWND hwnd;
    HWND hWnd;
    MSG Msg;

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = 0;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
    wc.hIconSm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, 0);
    wc.hInstance = hInstance;
    wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
    wc.lpfnWndProc = WndProc;
    wc.lpszClassName = g_szclassName;
    wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1); 
    wc.hCursor = LoadCursor(GetModuleHandle(NULL), MAKEINTRESOURCE(IDC_MYPOINTERC));
    
    wcx.cbSize = sizeof(WNDCLASSEX);
    wcx.style = 0;
    wcx.cbClsExtra = 0;
    wcx.cbWndExtra = 0;
    wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION); //LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
    wcx.hIconSm = LoadIcon(NULL, IDI_APPLICATION); //(HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, 0);
    wcx.hInstance = hInstance;
    wcx.hbrBackground = (HBRUSH) +13;
    wcx.lpfnWndProc = WndProc2;
    wcx.lpszClassName =  g_szclassName2 ;
    wcx.lpszMenuName = NULL; 
    wcx.hCursor = LoadCursor(NULL, IDC_ARROW);

    if(!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Err: Error with registering class1", "Error ",  MB_ICONERROR | MB_OK);
        return 0;
    }
    if(!RegisterClassEx(&wcx))
    {
        MessageBox(NULL, "Err: Error with registering class2", "Error ",  MB_ICONERROR | MB_OK);
        return 0;
    }

    hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szclassName,
"TYCK: Beginner",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
600,
650,
NULL,NULL, hInstance, NULL);

    hWnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szclassName2,
"TYCK: Beginner: -> Running",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
600,
650,
NULL,NULL, hInstance, NULL);
//    RegisterClassA(&wcx);
//    hWnd = CreateWindowExA(0,wcx,"Okno dva...",WS_VISIBLE|WS_SYSMENU,500,500,150,100,0,0,hInstance,0);

    if(hwnd == NULL)
    {
        MessageBox(NULL,"ERROr", "HWND ERR", MB_OK | MB_ICONERROR);
        return 0;
    }
    if(hWnd == NULL)
    {
        MessageBox(NULL,"ERROr", "HWND ERR", MB_OK | MB_ICONERROR);
        return 0;
    }

    ShowWindow(hwnd, nCmdShow);
    UpdateWindow(hwnd);

    while(GetMessage(&Msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    return Msg.wParam;



}

But now ONLY FIRST WINDOW SHOWS UP...

I am realy getting mad...


So WHY DOES DIALOG BOX FREEZE?

Ok, I solved the problem with making the own message loop for dialog box..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.