|
Arhh i can't modify my message anymore!! it says it wasn't posted by me, and loox!! the lil head is dark, but i'm not anonymous!! Itzzz buggyy, someone fix o't! lol
Kuniva
--------------------------------------------
|
|
|
|
|
P.S.: please don't ban me lol
Kuniva
--------------------------------------------
|
|
|
|
|
It's called "bèta-testing" i swear!
Do i get any points for finding these bugs, maybe platina level??? hmmm??
Kuniva
--------------------------------------------
|
|
|
|
|
I'm a little confused here cuz if you're saying that an application is listening to broadcast UDP packets and it needs the broadcaster's source address, then you don't need raw mode.
Regular Winsock API programming of a UDP socket can transmit a broadcast message which automatically inserts the IP address (as the source IP) of the computer sending the broadcast message. This is handled by Winsock. You simply just setup the in_addr structure with the remote port and IP address that you are sending a message to, setup your data field, and you don't have to put in any of the raw type parameters like length of fields, checksums, source IP address, or anything like that. All of that is done for you. You only have to specify the char array that holds your data and the length of it in the sendto() function.
Oh yeah, I forgot. You also have to do a setsocketopt() with a SO_BROADCAST option. Here's some code:
WSADATA wsaData;
SOCKET sock;
SOCKADDR_IN dst_addr;
char sampleMsg[132];
int optval = 1;
int optlen = sizeof(int);
dst_addr.sin_family = AF_INET;
dst_addr.sin_port = htons(myPort);
dst_addr.sin_addr.s_addr = inet_addr("255.255.255.255");
strcpy(sampleMsg, "This is a test sample msg from the box. ");
rc = WSAStartup (MAKEWORD (1, 1), &wsaData);
if(rc != 0)
{
}
sock = socket(AF_INET,SOCK_DGRAM, 0);
if(sock == INVALID_SOCKET)
{
}
rc = setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char *)&optval, optlen);
if(rc == SOCKET_ERROR)
{
}
while(!kbhit())
{
printf("Sending data: %s Any key to quit.\n", sampleMsg);
rc = sendto(sock, sampleMsg, strlen(sampleMsg) + 1, 0, (struct sockaddr*) &dst_addr, sizeof(dst_addr));
if(rc == SOCKET_ERROR)
{
}
Sleep(1000);
}
|
|
|
|
|
em..yea.. i was affraid you might not understand.
See, I know how to broadcast packets, and i know winsock fills in the ip for me, but thats exactly what i DONT want. I want to fill in the source ip myself, i want to change it to any ip i want, i need this because i need to pretend there is another computer present which is broadcasting ip packets from it's ip, while infact they are coming from the same computer on which the application is running that is listening for the broadcasted packets.
I hope this claryfies things...
Kuniva
--------------------------------------------
|
|
|
|
|
Yeah, I misunderstood. Was wondering why you were doing everything lately in raw mode. Sorry.
|
|
|
|
|
Yea, been working in raw mode a lot lately, wanted to figure it all out, but i still want my application to run on win9x. So no ideas for changing the source ip on win9x?
Kuniva
--------------------------------------------
|
|
|
|
|
Sorry, I had no idea that raw mode wouldn't work on 9x....I just assumed that you needed Winsock 2.0 and if it wasn't installed on 9x, you just install it. I had run into an issue before about trying to put a network card into promiscuous mode and that it would only work on Win2K (of course now I could just use the winpcap lib) but I didn't know about the raw mode restriction too.
Maybe something in that WinPCap library could help you accomplish what you want to do. It's at http://winpcap.polito.it/ Winpcap is used in many products one of which is the freeware sniffer/analyzer, ethereal.
|
|
|
|
|
Yea.. thanks for replying, but kind of already use ethereal and Winpcap, don't think u can use winpcap for generating though, but i'll look into it.
But anyways, thanks for replying, and if i ever do get it sorted, i'll be sure to post an article about it here on CP.
P.S.: And i will get it sorted! Grrrrrrrrrr....
Kuniva
--------------------------------------------
|
|
|
|
|
i search the owner draw edit control in codeguruAcodeproject and google web site, but nothing is found, someone give me "FlatEdit",but it call the default drawing function when draw it.
such as:
void CFlatEdit::OnPaint()
{
Default();
~~~~ i want to known how Default function do draw
DrawEdit(FE_MOUSEOUT, m_clrButton, m_clrButton);
}
some Win32 SDK/MFC example or slice code are expected, thanks!
|
|
|
|
|
There's a good reason for the lack of owner draw for the text in the edit control.
It's hard!
There's a lot to worry about. Fonts, insertion points, highlighted (highlit?) sections,
wrapping, caret, etc.
Also, the edit control has been round for a *long* time and is not as well "exposed" as
the more modern ones.
For a replacement which does its own text formatting I would suggest looking at the
crystal edit control[^] here on CP.
Iain.
|
|
|
|
|
thank you very much!
Now I is studying "crystal edit control",i found it solve some problem you note above. But CEdit is so hard to full owner draw? I only need one line single and basic CEdit, search example and other's discussion until I can programme do it myself.
And expect someone can give me more suggest or examples.
C/C++ code fans
|
|
|
|
|
In my project, i just PNG's for the GUI's graphics. I can paint them on the canvas using StretchDIBits. Problem is that my project has some dialogs too, in which i use Static controls to hold a BMP image. Is there a way to convert a DIB image to a BMP handle that i can use in such a dialog other than writing the Dib as a BMP to the harddisk and loading it again?
|
|
|
|
|
The following steps should do it:- Create a bitmap compatible with the screen device context.
- Create a memory device context compatible with the screen.
- Select the bitmap created in step 1 into the DC created in step 2. Be sure to save the return value, so you can restore the original bitmap.
- Draw the PNG into the memory device context using
StretchDIBits , or whatever's appropriate. - Restore the original bitmap into the memory device context. This 'detaches' the bitmap created in step 1 from the memory device context.
The bitmap created in step 1 now contains the image from the PNG, rendered in a fashion that's compatible with the screen. You can then use SetBitmap to display the image in the static controls in your dialog.
Software Zen: delete this;
|
|
|
|
|
well i did it this way:
<br />
HDC hDC = GetDC();<br />
HDC memDC = CreateCompatibleDC ( hDC );<br />
HBITMAP memBM = CreateCompatibleBitmap (hDC,dib->biWidth,dib->biHeight);<br />
HBITMAP memBM2 = CreateCompatibleBitmap (hDC,dib->biWidth,dib->biHeight);<br />
memBM2 = (HBITMAP)SelectObject ( memDC, memBM );<br />
<br />
StretchDIBits(memDC,0,0,dib->biWidth,dib->biHeight,0,0,dib->biWidth,dib->biHeight,lpbits,(LPBITMAPINFO)&dib,DIB_RGB_COLORS,SRCCOPY);<br />
<br />
memBM = (HBITMAP)SelectObject(memDC,memBM2);<br />
ReleaseDC(memDC);<br />
<br />
CStatic temp = GetDlgItem (IDC_LOGO);<br />
temp.SetBitmap((HBITMAP)memBM);<br />
and it only draws a black square...size is ok though...
|
|
|
|
|
You don't need to create the second bitmap, as it is returned by SelectObject() . Also, you're overwriting memBM with the second SelectObject() . Try this:
HDC hDC = GetDC();
HDC memDC = CreateCompatibleDC ( hDC );
HBITMAP memBM = CreateCompatibleBitmap (hDC,dib->biWidth,dib->biHeight);
HBITMAP memBM2;
memBM2 = (HBITMAP)SelectObject ( memDC, memBM );
StretchDIBits(memDC,0,0,dib->biWidth,dib->biHeight,0,0,dib->biWidth,dib->biHeight,lpbits,
(LPBITMAPINFO)&dib,DIB_RGB_COLORS,SRCCOPY);
SelectObject(memDC,memBM2);
ReleaseDC(memDC);
CStatic *temp = (CStatic*)GetDlgItem (IDC_LOGO);
temp->SetBitmap((HBITMAP)memBM);
Also make sure that your BITMAPINFOHEADER is setup correctly. I assume it is because you mentioned you can draw it elsewhere. If the image is 256 colours or less, the BITMAPINFOHEADER structure is NOT equivalent to a BITMAPINFO structure. The BITMAPINFO structure contains a BITMAPINFOHEADER plus the colour table. If the image has more than 256 colours, the colour table is not used and not required. For less than 256 colours it is.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
If you've got a HBITMAP handle for your DIB, then the static control will display it directly.
To create an HBITMAP from DIB data, use CreateDIBitmap() .
Hope this helps
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Nice answer. I had a feeling mine was too complicated .
Software Zen: delete this;
|
|
|
|
|
Thanks. I got a bit confused when he started out talking about PNGs, but then he said his question was how to convert a DIB to a HBITMAP, so that bit was easy . I just assumed the PNG to be a typo or unnecessary information.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
I dont think i can use this sollution because i only have these things handy:
BITMAPINFOHEADER dib;
int dib_size, dib_bits_offs;
char * lpbits;
So i don't see how i can work with that functions...
|
|
|
|
|
That's all you need. The BITMAPINFO structure is simply a BITMAPINFOHEADER followed by a colour table, which I assume you've got. If your image is 16-bit or above, no colour table is needed, so you don't have to worry about it.
For a 16, 24, or 32-bit image, just do this:
BITMAPINFO bi = { dib, 0 };
HBITMAP hbm = CreateDIBitmap(hDC, &dib, CBM_INIT, lpbits, &bi, DIB_RGB_COLORS);
For a 256 or less colour image, you'll need to include the colour table in the BITMAPINFO structure.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Great , it works!
Thank you all
|
|
|
|
|
Hi,
I made a worker thread in my program, and i used CDaoRecordset::GetFieldValue function in the thread.
But every time i got access violation error
Does CDaoRecordset class support threads ?
It's my source code:
while( !theApp.m_EleTele.IsEOF() )<br />
{<br />
pDlg->dwRecords.Add( theApp.m_EleTele.GetAbsolutePosition() ); <br />
pDlg->m_List.AddString( theApp.m_EleTele.GetFieldStr( pDlg->strField ) );<br />
theApp.m_EleTele.MoveNext();<br />
}
GetFieldStr is made by myself and it returns string.
Regards,
Hadi
|
|
|
|
|
If I want to open a modal dialogue in one of multi-thread app, how can I realize this?
......
dlg.DoModal();
......
Thank you in advance!
LeonOrient
|
|
|
|
|
See this article[^] in the MSDN on creating user-interface threads. You can call dlg.DoModal() in the InitInstance member function of your thread class.
Software Zen: delete this;
|
|
|
|
|