|
To Hello,
How do you create and locate an array of common controls(especially pushbuttons) dynamically?
Thanks.
S1189216G
|
|
|
|
|
All Windows controls can be considered normal Windows, with special properties. Following this logic, creating pushbuttons is just like creating new windows.
For MFC, use
:CButton* pNewButton = new CButton();
pNewButton->Create("My Caption", WS_CHILD | WS_VISIBLE, CRect(0,0,30,30), this, WM_USER + 1); This code fragment would create a new pushbutton as a child of the CWnd/CDialog class it is being called from, such as when CDialog::OnInitDialog is executed.
For Win32, the procedure is similar, but you'll just use HWND (window handle) and CreateWindow . To create a button, specify "BUTTON" as the class name in CreateWindow . Otherwise the parameters are similar to the MFC version.
See MSDN for more information.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
To Antti,
Thanks for the reply.
I need an array(x and y) OR a 2-D of CButtons.
CArray and Clist, which is better?
How do you create the CButtons?
S1189216G
|
|
|
|
|
The selection between CArray and CList depend solely on how many buttons you intend to have. If you have around 10-20 buttons, then an ordinary array of pointers will do.
Here is a code fragment that initializes and creates an array of 4x4 buttons.
CButton* ptrArray[4][4];<DIV>
for( int n = 0; n < 4; n++ )
{
for( int m = 0; m < 4; m++ )
{
ptrArray[n][m] = NULL;<DIV>
ptrArray[n][m] = new CButton();<DIV>
ptrArray[n][m]->Create("Push me !", WS_CHILD | WS_VISIBLE,
CRect(m * 25, n * 15, (m*25) + 20, (n*15) + 10),
this, WM_USER + 100 + n + m );
}
} This code fragment would create an array of 4x4 buttons, that each are 20*10 in size, hold a caption called "Push me !" and were ordered so that the top-left button was in 0,0, and the rest of them would be 25 pixels right from the previous and the next line would be 15 pixels to down from above.
And I won't take responsibility if that code fragment crashes your computer ! It's for reference/quick example only. Test it, debug it, see if it works. Then implement it in the way you choose. Remember to destroy the buttons (CButton::DestroyWindow ) and delete the pointers before you quit the application !
If you need more performance, you can utilize CArray or CList. For more information on how to use them, you should see MSDN, as it has a HUGE amount of information right at your fingertips. Go http://msdn.microsoft.com to read it.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hello all,
I pretty new to Visual C++ and have a question that I am not really sure how to ask, so please bare with me.
I have a dialog based application and a pop3 class that I got here at Code Project.
Anyway, what I need to do is have the functions in the pop3 class update a text box in the dialog as it is retrieving the mail.
I have looked at callbacks but they all seem to work on timers, and what I need is the pop3 functions to just automagically update the text box without any involvement of the dialog app.
Is this possible, and if so, how?
Thanks,
Murrah Boswell
|
|
|
|
|
when receiving a mail, send a message and let your Dialog-class catch and handle it?
Good luck.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
Hello,
I am dumber than I know sometimes! I wrote the code in the pop3 system that handles multiple downloads, so I just rewrote my code (pop3 and dialog app) to put the call to the GetMessage function in a loop in my dialog app, and then had access to the messages from pop3 system.
Can't see the forest sometimes...
Thanks for your response though, I really couldn't make it without all the folks at Code Project.
Murrah Boswell
|
|
|
|
|
otrcomm wrote:
I really couldn't make it without all the folks at Code Project.
I agree: I need some help now and then myself. The world would be a worse place without the codeproject and all the good and smart people using it.
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
I'm writing an application that loads a DLL midway through execution (it's a wizard). When I debug my program and step through the lines of code which load the DLL, I get a null pointer back and my error handler catches it just fine. But that's not my issue--the issue is, when I run the exact SAME executable file but I don't do it in debug mode, the program experiences a runtime error, presumably from trying to get functions from an invalid HINSTANCE pointer with GetProcAddress, which I do right afterwards. How is it possible for the same code to experience different behavior? Has anyone else run into this? I also see runtime differences between the debug and release versions of my code. Any ideas?
Thanks alot,
augy
|
|
|
|
|
Microsoft would call this "behaviour by design".
The debug versions are much more error-tolerant than the release versions. The runtime error is caused by the invalid HINSTANCE variable (if LoadLibrary returns NULL). The debug version doesn't cause a runtime error, because, during the debug build phase, there is a compiler predefinition called _DEBUG. This predef causes the compiler to generate much heavier and more error-tolerant code, made especially for debug purposes. On the release versions, a _NDEBUG is specified.
The idea is that you create code, then do a debug build, then run/step through the code to see if it is working smoothly. Then you do a release build. It is supposed to work this way. Trying to alter this behaviour is the same thing as trying to reinvent the wheel.
The debug mode of Visual Studio, when ran with a debug build, is capable of cathing and handling numerous types of error that would quickly crash a release version. It is designed to help you predict errors and fix them beforehand when building your applications.
The reason why your error catcher doesn't handle "the NULL pointer" error in a release build is probably because you either have forgotten to use a try - catch block or then you are trying to check the error handler after the GetProcAddress is called. When HINSTANCE parameter is NULL, GetProcAddress will cause a runtime error. Check the HINSTANCE parameter instantly after you call LoadLibrary .
For more detailed error analysis, you should paste the library loading code here.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Interesting. I figured as much, but I didn't know that the debug version would change runtime behavior THAT much.
Anyways, I do check the HINSTANCE immediately afterwards for a NULL value, before any GetProcAddress() calls, hence my utter confoundment. After running it a few times, the problem has gone away (but without ANY change in the DLL loading code), and my simple check on the HINSTANCE ptr seems to catch it. Why or how this changed, I still haven't got a clue; I was using the debug version.
|
|
|
|
|
the_augy wrote:
How is it possible for the same code to experience different behavior? Has anyone else run into this?
All the time
I'm not sure, but I think one reason could be that a debug mode is much slower then the release.
There is however nothing you can do about it. Just try to do it in a different manner.
(PS: you can even get different errors when your breakpoint is set or not)
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|
|
I don't know the meaning of the following sentence:
the "WinMain" function is the begining of the Windows application ,it create the windows which receive the message
and enter the message circulation.
Does this function create the main window of the application?
|
|
|
|
|
WinMain() is the function that Windows calls when it starts your program. Typically, this is where you create the main window and implement a message loop so you can process messages.
Ryan "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"
|
|
|
|
|
sunmozhou wrote:
the "WinMain" function is the begining of the Windows application ,it create the windows which receive the message
and enter the message circulation.
Does this function create the main window of the application?
Yeah if use CreateWindow() function to craete a window.
ShowWindow() to Make the Window Visible.
and GetMessage() and DispatchMessage() to handle messages.
-----------------------------
"I Think It will Work"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
How can I tell if a string is a file or a directory?
Can I do it without searching the string myself looking for a period?
Please no MFC!
wWw.KruncherInc.cOm - My cool programs
|
|
|
|
|
One solution is GetFileAttributes().
Kuphryn
|
|
|
|
|
|
Use the CRT _stat function, see in MSDN, notice the
_stat::st_mode:
Bit mask for file-mode information. The _S_IFDIR bit is set if path specifies a directory; the _S_IFREG bit is set if path specifies an ordinary file or a device. User read/write bits are set according to the file's permission mode; user execute bits are set according to the filename extension.
|
|
|
|
|
Guys
I would really appreciate if somebody gives me any ideas for the following task:
I need to have a control on a dialog to insert text there that would be able to have an image at the beginning of every message and also would be able to associate a data with every message. Also, if a message is too long to fit the entire text within the control's borders, the text must be wrapped. I mean broken into lines.
ListBox came to my mind first. You can insert images and accociate a data with each item. But ListBox is not a multiline control. I found some projects on Codeguru and Codeproject for multiline listbox controls but they don't work as they are supposed to be.
I need an urgent advice.
Thanks a lot!
|
|
|
|
|
You could try an owner-draw list box or list view control...
Ryan "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 need a bidirectional map, and usign two maps seems a bit overkill.
Are there any other ways to do that? (more curious from a design point, what else could be done, but if someone knows a good refernece implementetion.. )
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist || Agile Programming | doxygen
|
|
|
|
|
There is one in the STL section Bimap[^].
Come on Peter, I thought you would have found it yourself
If you vote me down, my score will only get lower
|
|
|
|
|
|
Why oh why does "[a-z]= " match "xy= "
(I expected it to match exactly one letter)
we are here to help each other get through this thing, whatever it is Vonnegut jr.
sighist || Agile Programming | doxygen
|
|
|
|