|
Hi all,
got another simple/silly question.
I am trying to make an array but i need to it to be of different lengths. For one case i need it to be 2 and another to be 8. i was trying to do this:
int size = 0;<br />
<br />
if(myBool == TRUE)<br />
size = 2;<br />
else<br />
size = 8;<br />
<br />
int myArray [size];<br />
....
Can someone tell me how to do this? I thought it was possible?
Jimmy
Just cause I am 15, doesn't mean I'm dumb! (I'll really be 4 on Feb. 29...the year 2004)
|
|
|
|
|
try reading the MSDN for malloc and new (free and delete also )
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
If you are trying to exercize the KISS principle, then just create two different arrays and use your if to determine which to use. If you want to make it dynamic, use a linked list.
My code isn't buggy. Those are all fleatures.
|
|
|
|
|
|
Please,
If someone know how can I determine within my application if network cable is unplugged ?
Thank you !
Alan
|
|
|
|
|
See InternetGetConnectedState() .
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
i think this wont solve all problems.. if the lan isnt used for internet, i suppose this wont work!
Don't try it, just do it!
|
|
|
|
|
check the ip interfaces.. if the network cable is unplugged, there wont be any ip interface for the adapter(on win2k and later).
Don't try it, just do it!
|
|
|
|
|
Ok, thank you, sound's great, but since I'm almost new in this world, can you please give me some line of code ?
Tnx
|
|
|
|
|
Maybe you use this code, its working for all known cases.
ok, its working at least for all my cases
bye
mario
1) InternetCheckConnection ( Checks for Google )
2) InternetAttemptConnect ( Windows Function )
3) IsModem Connected ( Modem Connection )
4) gethostbyname ( Google )
5) InternetGetConnectedState ( LAN )
6) Dont check for Internetconnection
// Check if Online
BOOL WINAPI IsADSLConnected()
{
LPDWORD lpdwFlags=0;
DWORD dwReserved=0;
RASCONN rc;
rc.dwSize = sizeof(rc);
DWORD numConns=0;
DWORD size=0;
DWORD res;
do {
switch(g_m_ConMode) {
case 0:
try {
g_IsConnected=InternetCheckConnection("http://www.google.com",FLAG_ICC_FORCE_CONNECTION ,0);
}
catch(...) {
g_m_ConMode = 4;
}
break;
case 1:
res = InternetAttemptConnect(0);
if(res == ERROR_SUCCESS) g_IsConnected = 1;
else g_IsConnected = 0;
break;
case 2:
// Enumerate the connections.
res = RasEnumConnections(&rc, &size, &numConns);
if (numConns > 0 || InternetGetConnectedState(lpdwFlags,dwReserved)) g_IsConnected = 1;
else g_IsConnected = 0;
break;
case 3:
if (gethostbyname ("www.google.com")) g_IsConnected = 1;
else g_IsConnected = 0;
break;
case 4:
g_IsConnected = 0;
if (::InternetGetConnectedState (&dwReserved, 0)) {
if ((dwReserved & INTERNET_CONNECTION_LAN) ||
(dwReserved & INTERNET_CONNECTION_MODEM) ||
(dwReserved & INTERNET_CONNECTION_PROXY))
{
g_IsConnected = 1;
}
}
break;
case 5:
g_IsConnected = 0;
break;
}
Sleep(2500);
} while(1);
}
|
|
|
|
|
Can you help me also with next one more thing: if I detect that I'm connected on my LAN, how can I measure speed between my pc and server (I know only name of that server).
Tnx
|
|
|
|
|
try to use SNMP, but thats not trivial, i'am currently working on the same thing
|
|
|
|
|
In the interface I'm creating I have a dialog box that opens up containing a bitmap. Something different will happen depending on where on the bitmap the user clicks. I have 2 bitmaps, the "real" and the "template". I don't know why, but when the user clicks on the bitmap, the colour values are being read from the real bitmap and not the template one. I think the problem comes from this bit of code, but I'm not completely sure why:
in my constructor:
...
HBITMAP hTemplateBMP;
hTemplateBMP = ::LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_PERIODIC_TMPL));
...
in my on clicked message handler:
POINT pt;
CDC *pDC = NULL;
CDC memDC;
HBITMAP hOldBMP = NULL;
COLORREF crColourAtPoint = 0;
GetCursorPos(&pt);
m_periodicBitmap.ScreenToClient(&pt);
pDC = m_periodicBitmap.GetDC();
memDC.CreateCompatibleDC(pDC);
hOldBMP = (HBITMAP)memDC.SelectObject(hTemplateBMP);
crColourAtPoint = GetPixel(memDC.m_hDC, pt.x, pt.y);
...
IDB_PERIODIC_TMPL is the template for my bitmap...
I believe crColourAtPoint ends up being the colour of the point in the real bitmap, not the template bitmap. Why??
|
|
|
|
|
For one thing, you are mixing MFC with Win32 GDI and that tends to get confusing.
Instead of using HBITMAP, use a CBitmap and the code should look like this:
in my constructor:
...
CBitmap TemplateBMP;
TemplateBMP.LoadBitmap(IDB_PERIODIC_TMPL);
...
in my on clicked message handler:
POINT pt;
CDC *pDC = NULL;
CDC memDC;
CBitmap OldBMP = NULL;
COLORREF crColourAtPoint = 0;
GetCursorPos(&pt);
m_periodicBitmap.ScreenToClient(&pt);
pDC = m_periodicBitmap.GetDC();
memDC.CreateCompatibleDC(pDC);
OldBMP = (CBitmap*)memDC.SelectObject(&TemplateBMP);
crColourAtPoint = GetPixel(memDC.m_hDC, pt.x, pt.y);
...
"It is better to remain silent and be thought a fool than to open one's mouth and remove all doubt." - Abraham Lincoln
|
|
|
|
|
Thanks. That didn't really change anything though. I was using those files you sent me before as a reference. You know how you made those periodic table bitmaps? I was just reading in the colours that you had in that exel file you sent along with the bitmaps, should I go through and re-do the template bitmap along with the colour values in that excel file in order to make it set up as r, g, b not just a single colour value? I put this in thinking it would work, but maybe that's where my problem is actually coming from:
//get the colour value from the string read in from the file
cstrInfo = breakString(cstrLine, &strPos);
int intColour = atoi(cstrInfo);
r = GetRValue(intColour);
g = GetGValue(intColour);
b = GetBValue(intColour);
//SetColour takes COLORREF as it's parameter
BmpItem.SetColour(RGB(r,g,b));
the value of crColourAtPoint is always soo much more than the value returned by the GetColour function (which is COLORREF)
|
|
|
|
|
The csv file I sent you uses just a COLORREF rather than the RGB components.
BmpItem.SetColour(atol(cstrInfo));
"It is better to remain silent and be thought a fool than to open one's mouth and remove all doubt." - Abraham Lincoln
|
|
|
|
|
OOOHHHH!!! I wasn't too sure what a COLORREF was.
is this:
CBitmap *OldBMP;
OldBMP = memDC.SelectObject(&TemplateBMP);
the same as:
CBitmap OldBMP;
OldBMP = (CBitmap*)memDC.SelectedObject(&TemplateBMP);
memDC.SelectedObject(&TemplateBMP) returns a CBitmap*....
|
|
|
|
|
No, its not the same.
OldBMP in the second example is a CBitmap, not a CBitmap pointer.
SelectObject returns a CBitmap pointer, so you don't have to cast it. That was a mistake.
"It is better to remain silent and be thought a fool than to open one's mouth and remove all doubt." - Abraham Lincoln
|
|
|
|
|
I'm doing something seriously wrong. No matter where I click on the bitmap, crColourAtPoint is ALWAYS set at 16777215. I don't understand why.
CBitmap TemplateBMP;
...
TemplateBMP.LoadBitmap(IDB_PERIODIC_TMPL);
...
POINT pt;
CDC *pDC = NULL;
CDC memDC;
COLORREF crColourAtPoint = 0;
CBitmap *hOldBMP = NULL;
//obtain the point where the click occurred on the bitmap
GetCursorPos(&pt);
m_periodicBitmap.ScreenToClient(&pt);
pDC = m_periodicBitmap.GetDC();
memDC.CreateCompatibleDC(pDC);
hOldBMP = memDC.SelectObject(&TemplateBMP);
crColourAtPoint = GetPixel(memDC.m_hDC, pt.x, pt.y);
CString colourString;
colourString.Format("Colour clicked: %d", crColourAtPoint);
AfxMessageBox(colourString);
|
|
|
|
|
Make sure your pt.x and pt.y are accurate.
"It is better to remain silent and be thought a fool than to open one's mouth and remove all doubt." - Abraham Lincoln
|
|
|
|
|
They appear to be. I mean, the values will remain the same if i click in the same spot, and they'll change (in what seems to be correct) if i click in a different spot.
Out of all the elements, only 3 of them end up getting a 'matching colour' when they're clicked on. The code that I've cut and pasted into these messages all looks right though doesn't it?
Maybe I'll just re-do the template bitmap or something... I don't really know what else to do.
|
|
|
|
|
I've just submitted an article about this. You can check out the demo files/source code at:
http://www.bj-consulting.com/tln/pte_demo.zip[^]
I didn't go the bitmap route though. It is a really nifty way of determining which element was clicked on, but if you later decided you wanted to include the dicovery date of the element (or any other text) then you would have to edit your bitmap by adding text in 117 different places and when you scaled your window the text would start to look all pixellated and illegible.
The code to draw the entire table is only 14 lines and it is scalable as you change the window size. It also highlights all of the elements in the chemical group you have selected with a red border. Right clicking an element adds it to the listbox, double clicking opens a dialog box with the chemical details. Thew controls are also resizable.
Oh - it includes an MS-Access database with the elemnt info - you'll need to create an ODBC mapping to the DB - just name the datasource PeriodicTableApp
|
|
|
|
|
Thanks.
I did decide on the bitmap 'route' though. Mainly because the bitmap will only have to display the element symbol (ie. H, C, etc..) and atomic number, and I only ever require to use the element symbol. I know that even in future versions of my interface, there will be no further information required...
Although I'm still having problems getting the colours to match up. It only works right for 3/92 elements (93-110 were removed because they won't ever be used for this)...
|
|
|
|
|
Hi,
How do I make a Dialog Box Pop up as soon as it recives a event from a different process.
Thanks and Regards,
Deepak Samuel
|
|
|
|
|
SendMessage with ShowWindow
Check MSDN
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|