dialog box

hy everybody
i want to make a dialog box only (with no menu )
i try with this source code
/////////////
#include
#include
#include
#include
#include
#include
#include"resource.h"


long WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL CALLBACK DlgProc(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp);

HINSTANCE hInst;
HWND hwnd;
int APIENTRY WinMain(HINSTANCE hi,HINSTANCE pi,LPSTR cline,int scmd)
{ WNDCLASS wc;
hInst=hi;
wc.style= CS_HREDRAW| CS_VREDRAW;
wc.lpszClassName="myclass";
wc.lpfnWndProc=WndProc ;
wc.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hIcon=LoadIcon(NULL,IDI_WINLOGO);
wc.hInstance=hi;
wc.lpszMenuName=NULL;
wc.cbWndExtra=0;
wc.cbClsExtra=0;
RegisterClass(&wc);
//HWND hwnd;
hwnd=CreateWindow("myclass","Prescreen VIEWER",WS_OVERLAPPEDWINDOW,0,0,600,500,NULL,NULL,hi,0);
ShowWindow(hwnd,scmd);
UpdateWindow(hwnd);
MSG msg;
while(GetMessage(&msg,hwnd,0,0)>0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}

long WINAPI WndProc(HWND hwnd ,UINT mid,WPARAM wp,LPARAM lp)
{
HWND hdlg;
switch(mid)
{

case WM_COMMAND:
switch(wp)
{
case WM_INITDIALOG:

hdlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,DlgProc);
//DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,DlgProc,0);

ShowWindow(hdlg,1);
break;



}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:return DefWindowProc(hwnd,mid,wp,lp);
}
return 0;
}


BOOL CALLBACK DlgProc(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp)
{ switch(mid)
{

case WM_CLOSE:
EndDialog(hdlg,0);
break;

case WM_COMMAND:
switch(wp)
{

case IDCANCEL:
EndDialog(hdlg,0);
break;

case IDOK:
MessageBox(hwnd,"hello","hy",MB_OK);
break;

} break;

}
return 0;

}





//////////
but it can not work
can anyone helpme?
many thanks in advance.

Comments

  • What compiler and version of it are you using?
  • i am using Microsoft Visual C++6.
    can you help me?
    many thanks in advance
    regards
    rania

  • I looked at your code and you are trying to process WM_INITDIALOG in your main window. This message will never be sent to a window created with CreateWindow, but to a dialog created with DialogBox.

    When do you want the dialog box to show up? if right away? then replace WM_INITDIALOG with WM_CREATE.

    : i am using Microsoft Visual C++6.
    : can you help me?
    : many thanks in advance
    : regards
    : rania
    :
    :

  • well i try as you said first it gives the window (i want this window to be the prescreen window of my project)so i want it to be dialog box , if i press to button1 for exampe it links with program1 by WinExec, and so on.
    by compiling after changing some codes it gives error in executing and this code:"cannt open debug/tryD1.exe(which is the program name) for writing"

    this is my source code.
    #include
    #include
    #include
    #include
    #include
    #include
    #include"resource.h"


    long WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);
    BOOL CALLBACK DlgProc(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp);

    HINSTANCE hInst;
    HWND hwnd;
    int APIENTRY WinMain(HINSTANCE hi,HINSTANCE pi,LPSTR cline,int scmd)
    { WNDCLASS wc;
    hInst=hi;
    wc.style= CS_HREDRAW| CS_VREDRAW;
    wc.lpszClassName="myclass";
    wc.lpfnWndProc=WndProc ;
    wc.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.hCursor=LoadCursor(NULL,IDC_ARROW);
    wc.hIcon=LoadIcon(NULL,IDI_WINLOGO);
    wc.hInstance=hi;
    wc.lpszMenuName=NULL;
    wc.cbWndExtra=0;
    wc.cbClsExtra=0;
    RegisterClass(&wc);
    //HWND hwnd;
    //hwnd=CreateWindow("myclass","Prescreen VIEWER",WS_OVERLAPPEDWINDOW,0,0,600,500,NULL,NULL,hi,0);
    DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc);
    //hwnd=CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,DlgProc);
    // ShowWindow(hdlg,TRUE);
    ShowWindow(hwnd,scmd);
    UpdateWindow(hwnd);
    MSG msg;
    while(GetMessage(&msg,hwnd,0,0)>0)
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    return 0;
    }

    long WINAPI WndProc(HWND hwnd ,UINT mid,WPARAM wp,LPARAM lp)
    {
    HWND hdlg;
    switch(mid)
    {

    case WM_COMMAND:
    switch(wp)
    {
    case WM_CREATE:

    hdlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,DlgProc);
    //DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,DlgProc,0);

    ShowWindow(hdlg,1);
    break;



    }
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:return DefWindowProc(hwnd,mid,wp,lp);
    }
    return 0;
    }


    BOOL CALLBACK DlgProc(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp)
    { switch(mid)
    {

    case WM_CLOSE:
    EndDialog(hdlg,0);
    break;

    case WM_COMMAND:
    switch(wp)
    {

    case IDCANCEL:
    EndDialog(hdlg,0);
    break;

    case IDOK:
    //MessageBox(hwnd,"hello","hy",MB_OK);
    WinExec("e:\Multimedia Viewer.exe",SW_SHOW);
    break;
    case IDC_BUTTON1:
    //MessageBox(hwnd,"hello","hy",MB_OK);
    WinExec("e:\General Viewer.exe",SW_SHOW);
    break;

    } break;

    }
    return 0;

    }

    can you help me?
    many thanks in advance
    regards
    rania





  • You get the access error because your EXE is not being unloaded from memory.

    I dont fully understand "prescreen". What are you trying to do? A dialog as your main window? In other words, instead of a normal resizable winodw, you want a dialog that has buttons etc?

    : well i try as you said first it gives the window (i want this window to be the prescreen window of my project)so i want it to be dialog box , if i press to button1 for exampe it links with program1 by WinExec, and so on.
    : by compiling after changing some codes it gives error in executing and this code:"cannt open debug/tryD1.exe(which is the program name) for writing"

  • yes i am trying to present first a dialog box with buttons instead of a resizable window.

    and this dialog box will have an image and 3 buttons.
    and i am working with the WinAPI32

    so can you help me?

    many thanks in advance
    regards
    rania
  • [b][red]This message was edited by pingpong at 2002-10-23 5:20:5[/red][/b][hr]
    Just call DialogBox then, this is the minimal code:
    [code]
    static INT WINAPI MyDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    switch(message)
    {
    case WM_INITDIALOG:
    // do initialization stuff here

    // I looked at your previous code, you need to return
    // 1 if you process a message in a dialog proc, 0 otherwise.
    return 1;

    case WM_COMMAND:
    switch(LOWORD(wParam)) // not switch(wParam) as you do
    {
    case IDOK:
    // do the OK stuff
    EndDialog(LOWORD(wParam));
    return 1;

    case IDCANCEL:
    // do the Cancel stuff
    EndDialog(LOWORD(wParam));
    return 1;

    break;
    }
    break;

    case WM_DESTROY:
    // if you need to clean up anything
    return 1;
    }

    return 0;
    }

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
    {
    DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, MyDlgProc);
    return 0;
    }
    [/code]
    See? No window, no WNDCLASS. However, if you need a true dialog box main window (with an icon, menu, etc) then its a bit more work. Let me know if this is satisfactory for you or not.

    : yes i am trying to present first a dialog box with buttons instead of a resizable window.
    :
    : and this dialog box will have an image and 3 buttons.
    : and i am working with the WinAPI32
    :
    : so can you help me?
    :
    : many thanks in advance
    : regards
    : rania
    :



  • well, i try as you said, but it does not work
    it gives same executing error" cannot open Debug/tryd1.exe for writing"



    #include
    #include
    #include
    #include
    #include
    #include
    #include"resource.h"


    //long WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);
    //BOOL CALLBACK DlgProc(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp);
    static INT WINAPI MyDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int);

    HINSTANCE hInst;
    HWND hwnd;
    /*
    int APIENTRY WinMain(HINSTANCE hi,HINSTANCE pi,LPSTR cline,int scmd)
    { WNDCLASS wc;
    hInst=hi;
    wc.style= CS_HREDRAW| CS_VREDRAW;
    wc.lpszClassName="myclass";
    wc.lpfnWndProc=WndProc ;
    wc.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH);
    wc.hCursor=LoadCursor(NULL,IDC_ARROW);
    wc.hIcon=LoadIcon(NULL,IDI_WINLOGO);
    wc.hInstance=hi;
    wc.lpszMenuName=NULL;
    wc.cbWndExtra=0;
    wc.cbClsExtra=0;
    RegisterClass(&wc);
    //HWND hwnd;
    //hwnd=CreateWindow("myclass","Prescreen VIEWER",WS_OVERLAPPEDWINDOW,0,0,600,500,NULL,NULL,hi,0);
    DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DlgProc);
    //hwnd=CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,DlgProc);
    // ShowWindow(hdlg,TRUE);
    ShowWindow(hwnd,scmd);
    UpdateWindow(hwnd);
    MSG msg;
    while(GetMessage(&msg,hwnd,0,0)>0)
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    return 0;
    }
    /*
    long WINAPI WndProc(HWND hwnd ,UINT mid,WPARAM wp,LPARAM lp)
    {
    HWND hdlg;
    switch(mid)
    {

    case WM_COMMAND:
    switch(wp)
    {
    case WM_CREATE:

    hdlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,DlgProc);
    //DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,DlgProc,0);

    ShowWindow(hdlg,1);
    break;



    }
    break;
    case WM_DESTROY:
    PostQuitMessage(0);
    break;
    default:return DefWindowProc(hwnd,mid,wp,lp);
    }
    return 0;
    }


    BOOL CALLBACK DlgProc(HWND hdlg,UINT mid,WPARAM wp,LPARAM lp)
    { switch(mid)
    {

    case WM_CLOSE:
    EndDialog(hdlg,0);
    break;

    case WM_COMMAND:
    switch(wp)
    {

    case IDCANCEL:
    EndDialog(hdlg,0);
    break;

    case IDOK:
    //MessageBox(hwnd,"hello","hy",MB_OK);
    WinExec("e:\Multimedia Viewer.exe",SW_SHOW);
    break;
    case IDC_BUTTON1:
    //MessageBox(hwnd,"hello","hy",MB_OK);
    WinExec("e:\General Viewer.exe",SW_SHOW);
    break;

    } break;

    }
    return 0;

    }

    */
    static INT WINAPI MyDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {//HDLG hdlg;
    HWND hdlg;

    switch(message)
    {
    case WM_INITDIALOG:
    // do initialization stuff here

    // I looked at your previous code, you need to return
    // 1 if you process a message in a dialog proc, 0 otherwise.
    //hdlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_DIALOG1),hwnd,DlgProc);
    DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG1), NULL, MyDlgProc);

    ShowWindow(hdlg,1);

    return 1;

    case WM_COMMAND:
    switch(LOWORD(wParam)) // not switch(wParam) as you do
    {
    case IDOK:
    // do the OK stuff
    WinExec("e:\Multimedia Viewer.exe",SW_SHOW);

    EndDialog(hdlg,LOWORD(wParam));
    return 1;

    case IDCANCEL:
    // do the Cancel stuff
    EndDialog(hdlg,LOWORD(wParam));
    return 1;

    break;
    }
    break;

    case WM_DESTROY:
    // if you need to clean up anything
    return 1;
    }

    return 0;
    }

    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
    {
    DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, MyDlgProc);
    return 0;
    }


    so may be there is an error in the program, can you get it ?

    please, can you help me?

    many thanks in advance
    regards
    rania

  • rania, as someone else said, your executable is still resident/running in memory. Close out of it by hitting CTRL-ALT-DEL and forcefully close it, but you really should fix it so it will close entirely when it completes running.

    : well, i try as you said, but it does not work
    : it gives same executing error" cannot open Debug/tryd1.exe for writing"
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories