Howdy, Stranger!

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

Categories

My First DIalog Box code

Sonx_hvn7Sonx_hvn7 Member Posts: 54
[code]

#include
#include "stdafx.h"
#include "Dialog box.h"

HWND hWnd;
LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DLGFIRST),
hWnd, reinterpret_cast(DlgProc));

return FALSE;
}

LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
switch(wParam)
{
case IDOK:
EndDialog(hWndDlg, 0);
return TRUE;
}
break;
}

return FALSE;
}
[/code]

Builds but doesn't run, nothing shows on output

Comments

  • sgauravvsgauravv Member Posts: 4
    : [code]:
    :
    : #include
    : #include "stdafx.h"
    : #include "Dialog box.h"
    :
    : HWND hWnd;
    : LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
    :
    : INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    : LPSTR lpCmdLine, int nCmdShow)
    : {
    : DialogBox(hInstance, MAKEINTRESOURCE(IDD_DLGFIRST),
    : hWnd, reinterpret_cast(DlgProc));
    :
    : return FALSE;
    : }
    :
    : LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
    : {
    : switch(Msg)
    : {
    : case WM_INITDIALOG:
    : return TRUE;
    :
    : case WM_COMMAND:
    : switch(wParam)
    : {
    : case IDOK:
    : EndDialog(hWndDlg, 0);
    : return TRUE;
    : }
    : break;
    : }
    :
    : return FALSE;
    : }
    : [/code]:
    :
    : Builds but doesn't run, nothing shows on output
    :
    :


    hey i think u r doing some thing wrong in this
    i think u have to use these lines also

    u have not calles wndProc function in your main loop
    for dialog box u have to create a window
    u have to use showWindow & updateWindow
    just go for ant book from where u get the basic logic that how to create a windoe and how main loop call the WndPro fuction in forever loop.

  • Sonx_hvn7Sonx_hvn7 Member Posts: 54
    : : [code]: :
    : :
    : : #include
    : : #include "stdafx.h"
    : : #include "Dialog box.h"
    : :
    : : HWND hWnd;
    : : LRESULT CALLBACK DlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
    : :
    : : INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
    : : LPSTR lpCmdLine, int nCmdShow)
    : : {
    : : DialogBox(hInstance, MAKEINTRESOURCE(IDD_DLGFIRST),
    : : hWnd, reinterpret_cast(DlgProc));
    : :
    : : return FALSE;
    : : }
    : :
    : : LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
    : : {
    : : switch(Msg)
    : : {
    : : case WM_INITDIALOG:
    : : return TRUE;
    : :
    : : case WM_COMMAND:
    : : switch(wParam)
    : : {
    : : case IDOK:
    : : EndDialog(hWndDlg, 0);
    : : return TRUE;
    : : }
    : : break;
    : : }
    : :
    : : return FALSE;
    : : }
    : : [/code]: :
    : :
    : : Builds but doesn't run, nothing shows on output
    : :
    : :
    :
    :
    : hey i think u r doing some thing wrong in this
    : i think u have to use these lines also
    :
    : u have not calles wndProc function in your main loop
    : for dialog box u have to create a window
    : u have to use showWindow & updateWindow
    : just go for ant book from where u get the basic logic that how to
    : create a windoe and how main loop call the WndPro fuction in forever
    : loop.
    :
    :
    Got this example from the net... Irritating for people to put incomplete examples cause us beginners assume they work. Thanx BTW!
  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : :
    : : hey i think u r doing some thing wrong in this
    : : i think u have to use these lines also
    : :
    : : u have not calles wndProc function in your main loop
    : : for dialog box u have to create a window
    : : u have to use showWindow & updateWindow
    : : just go for ant book from where u get the basic logic that how to
    : : create a windoe and how main loop call the WndPro fuction in forever
    : : loop.
    : :
    : :
    : Got this example from the net... Irritating for people to put
    : incomplete examples cause us beginners assume they work. Thanx BTW!
    :
    [color=Blue]The code is fine - no need for loop - DialogBox() API has a loop inside it (as well as all ShowWindow()/UpdateWindow() code). No idea for now why it does not work. Check resources. Also, when you begin using a debugger? Put a breakpoint on "case WM_INITDIALOG" and check if this break will be hit.

    P.S. The ID_DLGFIRST? Where is it? How do you compile the RC file? Windows has a weird thing when RC file is compiled. Say, you have some ID, like this:
    [code]
    #define ID_DLGFIRST 35123
    [/code]
    If you do not include that definition into RC compilation process - RC compiler will convert that text into pure text and name it your resource, so you get your resource named: "ID_DLGFIRST" and not 35123.

    Of course, when you write MAKEINTRESOURCE(ID_DLGFIRST) and ID_DLGFIRST is 35123 - then you get screwed, because resource called "ID_DLGFIRST" as text.
    [/color]
  • AmagAmag Member Posts: 1
    "If you do not include that definition into RC compilation process -
    RC compiler will convert that text into pure text and name it your resource, so you get your resource named: "ID_DLGFIRST" and not 35123."

    Can you please explain what you mean by "include the definition into RC compilation process"? Does it mean there is a special way of compiling? Cause according to my understanding, I have just to #define ID_DLGFIRST 35123 both in the resource file (let's say Dialog.rc) and main file (Let's say main.cpp), then compile and run.

    In fact, I'm also failing to create dialog boxes. I'm using Dev-C++. Sometimes the dialog box creation fails, other times it is successful. I don't understand what the problem is. What can cause DialogBox() to return -1 or MAKEINTRESOURCE macro to fail? What error might have occured? Does it have anything to do with the compiler or linker? Cause I think my code is fine.

    Help about this issue will be really appreciated.



  • AsmGuru62AsmGuru62 Member Posts: 6,519
    : "If you do not include that definition into RC compilation process -
    : RC compiler will convert that text into pure text and name it your
    : resource, so you get your resource named: "ID_DLGFIRST" and not
    : 35123."
    :
    : Can you please explain what you mean by "include the definition into
    : RC compilation process"? Does it mean there is a special way of
    : compiling? Cause according to my understanding, I have just to
    : #define ID_DLGFIRST 35123 both in the resource file (let's say
    : Dialog.rc) and main file (Let's say main.cpp), then compile and run.
    :
    : In fact, I'm also failing to create dialog boxes. I'm using Dev-C++.
    : Sometimes the dialog box creation fails, other times it is
    : successful. I don't understand what the problem is. What can cause
    : DialogBox() to return -1 or MAKEINTRESOURCE macro to fail? What
    : error might have occured? Does it have anything to do with the
    : compiler or linker? Cause I think my code is fine.
    :
    : Help about this issue will be really appreciated.
    :
    [color=Blue]If you have this "#define" in both .RC and .CPP file - you are OK. The problem is somewhere else. The dialog creation may fail if you are using in your dialog something from Common Controls Library (tree view, list view, up/down, progress bar, etc.) and you did not initialize that library by calling InitCommonControlsEx () function.[/color]
Sign In or Register to comment.