www.digitalmars.com         C & C++   DMDScript  

c++.windows.32-bits - Newbie Question on Win32, concerns DMC.

reply NuToWin32 <NuToWin32_member pathlink.com> writes:
I've been trying to learn the Win32 API, in the C++ language, and the compiler
I've been using is DMC. I ran through a tutorial quickly, but when I get to the
secton on dialog boxes, I had a problem passing the dialogbox procedure handler
to the DialogBox command. If I cast the procedure handler as DLGPROC (Which
isn't specified to do in the tutorial), the tutorial code compiles, but returns
-1 (I'm assuming because of failure to initialize).
Can someone either show me where I'm wrong, or point me to a DMC compatable
Win32 API tutorial? Much oblidged either way.

// Elsewhere Jan Knepper mentioned to use SUBSYTEM WINDOW, 4.0, which will not
// compile for me, so I use WINDOWS

simple.def:
NAME "simple.exe"
DESCRIPTION 'Simple Program'
EXETYPE    NT
SUBSYSTEM    WINDOWS
CODE    EXECUTE READ
DATA    READ WRITE

Source Excerption From theForge's Tutorial (Most coding comments removed)

//... program includes, defines, .rc, and .h removed for space conservation

BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM
lParam)
{
//... code removed for space conservation
}

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
char szFileName[MAX_PATH];
switch(msg)
{
case WM_CREATE:
HMENU hMenu, hSubMenu;
HICON hIcon, hIconSm;
hMenu = CreateMenu();
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
hSubMenu = CreatePopupMenu();
AppendMenu(hSubMenu, MF_STRING, ID_HELP_ABOUT, "A&bout");
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Help");
SetMenu(hwnd, hMenu);
hIcon = LoadImage(NULL, "menu_one.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
if(hIcon)
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
else
MessageBox(hwnd, "Could not load large icon!", "Error", MB_OK | MB_ICONERROR);
hIconSm = LoadImage(NULL, "menu_one.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
if(hIconSm)
SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm);
else
MessageBox(hwnd, "Could not load small icon!", "Error", MB_OK | MB_ICONERROR);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_FILE_EXIT:
PostMessage(hwnd, WM_CLOSE, 0, 0);
break;
case ID_HELP_ABOUT:

// The following line will not compile in DMC, with compile extensions -mn -WA
int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd,
AboutDlgProc);

// However, this line will compile, but causes ret to equal -1
/*int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd,
(DLGPROC) AboutDlgProc);*/

if (ret == IDOK)
{
MessageBox(hwnd, "Dialog exited with IDOK.", "Notice", MB_OK |
MB_ICONINFORMATION);
}
else if (ret == IDCANCEL)
{
MessageBox(hwnd, "Dialog exited with IDCANCEL.", "Notice", MB_OK |
MB_ICONINFORMATION);
}
else if (ret == -1)
{
MessageBox(hwnd, "Dialog failed!", "Error", MB_OK | MB_ICONINFORMATION);
}
break;
}
break;

//... code removed for space conservation
}
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, char *
lpCmdLine, int nCmdShow)
{
//... code removed for space conservation
}
Aug 28 2002
parent reply Jan Knepper <jan smartsoft.cc> writes:
NuToWin32 wrote:

 I've been trying to learn the Win32 API, in the C++ language, and the compiler
 I've been using is DMC. I ran through a tutorial quickly, but when I get to the
 secton on dialog boxes, I had a problem passing the dialogbox procedure handler
 to the DialogBox command. If I cast the procedure handler as DLGPROC (Which
 isn't specified to do in the tutorial), the tutorial code compiles, but returns
 -1 (I'm assuming because of failure to initialize).
 Can someone either show me where I'm wrong, or point me to a DMC compatable
 Win32 API tutorial? Much oblidged either way.

 // Elsewhere Jan Knepper mentioned to use SUBSYTEM WINDOW, 4.0, which will not
 // compile for me, so I use WINDOWS
That indeed should be WINDOWS, 4.0
 // The following line will not compile in DMC, with compile extensions -mn -WA
 int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd,
 AboutDlgProc);

 // However, this line will compile, but causes ret to equal -1
 /*int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd,
 (DLGPROC) AboutDlgProc);*/
Are you sure you have a RESOURCE included with you .exe with IDD_ABOUT defined as dialog? Jan
Aug 28 2002
next sibling parent NuToWin32 <NuToWin32_member pathlink.com> writes:
In article <3D6D197A.3126F917 smartsoft.cc>, Jan Knepper says...

 // Elsewhere Jan Knepper mentioned to use SUBSYTEM WINDOW, 4.0, which will not
 // compile for me, so I use WINDOWS
That indeed should be WINDOWS, 4.0
I had not included the S at the end of WINDOWS, 4.0, thank you.
Are you sure you have a RESOURCE included with you .exe with IDD_ABOUT defined
as
dialog?
Yes, it is included(and IDD_ABOUT is defined), the rest of the resources work in the program (Other menus, icons, etc.) I apologize for the formating of my prior post, by the way, apparently this editor didn't like my indent style. I had forgotten to include the error:
 Executing: C:\PROGRAMMING\CONTEXT\ConExec.exe "C:\Programming\dm\bin\Sc.exe"
"C:\Programming\Simple\simple.cpp" -oC:\Programming\Simple\simple.exe -mn -WA
simple.def
int ret = DialogBox(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc); ^ C:\Programming\Simple\simple.cpp(66) : Error: need explicit cast for function parameter 4 to get from: int (*std func)(void *,unsigned ,unsigned ,long ) to : int (*__import std func)() --- errorlevel 1
 Execution finished.
As I said previously, casting (DLGPROC) AboutDlgProc won't generate the error, but the call to DialogBox returns -1 before any non-internal-function code(Not sure if that's what it is called, the code between the curly braces) is executed. Thank you for the prompt reply.
Aug 28 2002
prev sibling parent reply NuToWin32 <NuToWin32_member pathlink.com> writes:
First of all, I have to apologize, apparently I'm not using rcc.exe right,
because although I'm generating (And supposedly compiling) .rc files, the .res
file isn't generating, and thus, no dialog box is being generated. Sorry for my
foolish mistake.
Moving on, how do I generate a .res file with rcc.exe, or is that what I need? I
can't find any documentation (I don't have the cd, although I'll probably being
buying it for personal, if not business, use)
As for what I *do* have: A working win32 program(Works with lcc-win32.exe
compiler. A .def program with the required fields (As far as I've read in the
rest of the newsgroup). A working .rc file, with everything I need.
Thank you for your time, and patience.
Sep 05 2002
parent reply "Walter" <walter digitalmars.com> writes:
"NuToWin32" <NuToWin32_member pathlink.com> wrote in message
news:al8pop$2k8o$1 digitaldaemon.com...
 Moving on, how do I generate a .res file with rcc.exe, or is that what I
need? I
 can't find any documentation (I don't have the cd, although I'll probably
being
 buying it for personal, if not business, use)
Open www.digitalmars.com/ctg/ctg.html and click on RC or RCC.
Sep 05 2002
parent NuToWin32 <NuToWin32_member pathlink.com> writes:
Thank you all for the help, I've got it working.
Sep 06 2002