|
Whee thanks! I always miss the obvious :p
|
|
|
|
|
Need Nice OSDesktop!
I wrote the follwing code to write a sample text everywhere of desktop so on clock. But I can not delete it by my program!!!
You can test this in a simple DialogBase program.
Please guid me
void CMyProgDlg::OnShowResolution() <br />
{<br />
CString sTempMsg;<br />
<br />
hWnd = GetDesktopWindow()->GetSafeHwnd();<br />
hdc = ::GetWindowDC( hWnd );<br />
nSDC = SaveDC( hdc );<br />
<br />
DEVMODE dd;<br />
ZeroMemory(&dd, sizeof(dd));<br />
dd.dmSize = sizeof(dd);<br />
EnumDisplaySettings( NULL, ENUM_CURRENT_SETTINGS, &dd);<br />
<br />
CFont oldFont,newFont;<br />
LOGFONT lfA;<br />
ZeroMemory( &lfA, sizeof( LOGFONT ) );<br />
lstrcpy( lfA.lfFaceName, "Comics Sans MS" );
int nSize = 10;<br />
<br />
lfA.lfWeight = FW_DEMIBOLD;<br />
lfA.lfHeight = 2 * nSize;<br />
lfA.lfWidth = 1 * nSize;<br />
newFont.CreateFontIndirect( &lfA );<br />
<br />
SelectObject( hdc, newFont );<br />
<br />
<br />
SetBkMode(hdc, TRANSPARENT);
SetBkColor( hdc, NULL );
COLORREF oldColor = SetTextColor(hdc, RGB(170,255,50) );
SetTextAlign( hdc, TA_RIGHT);<br />
<br />
TEXTMETRIC tm;<br />
GetTextMetrics( hdc, &tm );<br />
<br />
int x = dd.dmPelsWidth-5 , y=35;<br />
int FarNextLine = tm.tmHeight;<br />
<br />
sTempMsg.Format( "My Display Setting..." );<br />
TextOut( hdc, x, y, sTempMsg, strlen( sTempMsg ) );<br />
<br />
<br />
<br />
y += 2*FarNextLine;<br />
sTempMsg.Format("Resolution : [%4d , %4d]",<br />
dd.dmPelsWidth, dd.dmPelsHeight );<br />
TextOut( hdc, x, y, sTempMsg, strlen( sTempMsg ) );<br />
<br />
y += FarNextLine;<br />
sTempMsg.Format("Color=%2dBits", dd.dmBitsPerPel );<br />
TextOut( hdc, x, y, sTempMsg, strlen( sTempMsg ) );<br />
<br />
y += FarNextLine;<br />
sTempMsg.Format("RefreshRate=%3d Hz", dd.dmDisplayFrequency );<br />
TextOut( hdc, x, y, sTempMsg, strlen( sTempMsg ) );<br />
<br />
SetTextColor(hdc, oldColor );<br />
<br />
}<br />
|
|
|
|
|
|
when i call this dll funciton in vb ,it is saying cant find dll entry point.i have only one cpp file which has code as below.
what is the error.what should i do.
i want to call createwindow function .
#include "stdafx.h"
#include "Shellapi.h"
extern "C"__declspec(dllexport) void __stdcall CreateWindowFunction(void);
extern "C" __declspec(dllexport) BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
hModule=hModule;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
extern "C" __declspec(dllexport) void __stdcall CreateWindowFunction()
{
MessageBox(NULL,"Called","CreateWindowFunction",MB_OK);
}
|
|
|
|
|
I wrote a new program and distributed it freely to my user.
I upgrade my program frequently. But I can't email it to my user frequently.
Therefore, please someone write me a simple code that how can my program has the following option: "Check for newer version every x day".
|
|
|
|
|
anata wrote:
Therefore, please someone write me a simple code that how can my program has the following option
I'm pretty sure that noone is goint to write the program for you, but I'll bet that a lot of people is going to answar your questions if you ask "How can I do this", instead of "write it for me"...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Ok Anders and other programmers,
"How can I do that ... ?", please.
That job must be hide until detect new version.
|
|
|
|
|
Please help to find a source for bitmap editor like used in MFC
and by the way, does anyone know how to serialize CDC with all its components together wist other info like ints, chars, etc.
my mail is:alex_kuleshov@hotmail.com
|
|
|
|
|
Will loading a bitmap that is part-of RC using resource ID render? Have bug in OnDraw. In debug, the data bits in the HBITMAP are null. Hence, a BitBlt transfers nothing to DC. Any code clips or thoughts on how to render a CBitmap loaded from resouce ID would be appreciated? Note: The bitmap is > 256 bits, so IDE claims it can't render it in editor. In any other editors, the image renders.
michael
|
|
|
|
|
Hi All:
I have 3 questions on using MFC to do some GUI stuff. I am currently building a simulation, thus, I need to show some feedback to the user once the simulation starts. For example, I could be simulating a bouncing ball. Once the user clicks "Start", the simulation will run based on certain changing parameters (like speed of ball, height of ball etc) and feedback graphically to the user through a display window.
Qn1. May I know how can I make the display window refresh from my application? I understand that WM_PAINT should not be called from our own application.
Qn2. May I know what is the most efficient way of refreshing a device context? Currently, I am only updating a portion or pieces of the device context every timestep. What I am doing now is to "draw" the background first (so as to erase), then followed by going through what needs to be drawn onto the device context every timestep. I feel that there should be a better approach. The refresh needs to be pretty fast so that the user will not see any fickleness.
Qn3. I would like to write some sentences onto the device context. I am using "CDC::TextOut" in this case. May I know how then can I control the size and type of the font?
Due to company policy, I am not using the Doc/View approach in VC++ 6. I am manually coding in the various stuff like menus etc. Sorry if some of the questions is a bit naive as I am really new to MFC. Urgently needing help due to tight schedule.
Thank you very much in advance.
|
|
|
|
|
tanuki22 wrote:
May I know how can I make the display window refresh from my application?
Use CWnd::Invalidate() to schedule repainting of the window. Call CWnd::UpdateWindow() then if you want to repaint the window immediately.
tanuki22 wrote:
The refresh needs to be pretty fast so that the user will not see any fickleness.
Use double buffering - draw to the memory DC first and then switch the content from memory DC to display DC using BitBlt - see this[^].
tanuki22 wrote:
May I know how then can I control the size and type of the font?
Use CDC::SelectObject().
Pavel
Sonork 100.15206
|
|
|
|
|
hi everyone,
how do you manually highlight a node in a tree control? say i have a treectrl with 5 nodes.. if i want to have node 4 get highlighted everytime i start the program, how do i do it?
|
|
|
|
|
Use the TVM_SELECTITEM message to select an item.
--Mike--
"alyson hannigan is so cute it's crazy" -- Googlism
Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Hi folks
How do i add new folder button in browse for folder dialog box...need help????
Sansingh
|
|
|
|
|
|
I am working on an Application and would like to have a picture as the background. Is this possible using AfxRegisterWndClass()?
-- Steve
|
|
|
|
|
The background of what ? If the background of the program, then you need to handle WM_ERASEBKGND, the details are in the FAQ.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Hi.
I am a C++ programmer with experience with MFC and Winsock. I am working on project that utilize MFC, Winsock, and more advanced C++ like that found in Modern C++ Design. I have a question about writing commends.
I hate writing comments! Before you go off and post about responses, please consider my reasons. I understand the importance of comments from in terms of team project. In a team project where hundred and even thousands of programmers study and modify each other's code, comments are imperative. Comments are essential even in individual projects. Experienced programmers understand that we will one day read code we worked on six months ago. The bottomline is that comments are imperative to software implementation especially with C++ where some section of a code can be abstract and different to decipher.
Nonetheless, comments are tedious! For example, let say you spend an hour on an algorithm. Now, you have to spend another ten, twenty, even thirty minutes commenting the class or a collection of classes. In the end, you have less time solving other problems.
I want to know how do you programmers deal with commends in real-world team projects. Real-world projects vary from a simple simulation for NASA to an operating system. I know I am developing a bad habit that will hurt me in the end, but sometimes I get so caught up in solving problems that I ignore the comments. I remember all my code. Somethings I take a few minutes to see what goes on, but I always recommend it. Again, I understand the reason is because I am the person who wrote it.
Lastly, is there an art to writing good comments? How do you know where, when, and what to write such that the comment is elegant and takes up little time and effort because it becomes natural?
Thanks,
Kuphryn
|
|
|
|
|
There was a time not too long ago that I would have agreed that comments are tedious and at best a "necessary evil".
kuphryn wrote:
Nonetheless, comments are tedious! For example, let say you spend an hour on an algorithm. Now, you have to spend another ten, twenty, even thirty minutes commenting the class or a collection of classes. In the end, you have less time solving other problems.
One thing I have learned that helps me quite a bit is this. Anytime I have need to write a new class, start by commenting the class and then writing the code with inline comments. (By inline comments, I mean comments on important lines.)
kuphryn wrote:
get so caught up in solving problems that I ignore the comments
I might add that by not commenting you are only introducing future problems.
kuphryn wrote:
Lastly, is there an art to writing good comments? How do you know where, when, and what to write such that the comment is elegant and takes up little time and effort because it becomes natural?
For me it has taken a very long time (years) to get to the point where I comment first and then code. I have learned that this helps me in several ways not the least of which is it helps me to remain focused on the implementation I have chosen and not to try and gold-plate it or (wing it) as I go. The key to doing this, though is knowing in advance what I am going to write and not writing it until I have it figured out in my head or sometimes in a testbed.
Once I made the leap from the "code a solution" to "design a solution and then code it" it became clear that commenting had to come first.
Anyway, that's just my 2 cents.
|
|
|
|
|
Interesting...I don't know if you taught yourself how to program or if you were taught by someone. Teacher, friend whatever. From day one I always commented first then wrote code and refined both as I went on writting.
This would make for an interesting POLL question...
Chris...I think this should be a poll...
I always thought thats how everyone programmed.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
You bring up a very interesting point. I hate writing comments too, however, I do write them. But I have to admit that my comments do not follow any specific methodology. I have seen code where each class has comments. Each function has detailed comments before the function etc. However, I have also found that some of these comments are very bookish. For example:
/* Function Name: SumOfBlah
Author : Son of Blah
Parameters/Arguments: int one and int two
Returns : int
Purpose : Adds one and two and returns the resulting value
*/
Or something like that. Now if the function were merely adding then these comments are OK. But if the function were not sum and instead was some complex algorithm such as "Determines the meaning of life." Then I find that merely stating that like in the sample above does very little for me. I need to know, how you determined "the meaning of life." i.e., comments should not be written for the sake of writing them, but more so to explain just what the hell is happening in there.
What I tend to do is write comments as I write the code. Just a few words to explain what and why I am doing.
And I have to say I love it when other developers do the same. I have had to deal with code with no documentation and no comments that dealt with various forecasting algorithms. And this code not only had no comments but used variables like i1, i2 ...etc. Goes without saying.... I rewrote the damn code rather than trying to fix the bloody thing. On the other hand I have found code well commented in Russian...no problem.... called a russian friend who told me what it said...and bingo!!! code fixed in a few hours. Comments do help.....
So where do I stand on comments:
1. A brief description for each function/class...if necessary
2. Comments in the code as I write the code. (very critical)
3. Write code in a self documenting manner, i.e., use class names, variable names, function names that make sense. (very critical)
Where do my bosses stand on Comments:
Those bookish comment blocks above each function which may or may not provide any useful information, but they look pretty, cover the bosses rear end, and provide the impression of well documented work... I hope they don't read this...
And by the way.... my comments have come to my own rescue, 2 years and 4 projects later. Its not always that easy to recall, why you did something... hehehehehehe ;)
|
|
|
|
|
I can't say I've ever collaborated on any project other than sharing code with friends and sometimes re-working scripts and code snippets I get from sites like CP. However the importance of commenting IMO is crucial, it takes me twice as long to figure code when there are no comments...code context isn't enough...not as bad as trying to figure out assembly I agree, but still comments make a huge difference.
I personally comment about every second line of code, yes I have a 1:2 ratio on average according to some source code metrics tool I downloaded a while ago. The link is available somewhere under a CP article I sometimes catch myself writting to many comments...like
char* pChar = &Phantom[0];
When in reality only the most virgin newbie wouldn't understand what that code is doing just by analyzing context of the code.
As far as writting code and back tracking...? The one friend of mine who I occasionally team up with on web projects does that very same thing. Im the opposite...I code as I write...for starters I think it allows for better code seperation when using a color syntax supported IDE like VS. When I have written over 500 lines in one module and I catch a bug while testing and I know whats causing it it's easy for me to find the function and then the peice of code. To me commenting is an integral part of programming like color syntax hilighting. It's a tool and you might as well use it if it makes you time easier and not if it's a personal burden. However I guess as a team member it's essential...cuz if you had fellow coders like me, you'd hear nothing but whinning and complaining.
Just my opinion
Cheers!
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
Okay. Thanks.
I have decided to adopt an algorithm-based approach to commenting. I will comment every function with one line descripting the function. Otherwise, I will commend at the beginning of every algorithm, not lines of code. For example, "a = 5" is not important. It is the algorithm that is important, i.e. Why a = 5? I have been using this approach for the last couple of months.
Kuphryn
|
|
|
|
|
I can sum it up with this statment: Part of your job as a professional programmer is to write code that others are able to read and maintain.
If you think "oh I'll go back to comment it later" you're fooling yourself. You won't have time later to go comment it, you'll be working on bugfixes or features for the next revision.
kuphryn wrote:
In the end, you have less time solving other problems.
Commenting your algorithms so the other team members can read the code is part of the algorithm-writing process. So don't think of it as "1 hour to write the code, 20 minutes for the bloody comments", think of it as "1 hour 20 min to finish the entire task."
Skipping 20 minutes up front to write good documentation will most certainly cost the team more than 20 minutes later when someone else has to fix a bug in the code, but first they have to stare at it and step through it to understand what it's supposed to do. Or worse, call you over so you can explain it, which will cost two people time.
--Mike--
"alyson hannigan is so cute it's crazy" -- Googlism
Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
My simple approach to comments is,
Explain why I did something not what I did.
It's pointless trying to explain what the code is doing as that should be obvious from the code. However you should always say why you did something. This helps you when you go back to the code and wonder why the code is doing what it does.
I also document public class members, so that if somebody reuses the class then they know what the interface does and what parameters are needed. Anything private doesn't usually get a function header. I like people take a black box approach, documenting those functions that are specified in the design document but not really caring about the internal implementation.
Michael
Life’s not a song.
Life isn’t bliss.
Life is just this.
It’s living. -- Buffy the Vampire Slayer: Once more, with feeling
|
|
|
|
|