www.digitalmars.com         C & C++   DMDScript  

c++ - Trying to produce a window

reply Peter <Peter_member pathlink.com> writes:
Hi all,

Still Struggling!

I'm trying to produce a simple window. It compiles OK but nothing seems to
happen! Am I trying to achieve the impossible or am I doing  something totally
wrong?...

Peter.
---------------------------------------------------------

#include <windows.h>
#include <tchar.h>
#include "resource.h"

BOOL MainDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return FALSE;
}

int _tmain(void)
{
DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG1), 
NULL, (DLGPROC)MainDialogProc, 0);
return 0;
}
-------------------------------------------------------------
This is the resource.h file:
-------------------------------------------------------------
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by Step1.rc
//
#define IDD_DIALOG1                     101

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        102
#define _APS_NEXT_COMMAND_VALUE         40001
#define _APS_NEXT_CONTROL_VALUE         1000
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif
Dec 08 2002
next sibling parent reply "Tempest" <ajstempest.spamless email.com> writes:
Hi Peter,

I think returing FALSE from the DLGPROC might be the problem. The DLGPROC
handles all messages, which include things such as creation and
initialisation of the dialog. Returning FALSE would indicate failure and
terminate your processing prematurely. Try to find a default function to
call, replacing return FALSE with something like:

return DefWindowProc (hWnd, uMsg, wParam, lParam);

Anton.

"Peter" <Peter_member pathlink.com> wrote in message
news:asvniv$2b4i$1 digitaldaemon.com...
 Hi all,

 Still Struggling!

 I'm trying to produce a simple window. It compiles OK but nothing seems to
 happen! Am I trying to achieve the impossible or am I doing  something
totally
 wrong?...

 Peter.
 ---------------------------------------------------------

 #include <windows.h>
 #include <tchar.h>
 #include "resource.h"

 BOOL MainDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
 return FALSE;
 }

 int _tmain(void)
 {
 DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG1),
 NULL, (DLGPROC)MainDialogProc, 0);
 return 0;
 }
 -------------------------------------------------------------
 This is the resource.h file:
 -------------------------------------------------------------
 //{{NO_DEPENDENCIES}}
 // Microsoft Developer Studio generated include file.
 // Used by Step1.rc
 //
 #define IDD_DIALOG1                     101

 // Next default values for new objects
 //
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        102
 #define _APS_NEXT_COMMAND_VALUE         40001
 #define _APS_NEXT_CONTROL_VALUE         1000
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif
Dec 08 2002
parent reply Peter <Peter_member pathlink.com> writes:
Walter,

Sorry for my ignorange but could you explain what .def file is needed?
When the cd arrives I'll probably have some reading to do!.

Anton,

I've tried many variations but with no luck. In fact I haven't yet managed to
get a non-console program to work!. Below is the most minimal program that if I
understand correctly should work without invoking the console but it does. I
think I must be making some mistake while compiling...

#include <windows.h> 

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) 
{
MessageBox(NULL, "Hello world!", "Sample", MB_OK);
return 0; 
}

Peter.
Dec 08 2002
parent "Walter" <walter digitalmars.com> writes:
You'll need a file called "program.def" in it, and it should contain the
line:
    EXETYPE WINDOWS


"Peter" <Peter_member pathlink.com> wrote in message
news:at0ceq$6up$1 digitaldaemon.com...
 Walter,

 Sorry for my ignorange but could you explain what .def file is needed?
 When the cd arrives I'll probably have some reading to do!.

 Anton,

 I've tried many variations but with no luck. In fact I haven't yet managed
to
 get a non-console program to work!. Below is the most minimal program that
if I
 understand correctly should work without invoking the console but it does.
I
 think I must be making some mistake while compiling...

 #include <windows.h>

 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
 {
 MessageBox(NULL, "Hello world!", "Sample", MB_OK);
 return 0;
 }

 Peter.
Dec 08 2002
prev sibling next sibling parent "Walter" <walter digitalmars.com> writes:
What's your .def file?

"Peter" <Peter_member pathlink.com> wrote in message
news:asvniv$2b4i$1 digitaldaemon.com...
 Hi all,

 Still Struggling!

 I'm trying to produce a simple window. It compiles OK but nothing seems to
 happen! Am I trying to achieve the impossible or am I doing  something
totally
 wrong?...

 Peter.
 ---------------------------------------------------------

 #include <windows.h>
 #include <tchar.h>
 #include "resource.h"

 BOOL MainDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
 return FALSE;
 }

 int _tmain(void)
 {
 DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG1),
 NULL, (DLGPROC)MainDialogProc, 0);
 return 0;
 }
 -------------------------------------------------------------
 This is the resource.h file:
 -------------------------------------------------------------
 //{{NO_DEPENDENCIES}}
 // Microsoft Developer Studio generated include file.
 // Used by Step1.rc
 //
 #define IDD_DIALOG1                     101

 // Next default values for new objects
 //
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        102
 #define _APS_NEXT_COMMAND_VALUE         40001
 #define _APS_NEXT_CONTROL_VALUE         1000
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif
Dec 08 2002
prev sibling parent "Daniel Fazekas" <fds mailbox.hu> writes:
How are you compiling in the resource?
Show us the .rc file too.
Is the .res file getting generated correctly and is it linked into your
executable?

Check if the return value of DialogBoxParam is -1 and if so, try to output
the error message from Windows.

if (DialogBoxParam(....) == -1) {

LPTSTR lpMsgBuf;

FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |

FORMAT_MESSAGE_FROM_SYSTEM |

FORMAT_MESSAGE_IGNORE_INSERTS, NULL,

GetLastError(), MAKELANGID(LANG_NEUTRAL,

SUBLANG_DEFAULT),

(LPTSTR) & lpMsgBuf, 0, NULL);

MessageBox(NULL, (LPCTSTR) lpMsgBuf, TEXT("Error"),

MB_OK | MB_ICONSTOP);

LocalFree(lpMsgBuf);

}



--
Daniel


"Peter" <Peter_member pathlink.com> wrote in message
news:asvniv$2b4i$1 digitaldaemon.com...
 Hi all,

 Still Struggling!

 I'm trying to produce a simple window. It compiles OK but nothing seems to
 happen! Am I trying to achieve the impossible or am I doing  something
totally
 wrong?...

 Peter.
 ---------------------------------------------------------

 #include <windows.h>
 #include <tchar.h>
 #include "resource.h"

 BOOL MainDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
 return FALSE;
 }

 int _tmain(void)
 {
 DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_DIALOG1),
 NULL, (DLGPROC)MainDialogProc, 0);
 return 0;
 }
 -------------------------------------------------------------
 This is the resource.h file:
 -------------------------------------------------------------
 //{{NO_DEPENDENCIES}}
 // Microsoft Developer Studio generated include file.
 // Used by Step1.rc
 //
 #define IDD_DIALOG1                     101

 // Next default values for new objects
 //
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        102
 #define _APS_NEXT_COMMAND_VALUE         40001
 #define _APS_NEXT_CONTROL_VALUE         1000
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif
Dec 22 2002