Re: In the need for some advice!
- From: Robby <Robby@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 22 Mar 2006 22:40:29 -0800
Hi David and thanks for getting back to me!
David, I have spent the whole day on this and I feel a little discouraged. I
know that usually I would post the error, but there are about 100 of them. I
think this will confuse you more than anything else if I post all 100 errors.
And I know what you are saying to start by the errors that pertain to one
window and work from there, but somehow, it's almost like the errors list
gets bigger with every time I buid the application. Anyhow, allow me to
boldly post the 6 files of the project. I usually would not do this, but I am
exhausted of trying all kinds of test and getting no where. Its probably
because I am not used to having code broken up in several headers and '.c'
files so I might also be getting confused on that too.
So here I go... If I may politely ask you to take the files one at a time
and copy them as they are in VC++ and try to compile it, you may see the
problem better than I can. You can try to use '.c' or .'cpp' I tried them
both, I know you have menioned to me that I should use '.c', however my files
are '.cpp'. If you want I can re-name them an re-send them as '.c'.
==================================================
File name: APP1.h
==================================================
//DECLARE CALLBACK
////////////////////////
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
//DECLARE GLOBAL STRUCTURE
///////////////////////////////////
struct tagIdRoomIndex
{
int iRoomNumber;
TCHAR *szRoomName;
};
//MAIN WINDOWS DECLARATION VARIABLES
/////////////////////////////////////////////////
static TCHAR *szMW_Name = TEXT ("MAIN APPLICATION 1");
static TCHAR szMW_ClassName[] = TEXT ("MW");
//CONTROLS IN WINDOWS MAIN [WndProc]
////////////////////////////////////////////////
//control #1
#define DCnst_btC1_ID 1 //Defined Constant ID of child control window
static TCHAR *szMW_btC1_Name = TEXT("Display aplication"); //Child Name
//control #2
#define DCnst_btC2_ID 2 //Defined Constant ID of child control window
static TCHAR *szMW_btC2_Name = TEXT("EXIT"); //Child Name
================================================
==================================================
File name: APPLICATION_1.cpp
==================================================
////////////////////////////////////////////////////////////////////////////////////////////
// MAIN CPP
#include <windows.h>
#include "APP1.h"
#include "CW1_WPHeader.h"
#include "LIB1_FHeader.h"
//WIN MAIN
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInnstance,
PSTR szCmdLine, int iCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
//CONFIGURE WINDOW APPLICATION
/////////////////////////////////////////
wndclass.style = CS_HREDRAW |CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szMW_ClassName;
//REGISTER WINDOW APPLICATION
///////////////////////////////////////
RegisterClass (&wndclass);
//CONFIGURE CHILD WINDOW #1
/////////////////////////////////////
wndclass.lpfnWndProc = CW1_WndProc;
wndclass.hIcon = LoadIcon (NULL, IDI_EXCLAMATION);
wndclass.hIcon = NULL;
wndclass.lpszClassName = szCW1_ClassName;
//REGISTER CHILD WINDOW #1
///////////////////////////////////
RegisterClass(&wndclass);
////////////////////////////////////////////////////////////////////////////////
//Create Main window
hwnd = CreateWindow (szMW_ClassName,szMW_Name,
WS_OVERLAPPEDWINDOW,
100, 100,
1000, 600,
NULL, NULL, hInstance, NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow (hwnd);
while (GetMessage (&msg, NULL, 0, 0)) //Window's queue loop
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int) msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
//////////////////////////////////////////////////////////////////////////
//CHILD WINDOW HANDLES
static HWND hdMW1;
///////////////////////////////////////////////////////////////////////////
//CHILD CONTROL HANDLES
static HWND hdMW_btC1, hdMW_btC2;
PAINTSTRUCT ps;
switch(message)
{
case WM_CREATE:
hdMW_btC1 = CreateWindow( //Create display app button
TEXT ("button"),szMW_btC1_Name,
WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON ,
10,10,150,50,hwnd,(HMENU)DCnst_btC1_ID,
(HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
hdMW_btC2 = CreateWindow( //Create application exit button
TEXT ("button"),szMW_btC2_Name,
WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON ,
900,490,60,40,hwnd,(HMENU)DCnst_btC2_ID,
(HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
return 0;
case WM_PAINT:
BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return 0;
case WM_COMMAND:
if (LOWORD(wParam) == DCnst_btC1_ID)
{
hdMW1 = CreateWindow( //Create Child window
szCW1_ClassName,szCW1_Name,
WS_CHILD | WS_CAPTION | WS_SYSMENU,
200,50,400,400,hwnd,(HMENU)DCnst_CW1_ID,
(HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
ShowWindow(hdMW1,SW_SHOW);
SetFocus(hwnd); //Remove focus from button and
//set it to the main window.
EnableWindow(
GetDlgItem(
hwnd,DCnst_btC1_ID),
FALSE);
}
else if (LOWORD(wParam) == DCnst_btC2_ID)
{
DestroyWindow(hwnd); //End application
}
return 0;
Case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
==============================================
==================================================
File name: CW1_WPHeader.h
==================================================
//DECLARE CALLBACK
LRESULT CALLBACK CW1_WndProc (HWND, UINT, WPARAM, LPARAM);
//DECLARE ARRAY OF STRUCTURES
////////////////////////////////////////
tagIdRoomIndex RIndex[] =
{
1 ,TEXT("Kitchen"),
2 ,TEXT("Living room"),
3 ,TEXT("Den"),
4 ,TEXT("Bedroom #1"),
5 ,TEXT("Bedroom #2"),
6 ,TEXT("Bathroom"),
7 ,TEXT("Bathroom #2")
};
//SET INFORMATION RELATED TO ARRAY
static int iMinLines = 0;
static int iMaxLines = (sizeof RIndex / sizeof RIndex[0]) ;
///////////////////////////////////////////////////////////////////////////////////////////
//CHILD WINDOW #1
#define DCnst_CW1_ID 100 //Defined Constant ID of child window
static TCHAR *szCW1_Name = TEXT("Display application"); //Child window
name
static TCHAR szCW1_ClassName[] = TEXT("CW1"); //Child window class name
//CONTROLS IN CHILD WINDOW #1, [CW1_WndProc]
/////////////////////////////////////////////////////////
//control #101
#define DCnst_btC101_ID 101 //Defined Constant ID of child control window
static TCHAR *szCW1_btC101_Name = TEXT("EXIT !"); //Child window Name
//control #102
#define DCnst_btC102_ID 102 //Defined Constant ID of child control window
static TCHAR *szCW1_btC102_Name = TEXT("CLEAR"); //Child window Name
//control #103
#define DCnst_btC103_ID 103 //Defined Constant ID of child control window
static TCHAR *szCW1_btC103_Name = TEXT("All >2"); //Child window Name
//control #104
#define DCnst_btC104_ID 104 //Defined Constant ID of child control window
static TCHAR *szCW1_btC104_Name = TEXT("Re-List All"); //Child window Name
====================================================
==================================================
File name: CW1_WndProc.cpp
==================================================
//////////////////////////////////////////////////////////////////////////////////////////
//CW1_WndProc is a Windows procedure that displays a child window
#include "CW1_WPHeader.h"
LRESULT CALLBACK CW1_WndProc (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
//////////////////////////////////////////////////////////////////////////////////////////////CHILD CONTROL HANDLES
static HWND hdCW1_btC101, hdCW1_btC102, hdCW1_btC103, hdCW1_btC104;
//////////////////////////////////////////////////////////////////////////////////////////////VARIABLES AND OBJECTS
static int cxChar, cxCaps, cyChar, cxClient, cyClient;
static bool bClear = FALSE; //TRUE = Clear list, FALSE = Don't clear list
static TCHAR szHeader[] = TEXT(" Room [#] Room name");
static TCHAR szUnderL[] = TEXT(" ---------------
--------------------");
//////////////////////////////////////////////////////////////////////////////////////////////WIN32 AND C++ VARIABLES/OBJECTS
static RECT rectA1; //Common area #1 in child window client area.
HDC hdc;
PAINTSTRUCT ps;
TEXTMETRIC tm;
switch(message)
{
case WM_SIZE:
cxClient = LOWORD(lParam);
cyClient = HIWORD(lParam);
bClear = FALSE;
SetRect(&rectA1,0,25,cxClient,cyClient-100);
return 0;
case WM_CREATE:
hdc = GetDC(hwnd);
GetTextMetrics(hdc,&tm);
cxChar = tm.tmAveCharWidth;
cxCaps = (tm.tmPitchAndFamily & 1 ? 3:2) * cxChar / 2;
cyChar = tm.tmHeight + tm.tmExternalLeading;
//Create child controls
hdCW1_btC101 = CreateWindow(
TEXT ("button"),szCW1_btC101_Name,
WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON ,
300,320,80,30,hwnd,(HMENU)DCnst_btC101_ID,
(HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
hdCW1_btC102 = CreateWindow(
TEXT ("button"),szCW1_btC102_Name,
WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON ,
10,320,80,30,hwnd,(HMENU)DCnst_btC102_ID,
(HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
hdCW1_btC103 = CreateWindow(
TEXT ("button"),szCW1_btC103_Name,
WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON ,
100,320,80,30,hwnd,(HMENU)DCnst_btC103_ID,
(HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
hdCW1_btC104 = CreateWindow(
TEXT ("button"),szCW1_btC104_Name,
WS_CHILD | WS_VISIBLE |BS_PUSHBUTTON ,
190,320,100,30,hwnd,(HMENU)DCnst_btC104_ID,
(HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE),NULL);
ReleaseDC(hwnd,hdc);
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd,&ps);
if (bClear == FALSE)
{
L1_txtDISPLAY_ArSt2MEMB(hdc,RIndex,szHeader,szUnderL,
cxChar,cyChar,25,25,2,15,FALSE,iMinLines,iMaxLines );
}
else
{
bClear = FALSE;
}
EndPaint(hwnd,&ps);
return 0;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case DCnst_btC101_ID: //CLOSE CHILD WINDOW
//Enable/disable child control in parent window
EnableWindow(GetDlgItem((HWND)GetWindowLong( hwnd,GWL_HWNDPARENT),DCnst_btC1_ID), TRUE);
DestroyWindow(hwnd);
break;
case DCnst_btC102_ID: //CLEAR
bClear = TRUE; //Set Clear flag
InvalidateRect(hwnd,&rectA1,TRUE); //Call WM_PAINT and erase the whole list
break;
case DCnst_btC103_ID: //All > 2
bClear = TRUE; //Set Clear flag
InvalidateRect(hwnd,&rectA1,TRUE); //Call WM_PAINT and erase the whole list
bClear = FALSE; //Reset Clear flag to Display text
iMinLines = 2; //List all lines = or greater than 2
InvalidateRect(hwnd,&rectA1,TRUE); //Call WM_PAINT and display list criteria
break;
case DCnst_btC104_ID: //Re-List all
bClear = TRUE; //Set Clear flag
InvalidateRect(hwnd,&rectA1,TRUE); //Call WM_PAINT and erase the whole list
bClear = FALSE; //Reset Clear flag to Display text
iMinLines = 0; //List all lines = or greater than 0
InvalidateRect(hwnd,&rectA1,TRUE); //Call WM_PAINT and display list criteria
break;
}
return 0;
case WM_CLOSE:
EnableWindow(GetDlgItem((HWND)GetWindowLong( hwnd,GWL_HWNDPARENT),DCnst_btC1_ID), TRUE);
break;
}
return DefWindowProc(hwnd, message,wParam,lParam);
}
====================================================
==================================================
File name: LIB1_FHeader.h
==================================================
//Function declaration
void L1_txtDISPLAY_ArSt2MEMB(
HDC, //Handle to a device context
struct tagIdRoomIndex RIndex[], //Array of structures tagIdRoomIndex
TCHAR *, //Header string desired
TCHAR *, //Underlining of header string desired
int , int , //Width and height of characters
int , //Maximum lenght of character items in structure
int ,int , //Depicts where text begins from left and top of client area in
Pixels
int , //Space in pixels between the 2 members (Column space)
bool , //Tab alignment, FALSE = left justified, TRUE = right justified
int , int ); //Minimum and maximum of lines of array items to display
===================================================
==================================================
File name: LIB1_Functions.cpp
==================================================
//Library functions #1
////////////////////////////////////////////////////////////////////////////////////////////
#include "LIB1_FHeader.h"
//INTENT OF FUNCTION
///////////////////////////
//This function displays text from an array of structures which should
declared in
//the local wndProc function (which should be the Proc function that holds
the
//calling function statement to this function). The structure can be
declared globally
//or in the local WndProc. This function assumes that the structure
//contains 2 members which are of integer and character types respectively.
The text
//will be displayed in two columns in the child window's client area. The
basic intent
//of this function is to display a few lines of text in a child window.
void L1_txtDISPLAY_ArSt2MEMB(
HDC hdc, //Handle to a device context
struct tagIdRoomIndex RIndex[], //Array of structures
TCHAR *szHeader, //Header string desired
TCHAR *szUnderL, //Underlining of header string desired
int cxChar, int cyChar, //Width and height of characters
int iMaxLCItems, //Maximum lenght of character items in structure
int iTxtBegLeft,int iTxtBegTop, //Depicts where text begins from left and
top of client
int iTabSpace, //Space in pixels between the 2 members (Column space)
bool b_TabA_LR, //Tab alignment, FALSE = left justified, TRUE = right
justified
int iMinLines, int iMaxLines) //Minimum and maximum of lines of array items
to display
{
//////////////////////////////////////////////////////////////////////////////////////////////MY VARIABLES/OBJECTS
int i,ii; //For loop variable
TCHAR *szBuffer; //Declare string variable
szBuffer = (TCHAR*) malloc(sizeof(TCHAR)*iMaxLCItems); //Allocate memory
//////////////////////////////////////////////////////////////////////////////////////////////VARIABLE INNITIALIZATIONS
ii = 0;
//*PROGRAM ORIGIN OF FUNCTION*
///////////////////////////////////////
TextOut(hdc,0,0,szHeader, lstrlen(szHeader));
SetBkMode(hdc,TRANSPARENT); //Set underlining to transparent backgroung
TextOut(hdc,0,cyChar-10,szUnderL, lstrlen(szUnderL));
for(i = iMinLines; i < iMaxLines; i++)
{
if(b_TabA_LR==FALSE){SetTextAlign(hdc,TA_LEFT);} //Select Text alignment
else{SetTextAlign(hdc,TA_RIGHT);}
TextOut (hdc,iTxtBegLeft,(cyChar * (ii+iTxtBegTop)),szBuffer,
wsprintf(szBuffer,TEXT("%d"),RIndex[i].iRoomNumber));
TextOut (hdc,cxChar * iTabSpace ,(cyChar * (ii+iTxtBegTop)) ,szBuffer,
wsprintf(szBuffer,TEXT("%s"),RIndex[i].szRoomName));
ii ++; //Always start displaying from the top line
}
free(szBuffer); //Free allocated memory
}
=================================================
David ! I don't like myself for doing this! :-( But I don't even know
where to begin to ask questions. If you compile these files you will see
errors like:
c:\_DTS_PROGRAMMING\vc++\MY_APPS_LAB\Test1_APPLICATION_1\LIB1_FHeader.h(2) :
error C2065: 'HDC' : undeclared identifier
c:\_DTS_PROGRAMMING\vc++\MY_APPS_LAB\Test1_APPLICATION_1\LIB1_FHeader.h(3) :
error C2226: syntax error : unexpected type 'tagIdRoomIndex'
But lets take the latter error for example, 'tagIdRoomIndex' is my structure
tag and the structure its declared in APP1.h which is included in
APPLICATION1.cpp. So I don't understand where the problem is.
Also another erro is:
c:\_DTS_PROGRAMMING\vc++\MY_APPS_LAB\Test1_APPLICATION_1\LIB1_Functions.cpp(25) : error C2182: 'L1_txtDISPLAY_ArSt2MEMB' : illegal use of type 'void'
I have always implemented functions this way without a problem!
I believe that all the 'includes' are done as we have discussed and all the
CALLBACKS are in their respective headers.
I am missing out on some detail that I wish you can come through for me like
you always have. I wouldn't like to have to start this post over at this
point, I think it got too complicated..... and go figure on such a simple
issue *#includes*...
Hope we can fix this, and let me know if you can come up with something.
I Appreciate it.
--
Best regards
Robert
"David Wilkinson" wrote:
Robby wrote:.
OH boy.... Thanks David, I just had replied to you with a detailed
description of what I tried after your last post but I somehow lost it, any
how I did what you said, I included every header file in it's respective '.c'
file, but still no luck.
I would like to know if it would be alright with you if I could e-mail you
the project, this would give you a clearer idea of what is going on. I would
like to have your permission before I go ahead with the e-mail. If you are
reluctant to this, well that Okay too and I understand.
Anyhow, I feel like I am in a bind, and I could read all the help files I
want, I don't know if its something else that is causing this, but I am
pretty sure I am overlooking something simple. The program is short and
simple and it did work when all but my main 'c.' file were '.h' files.
However thats weird I should be allowed to have more than 1 implementation
file '.c' in my projects.
Please let me know!
Robby:
You need to tell us what these errors are. Are they compile errors or
link errors? Remember how C/C++ compilation works: Each .c or .cpp
implementation file (translation unit) is compiled separately. So , if
you have compilation errors in any given file, focus on that file alone
for a while (compile not build in the IDE). When each file compiles by
itself, any further errors will be link errors. Either some variable (or
function) is not defined, or it is defined multiple times. Either is
bad: it must be defined exactly once.
David Wilkinson
David Wilkinson
- Follow-Ups:
- Re: In the need for some advice!
- From: David Wilkinson
- Re: In the need for some advice!
- References:
- Re: In the need for some advice!
- From: David Wilkinson
- Re: In the need for some advice!
- From: Robby
- Re: In the need for some advice!
- From: David Wilkinson
- Re: In the need for some advice!
- From: Robby
- Re: In the need for some advice!
- From: David Wilkinson
- Re: In the need for some advice!
- Prev by Date: Re: Socket connections
- Next by Date: checking whether particular exe or process is running?
- Previous by thread: Re: In the need for some advice!
- Next by thread: Re: In the need for some advice!
- Index(es):
Loading