|
When the dialog is created I use CWnd::SetTimer(0, 60000, NULL); and then I catch it with:
void CNewNotifyDlg::OnTimer(UINT nIDEvent) <br />
{<br />
OnRefresh();<br />
<br />
CWnd::SetTimer(0, 60000, NULL);<br />
<br />
CDialog::OnTimer(nIDEvent);<br />
}
OnRefresh() is my function to do my calculations and see if I should notify the user. I want this to run in the background, minimized the majority of the time, and then, if my app's logic dictates, I notify with AfxMessageBox("Hey, wake up!");
I didn't actually see the AfxMessageBox until I maximized the dialog (after I was informed that I had forgotten to do something in the office within a certain amount of time, Arrggh! ).
Danny
|
|
|
|
|
bugDanny wrote:
I didn't actually see the AfxMessageBox
Your timer is being called. Try turning your speakers on - you should hear a beep with each message box each time the timer is executed. The message box however, is in the foregound of your app, and your app is minimised - so you don't see it. (Your data file is still being written out right?)
You could do this:
if (IsIconic())<br />
{<br />
ShowWindow(SW_RESTORE);<br />
}<br />
in your timer, it will restore your dialog. Personally I don't think it's good form to be bringing windows up in front of the user like that, I'd rather minimise to the system tray and maybe use a balloon tooltip as a notification. You might want to have a look around this site for examples of that.
Again, should you be new to this... you don't need to call CWnd::SetTimer(0, 60000, NULL); in your OnTimer (and you don't need the CWnd:: bit in the first SetTimer call...)
-Dy
|
|
|
|
|
bugDanny wrote:
AfxMessageBox("Hey, wake up!");
Use MessageBox instead of the AfxMessageBox version. This should get you the desired results.
-------------------------------
DEBUGGING : Removing the needles from the haystack.
|
|
|
|
|
Is there a straight forward way to make a number like 123 and turn it into a string with left padded zeros.
Example "123" into 0000123
A way that does not require a silly loop like this.
CString strSecId;
strSecId.Format("%d", m_iSectionId);
while(strSecId.GetLength() < 7)
strSecId = "0" + strSecId; //left pad with zeros
thanks
|
|
|
|
|
Try "%.7d".
Don't try it, just do it!
|
|
|
|
|
Your code looks great until that last line. Try this:
strSecId.Insert(0, "0");
The first argument is the 0-based index of where you want to insert this string (we want it at the fron, hence the 0) and the second argument is the string to insert (a 0!)
Hope this helps!
Danny
|
|
|
|
|
Use:
strSecId.Format("%07d", m_iSectionId);
|
|
|
|
|
Don't I feel silly. Thank you.
|
|
|
|
|
Hi there,
I created a dll which creates a WH_CBT windows hook to subclass new windows.
The problem is the CBT_CREATEWND structure given as parameter to the CBTProc.
It includes a pointer to a CREATESTRUCT structure, where I need to check the lpszClass member to determine the type of window. Some values are less than 0xBFFF, so I can call GetAtomName() to get the class name, but there are also values bigger than 0xC000, which are no memory addresses. Spy++ says they are atoms, but atoms have to be less than 0xBFFF. Any ideas?
Regards,
Alex
Don't try it, just do it!
|
|
|
|
|
I’m trying to make a surface plot in a dialog based VC++ 6 application to display the data from a numerical simulation of a differential equation. I initially wrote the code using SetPixel() which works fine but takes a long time to draw and is the wrong way to do things I am told. So I am trying to write a bitmap to the screen to speed up the display time but I am hopelessly confused.
I believe my problem is with the BITMATINFO structure I am not sure how to deal with the fact that RGBQUAD is of size [1]? But I will leave that to your judgment.
What I currently have seems to work for most of the bitmap(it displays a gradient of gray as it should) but then random colors appear on the bottom of my screen (and I am not using the BITMAPINFO structure as I am sure I should).
Anyway the code I am using inside the OnPaint() event is :
CPaintDC dc(this);
int length = 8;
int size = length*length;
unsigned char *surface;
surface = new unsigned char[size];
CPalette temp_palette;
BITMAPINFOHEADER bmH;
bmH.biSize = sizeof(BITMAPINFOHEADER);
bmH.biWidth = length;
bmH.biHeight = length;
bmH.biPlanes = 1;
bmH.biBitCount = 8;
bmH.biCompression = BI_RGB;
bmH.biSizeImage = 0;
bmH.biXPelsPerMeter = 0;
bmH.biYPelsPerMeter = 0;
bmH.biClrUsed = 256;
bmH.biClrImportant = 0;
RGBQUAD pcolors[256];
LOGPALETTE *ppal = (LOGPALETTE *) new char[sizeof(LOGPALETTE) + 256*sizeof(PALETTEENTRY)];
ppal->palVersion = 0x300;
ppal->palNumEntries = 256;
for(int n=0; n< 256; n++){
ppal->palPalEntry[n].peBlue = pcolors[n].rgbBlue = n;
ppal->palPalEntry[n].peGreen = pcolors[n].rgbGreen = n;
ppal->palPalEntry[n].peRed = pcolors[n].rgbRed = n;
ppal->palPalEntry[n].peFlags = pcolors[n].rgbReserved = 0;
}
temp_palette.CreatePalette(ppal);
delete ppal;
//set surface to display a gradient and verify the code
for(n=0; n
|
|
|
|
|
Sorry everyone:
The data initialization loop was displayed incorectly It should be
for(n=0; n<size; n++){
surface[n] = (char)((int)(n/((double)size)*255));
}
|
|
|
|
|
Nick Usechak wrote:
I believe my problem is with the BITMATINFO structure I am not sure how to deal with the fact that RGBQUAD is of size [1]?
that 1 is misleading. the number of RGBQUADs is either 0, 2, 16 or 256. what you really need to know is that the palette immediately follows the BITMAPINFOHEADER, always.
so try allocating the BITMAPINFOHEADER and the palette in a single chunk of memory (allocate sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256). then, fill in the BMIH. then start filling in the palette immediately after the BMIH. pass that as the BITMAPINFO to StretchDIBits.
Nick Usechak wrote:
What I currently have seems to work for most of the bitmap(it displays a gradient of gray as it should) but then random colors appear on the bottom of my screen (and I am not using the BITMAPINFO structure as I am sure I should).
DIBs are stored bottom-down (bottom left pixel is the first byte in the pixel array). so if you see garbage at the bottom, that's a good sign that you're overwriting the start of the image pixels.
also note that the width of a DIB row needs to be an even multiple of 4. your code works for your 8x8 image, but will fail with a 9x8.
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
Chris,
I did as you suggested (I think):
I changed bmH.biSize = sizeof(BITMAPINFOHEADER);
in my code to
bmH.biSize = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256;
but it did not work. I tried some other options (before bugging you again) and found that if I use
bmH.biSize = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*34;
it works. But this makes no sense (to me) 256-the number of elements in my palette sure, but 34? I did not change anything else in my code, I think that I have the order correct? I also changed the order of my BITMAPINFOHEADER and RGBQUAD but that had no effect on the result?
By the way thanks for the tip about this only working for an even multiple of 4, otherwise I would have been perplexed about that next.
Is there any easy workaround for that?
Thanks
Nick
|
|
|
|
|
Nick Usechak wrote:
changed bmH.biSize = sizeof(BITMAPINFOHEADER
no, not like that, like this:
BYTE *pDIBHeader = new BYTE[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*256];
BITMAPINFOHEADER *pBMIH = (BITMAPINFOHEADER *)pDIBHeader;
pBMIH ->biSize = sizeof(BITMAPINFOHEAER);
etc..
RGBQUAD *pPal = (RGBQUAD *)(pDIBHeader + sizeof(BITMAPINFOHEADER));
for (int i=0; i < 256; i++)
{
pPal[i].rgbRed = pPal[i].rgbGreen = pPal[i].rggBlue = i;
}
StretchDIBits(... pDIBHeader, surface,...);
ie. make the palette and the BMIH contiguous in memory by allocating them together. biSize should always be the size of the BITMAPINFOHEADER struct itself (or one of the newer variants, which are all bigger than the original).
Nick Usechak wrote:
By the way thanks for the tip about this only working for an even multiple of 4, otherwise I would have been perplexed about that next.
Is there any easy workaround for that?
there's no workaround. that's simply how windows expects image data: bottom-up, DWORD-padded (ie. multiple of 4 bytes per row) and BGR order for 24 or 32 bit data.
Cleek | Image Toolkits | Thumbnail maker
-- modified at 15:56 Wednesday 14th September, 2005
|
|
|
|
|
Thanks a lot Chris that solved my problem, I appreciate your help.
-Nick
|
|
|
|
|
|
One small thing I can add - you are not forced to work with inverted (top-down) images.
To work with bottom-up images, set the bitmap header biHeight parameter to a negative value.
|
|
|
|
|
Hey all I hope you can help,
I need to open a dos console from within my windows enviornment, I have used CreateProcess() to do this once before but this case is more complicated.
My dos console, (lets call it (foo.exe)) takes a binary file(lets call it(input.file)) and converts it into 0-3 text files and a log file. foo.exe also requires keyboard input so that the user can tell foo.exe which of the
0-3 files to produce. What I need to do is supply foo.exe with the input.file and redirect a text file(lets call this key.txt) into foo.exe to handle the keyboard input. I can open foo.exe with just input.file and it works great, but I need this whole process to be transparent to my user, hence the need to bring key.txt in to the mix.
I have tried both a using the cmd.exe and a batch file approach and trying to do the redirection directly from the commandd line neither way works. I am not sure if I was even doing the cmd.exe, batch file version of this correctly, since I could never get it to work.
Here is what I have at the moment.
CreateProcess( NULL,
lpCommandLine,
NULL,
NULL,
0,
dwCreateFlags, <-- Set to CREATE_NEW_CONSOLE
NULL,
NULL,
&si,
&pi );
lpCommandLine is set as follows:
(I fudged the path names but you will get the general idea)
"C:\Documents and Settings\bob\very very\long\path\foo.exe "C:\Documents and Settings\bob\very very\long\path\input.file" < "C:\Documents and Settings\bob\very very\long\path\key.txt""
I have been looking around on this for a few days and know that the quotes can be a big problem?
My current permutation above opens the console window for a split second but nothing happens, the directory where the files should be created remains unchanged.
Thanks for any suggestions.
|
|
|
|
|
The easiest way to do this is to put that long command line in a batch file and run the batch file via CreateProcess() .
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
I went and tried what you suggested and I get the same result it opens the console for a split second but nothing happens,
I was able to shorten the length of the command line to
"C:\Documents and Settings\bob\very very\long\path batch.bat"
batch file = (foo input.file < key.txt)
This batch filel will work outside of my program but not when called from within it.
Any Ideas
|
|
|
|
|
Nitefall2060 wrote:
batch file = (foo input.file < key.txt)
Go ahead and qualify these three files with a path, too.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
You can do two things first
echo "input" | foo.exe
Second:
Create a Pipe Using CreatePipe Assign the out side of the pipe to the STARTUPINFO.hStdInput then set STARTUPINFO.dwflags = STARTF_USESTDHANDLES the call create process with bInheritHandles = true. The use writefile to write to the pipe and yo should be good.
A programer trapped in a thugs body
|
|
|
|
|
ky_rerun wrote:
You can...
Thanks, but I think you meant to send this to Nitefall2060.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
|
I can answer this one! This drove me batty a while ago. You cannot combine the lines together in the arguments to CreateProcess. From my code:
int rc = CreateProcess(CalExe, Arguments, NULL, NULL, NULL, 0, NULL, NULL, NULL, &ProcInfo);
CalExe has nothing but "c:\blah\file.exe". Arguments contains the arguments. I have NO idea why one would code it this way but such is life.
C. Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
|
|
|
|