• Advertisement

Archived

This topic is now archived and is closed to further replies.

Dev-C++ 4.0, and a dialog resource problem

This topic is 5782 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve been learning Win32 programming from Petzold''s Programming Windows, but I''ve hit a snag with one of the examples. Here is the first few lines of a dialog resource in my Rsrc.rc:
  HexCalc DIALOG 1, 1, 102, 122
  STYLE WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX
  CLASS "HexCalc"
  CAPTION "Hex Calculator"
  {
     PUSHBUTTON "D",       68,  8,  24, 14, 14
     ......
 
I get a parse error on line 3. Near as I can tell, it''s all right, and I''m not sure where to look for info on the CLASS keyword. Any ideas what might be causing that? Thanks for your help. Chris Barry (crbarry at mts.net) My Personal Programming Depot

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by Puzzler183
What language?

I think it's pretty well stated that it's a Win32 resource file. Edit: I don't personally know the answer (I haven't touched a Win32 resource file for at least a year), I'm just answering sub-questions.



[edited by - Null and Void on April 18, 2002 12:01:13 AM]

Share this post


Link to post
Share on other sites
if your using a dialog in there, you need to #include <windows.h> at the top of the file

Share this post


Link to post
Share on other sites
If you don''t have a resource.h file then don''t worry about it.

But if you see anywhere in your source the following:

MAKEINTRESOURCE

Then chances are that the program needs a resource.h file to resolve the string names into integers. Otherwise if don''t want to use a resource.h file, then anywhere you see MAKEINTRESOURCE, delete it, and just use the string itself.

Share this post


Link to post
Share on other sites
I''ve mucked about with resource files for a couple of years now (thanks to lcc-win32 ), and for the life of me, I''ve never come across a CLASS identifier. Have you tried removing it?

Share this post


Link to post
Share on other sites
Hi,

I am also a newbie to Windows Programming. But, I think I can help you. Use this :

Add this in your "resource.rc"

IDD_ABOUT DIALOG DISCARDABLE 0, 0, 239, 66
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "My About Box"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "OK",IDOK,174,18,50,14
PUSHBUTTON "Cancel",IDCANCEL,174,35,50,14
GROUPBOX "About this program...",IDC_STATIC,7,7,225,52
CTEXT "An example program showing how to use Dialog Boxes\r\n\r\nby The Lion King",
IDC_STATIC,16,18,144,33
END

Use this for calling the Dialog Box in *.cpp file :

DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(IDD_ABOUT), hwnd,
AboutDlgProc);

IDD_ABOUT is a #defined word. It is usually defined in "resource.h" and this file is #include in both *.cpp and *.rc files. i.e.

#define IDD_ABOUT 104

what we do here is that we assign a name to the our Dialog Box resource i.e. IDD_ABOUT and assigned IDD_ABOUT an integer value.
i.e. 104.

It means that whenever we say IDD_ABOUT, we mean to say 104.

About that CLASS "HexCalc", to be honest with you. I don''t really know about the CLASS. But I do know that HexCalc is the name assigned to the Dialog Box. So remove this line and add in reource.h as I said or #define HexCalc 104 in both files. Its up to you. The dialog box resource will be created.

(Please tell me if I am wrong anyone!!!).

For just telling you that, I would like a favor from anyone. Since I am a newbie. I can''t find any good tutorials on WinAPI.
And I am stuck in creating a simple command button in my window.

Can any one Help???

Thanks (in Advance!!!)

I ... am ... the GAME!!!

Share this post


Link to post
Share on other sites
quote:
Original post by NuffSaid
I''ve mucked about with resource files for a couple of years now (thanks to lcc-win32 ), and for the life of me, I''ve never come across a CLASS identifier. Have you tried removing it?
Yes, but it doesn''t like that. The program won''t respond to button presses or anything else. The idea behind this example is that the dialog is the main window (CreateWindow() isn''t called) and evidently, the CLASS keyword is necessary to tell Windows to send messages to my windows procedure instead of its own.

I can post the .rc and .cpp files; shall I?

Chris Barry (crbarry at mts.net)
My Personal Programming Depot

Share this post


Link to post
Share on other sites
To serve as a bump, I believe I shall.


    
// hexcalc.c

#include <ctype.h>

#include <windows.h>



LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("HexCalc");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;

wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = DLGWINDOWEXTRA; // Note!

wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (hInstance, szAppName);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;

if(!RegisterClass(&wndclass))
{
MessageBox(NULL, TEXT ("This program requires Windows NT!"), szAppName, MB_ICONERROR);
return 0;
}

hwnd = CreateDialog(hInstance, szAppName, 0, NULL);

ShowWindow(hwnd, iCmdShow);

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

return msg.wParam;
}


void ShowNumber(HWND hwnd, UINT iNumber)
{
TCHAR szBuffer[20];

wsprintf(szBuffer, TEXT ("%X"), iNumber);
SetDlgItemText(hwnd, VK_ESCAPE, szBuffer);
}


DWORD CalcIt(UINT iFirstNum, int iOperation, UINT iNum)
{
switch (iOperation)
{
case '=': return iNum;
case '+': return iFirstNum + iNum;
case '-': return iFirstNum - iNum;
case '*': return iFirstNum * iNum;
case '&': return iFirstNum & iNum;
case '|': return iFirstNum | iNum;
case '^': return iFirstNum ^ iNum;
case '<': return iFirstNum << iNum;
case '>': return iFirstNum >> iNum;
case '/': return iNum ? iFirstNum / iNum: MAXDWORD;
case '%': return iNum ? iFirstNum % iNum: MAXDWORD;
default : return 0;
}
}


LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static BOOL bNewNumber = TRUE;
static int iOperation = '=';
static UINT iNumber, iFirstNum;
HWND hButton;

switch (message)
{
case WM_KEYDOWN: // left arrow --> backspace

if(wParam != VK_LEFT)
break ;
wParam = VK_BACK;
// fall through


case WM_CHAR:
if((wParam = (WPARAM)CharUpper((TCHAR *)wParam)) == VK_RETURN)
wParam = '=';

if(hButton = GetDlgItem(hwnd, wParam))
{
SendMessage(hButton, BM_SETSTATE, 1, 0);
Sleep(100);
SendMessage(hButton, BM_SETSTATE, 0, 0);
}
else
{
MessageBeep(0);
break;
}
// fall through


case WM_COMMAND:
SetFocus (hwnd);

if(LOWORD(wParam) == VK_BACK) // backspace

ShowNumber(hwnd, iNumber /= 16);

else if(LOWORD(wParam) == VK_ESCAPE) // escape

ShowNumber(hwnd, iNumber = 0);

else if(isxdigit(LOWORD(wParam))) // hex digit

{
if(bNewNumber)
{
iFirstNum = iNumber;
iNumber = 0;
}
bNewNumber = FALSE;

if(iNumber <= MAXDWORD >> 4)
ShowNumber(hwnd, iNumber = 16 * iNumber + wParam - (isdigit(wParam) ? '0': 'A' - 10));
else
MessageBeep(0);
}
else // operation

{
if(!bNewNumber)
ShowNumber(hwnd, iNumber = CalcIt(iFirstNum, iOperation, iNumber));
bNewNumber = TRUE;
iOperation = LOWORD(wParam);
}
return 0;

case WM_DESTROY:
PostQuitMessage(0);
return 0;
}

return DefWindowProc (hwnd, message, wParam, lParam);
}


And the resource file:


      
// Icon

HEXCALC ICON DISCARDABLE "C:/Win32 API tutorials/HexCalc/HexCalc.ico"

// Include the dialog script

HexCalc DIALOG 1, 1, 102, 122
STYLE WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX
CLASS "HexCalc"
CAPTION "Hex Calculator"
{
PUSHBUTTON "D", 68, 8, 24, 14, 14
PUSHBUTTON "A", 65, 8, 40, 14, 14
PUSHBUTTON "7", 55, 8, 56, 14, 14
PUSHBUTTON "4", 52, 8, 72, 14, 14
PUSHBUTTON "1", 49, 8, 88, 14, 14
PUSHBUTTON "0", 48, 8, 104, 14, 14
PUSHBUTTON "0", 27, 26, 4, 50, 14
PUSHBUTTON "E", 69, 26, 24, 14, 14
PUSHBUTTON "B", 66, 26, 40, 14, 14
PUSHBUTTON "8", 56, 26, 56, 14, 14
PUSHBUTTON "5", 53, 26, 72, 14, 14
PUSHBUTTON "2", 50, 26, 88, 14, 14
PUSHBUTTON "Back", 8, 26, 104, 32, 14
PUSHBUTTON "C", 67, 44, 40, 14, 14
PUSHBUTTON "F", 70, 44, 24, 14, 14
PUSHBUTTON "9", 57, 44, 56, 14, 14
PUSHBUTTON "6", 54, 44, 72, 14, 14
PUSHBUTTON "3", 51, 44, 88, 14, 14
PUSHBUTTON "+", 43, 62, 24, 14, 14
PUSHBUTTON "-", 45, 62, 40, 14, 14
PUSHBUTTON "*", 42, 62, 56, 14, 14
PUSHBUTTON "/", 47, 62, 72, 14, 14
PUSHBUTTON "%", 37, 62, 88, 14, 14
PUSHBUTTON "Equals", 61, 62, 104, 32, 14
PUSHBUTTON "&&", 38, 80, 24, 14, 14
PUSHBUTTON "|", 124, 80, 40, 14, 14
PUSHBUTTON "^", 94, 80, 56, 14, 14
PUSHBUTTON "<", 60, 80, 72, 14, 14
PUSHBUTTON ">", 62, 80, 88, 14, 14
}


Hope that code turns out well .....

Chris Barry (crbarry at mts.net)
My Personal Programming Depot

[edited by - 23yrold3yrold on April 19, 2002 11:12:46 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
A nerdy accountant is sent to jail for embezzlement and they put him in a cell with a huge evil looking guy. The big guy says, "I want to have some sex. You wanna be the husband or the wife?" The accountant replies, "Well, if I have to be one or the other, I guess I''d rather be the husband." The big guy says, "Okay. Now get over here and suck your wife''s dick."

Share this post


Link to post
Share on other sites
Go email Colin and ask him about his IDE. If he can''t answer, switch to lcc-win32 or buy MSVC. That''s probably the best advice I can give.

Share this post


Link to post
Share on other sites

  • Advertisement