|
i have tried this also... but this also does not work.. You know what happend if i click anywhere on my desktop or elsewhere than message starts going. i dont quiet understand whats happening.
|
|
|
|
|
Have you tried SendMessage instead? Other than that I am not sure what to suggest.
If you vote me down, my score will only get lower
|
|
|
|
|
i have tried that also i am afraid that also does not work.. i tried SendInput() with MOUSE_EVENT just to simulate the click event than this message is going but sometimes what happens this SendMessage goes to the default button in the window. The button i want to send the message is not the default button.
|
|
|
|
|
The following code snippet read data from keyboard and write into one file;
and read that file and display it on screen....But it displays junk characters....
What may be the problem ...?
// main.c
#include <stdio.h>
int main(void){
char ch;
FILE *fp;
fp = fopen("test_file_src","w");
printf("\n Eneter the data (type Ctrl^D at end :\n");
if (fp != NULL) {
while(ch = getchar() != EOF)
fputc(ch ,fp);
} else {
printf("\n Unable to create file \n");
}
fclose(fp);
printf("\n\n Reading from file\n\n ");
fp = fopen("test_file_src","r");
if (fp != NULL) {
while(!feof(fp)) { // Move up to end of file
ch = fgetc(fp);
putchar(ch);
}
} else {
printf("\n Unable to process file \n");
}
fclose(fp); // Close file
printf("\n\n\n");
return 0;
}
/* Output
Enter the data (type Ctrl^D at end :
11111111111111222
2222222222222222222
22222222222222222
Reading from file
|
|
|
|
|
while(ch = getchar() != EOF)
should be
while((ch = getchar()) != EOF)
The assignment operator has lowest precedence of all in C.
|
|
|
|
|
I am having a strange problem. When debugging using Code::Blocks, the following function returns the correct answers. However, when I am not debugging, it gives a correct answer the first time. Subsequent calls to the SAME function using the SAME parameter results in different answers, but not without a pattern:
The first three calls result in return values that are close to each other, after that, the return values are completely different from the first three, but identical to each other.
like so:
0.29012
0.29013
0.29102
0.42030
0.42030
...
double CalculateMSE( std::vector< complex<double> > inputv)
{
int N = inputv.size();
int M = 2*N+int(0.1*double(N) + 0.5);
int K = 100;
int T = M;
std::vector<double> m = mylinspace(0, M-1, M);
std::vector<double> k = mylinspace( -1 * ceil(K/2), K/2, K+1);
std::vector<double> freq_samples;
for( int i=0; i < k.size(); i++)
freq_samples.push_back( k[i] / T );
std::vector<double> sinc_pulse( freq_samples.size() );
sinc_pulse = mysinc(freq_samples);
std::vector< std::vector< double > > sinc_pulse2;
for(int i=0; i < m.size(); i++)
{
sinc_pulse2.push_back( sinc_pulse );
}
std::vector< matrix< std::complex<double> > > B;
matrix< std::complex<double> > exp_freq_samples;
std::complex<double> cplx_j(0,1);
matrix< double > mx_freq_samples( 1, freq_samples.size() );
for( int i=0; i < freq_samples.size(); i++)
{
mx_freq_samples(0,i) = freq_samples[i];
}
matrix< double > mx_m(1, m.size());
for( int i=0; i < m.size(); i++)
{
mx_m(0,i) = m[i];
}
matrix< double > mx_sinc_pulse( sinc_pulse2.size(), sinc_pulse2[0].size() );
for( int i=0; i<mx_sinc_pulse.size1(); i++)
{
for( int j=0; j<mx_sinc_pulse.size2(); j++)
{
mx_sinc_pulse(i, j) = sinc_pulse2[i][j];
}
}
mx_sinc_pulse = trans(mx_sinc_pulse);
matrix< double > mx_pp(1, m.size());
matrix< double > trans_freq_samples( trans(mx_freq_samples) );
complex< double > cplx_tmp = -1.0 * cplx_j * 2.0 * PI;
for( int i=0; i<N; i++)
{
matrix< std::complex<double> > Bmat;
for (unsigned j = 0; j <mx_pp.size1 (); j++)
for (unsigned jj = 0; jj <mx_pp.size2 (); jj++)
mx_pp (j, jj) = i + m[jj];
Bmat = prod(trans_freq_samples, mx_pp);
Bmat *= cplx_tmp;
for( int j=0; j < Bmat.size1(); j++)
{
for( int jj=0; jj < Bmat.size2(); jj++)
{
Bmat(j, jj) = mx_sinc_pulse(j, jj) * exp(Bmat(j, jj));
}
}
B.push_back( Bmat );
}
matrix< complex<double> > P(K+1,M);
for (int i=0; i < inputv.size(); i++)
{
P = inputv[i] * B[i] + P;
}
matrix< double > Kg(M, 1);
for( int i=0; i<Kg.size1(); i++)
Kg(i, 0) = 1;
matrix< complex<double> > transP;
matrix< complex<double> > tmpP = prod(herm(P) , P);
matrix<double> mag_pi_sqrd(tmpP.size2(), 1);
for( int i=0; i<mag_pi_sqrd.size1(); i++)
{
mag_pi_sqrd(i, 0) = real(tmpP(i,i));
}
matrix< double > MSE_tmp(M, 1);
double sumtotal = 0;
for( int i = 0; i < M; i++)
{
matrix< complex<double> > p_i(P.size1(), 1);
matrix< complex<double> > p_j(P.size1(), M-1);
for(int j=0; j < P.size1(); j++)
{
p_i(j, 0) = P(j, i);
}
for(int j=0; j < M-1; j++)
{
int ix = j;
if( j >= i )
ix++;
for(int jj=0; jj < P.size1(); jj++)
p_j(jj, j) = P(jj, ix);
}
matrix< complex<double> > hp_i = herm(p_i);
matrix< complex<double> > prodhpi_pj = prod( hp_i, p_j );
matrix< complex<double> > hermprodhpi_pj = herm(prodhpi_pj);
matrix< double > mag_rhoij = real( prod( prodhpi_pj , hermprodhpi_pj ) );
MSE_tmp(i, 0) = (Kg(i,0) * mag_rhoij(0,0)) / (mag_pi_sqrd(i,0)*mag_pi_sqrd(i,0));
sumtotal += MSE_tmp(i, 0);
}
sumtotal = sumtotal/double(M);
return sumtotal;
}
Any ideas?
|
|
|
|
|
this might give you ideas at some things to look for Surviving the Release Version[^]
apart from that, you dont seriously expect anyone here to read that code do you ? with no comments/clue as to what it's supposed to achieve ?
'g'
|
|
|
|
|
The code is meant to calculate the MSE of a transmit code for synthetic aperture radar systems. I really only included it in case someone wanted to dig through it. I guess I meant my question to be more general. As in, "Given any function with only local variables, why would this behavior occur? (by the way, here's such a function)"
|
|
|
|
|
sorry, didnt see this - my b/berry didnt synch or was off the network for some reason ..
As KarstenK says below, which was a also the point of the link I pasted, make sure everything is initialised to a value you expect - even a matrix, where the system has gone out and grabbed chunks of memory for the cells, may not be 'clean' - so if you're doing a calc across the matrix and there's cr@p in the middle, bingo
'g'
|
|
|
|
|
Posted code contains many instances of your own classes. Since we don't know about them, how could help?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Ah, my mistake, I did not copy the includes. The classes used are all defined in the boost ( http://www.boost.org/[^]) template library and in the STL. Matrix is boost's ublas implementation, complex and vector are STL.
|
|
|
|
|
if debug != release it is often an contruction issue.
is std::vector< complex<double> > properly initilized?
or the use of some static members can often lead to damages
make som output in the long function to find WHERE it happens
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
I am trying to save the content in IPicture to JPG. CImage seems to promising. However I can't use MFC or ALT. Thanks in advance...
|
|
|
|
|
Have you tried this?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Thanks very much for your reply. I figured out the solution by myself. I ended up with using Gdi+. What I did was:
1) Create IStream and save content of IPicture to this stream;
2) call Gdiplus::Image::FromStream to load this BMP format stream into image;
3) By passing in the JPG format ClsID, I called Save to save this image to JPG format stream. This is all I needed. Of course, you can save it out as a file.
|
|
|
|
|
Here is simplest way for save jpg and... formats CImage class.
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Hello everybody!
I'm working on a small personal project which has to use async sockets. So far I've not yet finished the GUI (since I'm coding it with pure WinAPI, it's going to take some time) but i thought to give it a shot and see if it's processing all specified messages in WndProc but so far i realized that it isn't processing network messages. Here's a sample code from my project:
int WINAPI WinMain(HINSTANCE currentInst,
HINSTANCE prevInst,
LPSTR args,
int showVar)
{
WSADATA wsaData;
if(WSAStartup(0x0202, &wsaData))
{
MessageBox(NULL,"Call to WSAStartup() failed at line #", "Error!", MB_ICONEXCLAMATION | MB_OK);
WSACleanup();
return wsaFail;
}
else
{
if(wsaData.wVersion != 0x0202)
{
MessageBox(NULL,"Wrong socket version! at line #", "Error!", MB_ICONEXCLAMATION | MB_OK);
WSACleanup();
return wsaFail;
}
}
WNDCLASSEX windowClass;
HWND handleToWindow;
SOCKET serverSocket;
sockaddr_in serverSockAddrIn;
MSG Msg;
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style = CS_HREDRAW | CS_NOCLOSE | CS_VREDRAW;
windowClass.lpfnWndProc = WndProc;
windowClass.lpszClassName = class_name;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = currentInst;
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 6);
windowClass.lpszMenuName = NULL;
windowClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&windowClass))
{
MessageBox(NULL, "Window Registration Failed at EntryPoint.cpp line #", "Error!", MB_ICONEXCLAMATION | MB_OK);
return windowRegistrationFail;
}
handleToWindow = CreateWindowEx(WS_EX_CLIENTEDGE | WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST,
class_name,
"Server Console",
WS_OVERLAPPED| WS_VISIBLE,
400, 500, 800, 500, NULL, NULL, currentInst, NULL);
if(handleToWindow == NULL)
{
MessageBox(NULL, "Window Creation Failed at line #", "Error!", MB_ICONEXCLAMATION | MB_OK);
return windowCreationFail;
}
UpdateWindow(handleToWindow);
memset(&serverSockAddrIn, 0, sizeof(serverSockAddrIn));
serverSockAddrIn.sin_family = AF_INET;
serverSockAddrIn.sin_port = htons(2567);
serverSockAddrIn.sin_addr.s_addr = htonl(INADDR_ANY);
serverSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(serverSocket == INVALID_SOCKET)
{
MessageBox(NULL, "Socket Creation Failed at EntryPoint.cpp line#", "Error!", MB_ICONEXCLAMATION | MB_OK);
WSACleanup();
return socketFail;
}
WSAAsyncSelect(serverSocket, handleToWindow, NetworkNotification, FD_ACCEPT | FD_READ | FD_WRITE | FD_CLOSE);
if(bind(serverSocket, (sockaddr*)&serverSockAddrIn, sizeof(serverSockAddrIn)) == SOCKET_ERROR)
return 0;
while(GetMessage(&Msg, NULL, 0, 0) > 0)
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return 0;
}
So far this is the whole entry point of my program. Keep in mind that it's not finished yet. Please do not reply with coments like "You should error check at x" etc. if it's not a possible fix for my problem.
WndProc (showing only network messages):
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case NetworkNotification:
{
switch(WSAGETSELECTEVENT(lParam))
{
case FD_ACCEPT:
{
MessageBox(hwnd, "Success!", "Test", NULL);
break;
}
case FD_READ:
break;
case FD_WRITE:
break;
case FD_CLOSE:
break;
}
}
case WM_COMMAND:
{
}
case WM_CREATE:
{
}
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
I repeat...it's not the whole WndProc here. Unless it's really needed i wouldn't like to post it all.
As far as I'm aware, it should show the message box when a client is trying to connect, but of course.. since i'm not calling accept() the client won't be able to connect but it still should trigger a FD_ACCEPT event...right ?
Ahh...i almost forgot..
#define NetworkEvent (WM_USER + 5)
modified on Friday, January 8, 2010 8:32 AM
|
|
|
|
|
What is the value of "NetworkNotification"? Unless it's a valid WM_xxx type message it will not be getting dispatched to your WndProc.
|
|
|
|
|
Member 4054478 wrote: As far as I'm aware, it should show the message box when a client is trying to connect, but of course.. since i'm not calling accept() the client won't be able to connect but it still should trigger a FD_ACCEPT event...right ?
Yes, but you should also listen to incoming connections on the server side: socket , WSAAsyncSelect , bind , listen
Let me know if this fixes it. When implementing an own asynchronous network class, think about adding a DNS resolver later on... otherwise hostname lookups will be blocking everything (they can take quite a while).
/M
|
|
|
|
|
|
can i have an example using this method?
|
|
|
|
|
Searching[^] is not so difficult.
Neither reading first[^].
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
|
No comments.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
can you define "POLYGON" ?
|
|
|
|
|