|
Since controls are just windows you can use them as a child window on any window.
An easy way is to add a CComboBox member to your window class:
CComboBox m_MyCombobox;
Add a WM_CREATE handler to the window class. In the handler call Create() for the combo box.
int CMyWindow::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
m_MyCombobox.Create(CBS_DROPDOWN, CRect(10,10,100,15), this, IDC_MYCOMBOBOX);
...possibly populate the combo box here using AddString() etc ...
return 0;
}
This example places a 100 wide by 15 high CBS_DROPDOWN style combo box at 10,10 in the window.
You could handle WM_SIZE in the window and move the combo box in response to the user resizing the
window.
Hope this helps get you started!
Mark
|
|
|
|
|
Hey Mark,
Thanks for that mate. I implemented it and I had no errors, however the Combo box still isn't showing up. I also created a IDC_MYCOMBOX resource with the type set to child. Any ideas?
For what its worth I am dealing with a view that is derived from CView as opposed to CFormView. Is that part of my problem?
Thanks again to everyone for all their help.
Danny
|
|
|
|
|
Danny Nowlan wrote: I implemented it and I had no errors, however the Combo box still isn't showing up.
Sorry The limited example code didn't have enough style flags.
try
m_MyCombobox.Create(CBS_DROPDOWN|WS_VISIBLE|WS_CHILD, CRect(10,10,100,15), this, IDC_MYCOMBOBOX);
Calling MyCombobox.ShowWindow(SW_SHOW) would make it show as well. Useful if you want to
create it hidden and show it later I suppose.
Mark
|
|
|
|
|
In my application I connect to a site and request a search. In the source code of the webpage the server sends back, there's a link I need to follow. I was thinking something like this would work:
connect
send: "GET /?name=example HTTP/1.1\r\nHost: example.com\r\nConnection: Keep-Alive\r\n\r\n"
retrieve the page returned and parse it
send: "GET /?id={what I parsed out} HTTP/1.1\r\nHost:example.com\r\nConnection: Close\r\n\r\n"
I retrieve the page like this:
void ReceiveDoneCallback() {
if (bytes read > 0) { read more }
else { parse message; generate second request; }
}
Now this works but not the way I want it to. It takes about 20 seconds before the server closes the connection. That is, when the Connection: Keep-Alive header is sent along. I think it's because I still call another BeginReceive while there's bytes read. I workaround could be to compare bytesRead to buffer->Length, but what if the output page is a multiple of my output buffer size?
Can someone tell me how this is done?
Thanks in advance,
Frank
|
|
|
|
|
Are you using WinInet for this? If so, call InternetQueryDataAvailable() to tell how many bytes of the response are waiting for you to read.
|
|
|
|
|
I asked around a bit and I was told that I need to read out the Content-Length header which the server sends back. I was very proud of myself when I got that done, but then I found out that's the length of the stuff that comes after the headers, and Content-Length isn't the latest header sent
Anyway, I also managed to fix that up. Here's the code I used.. if anyone ever uses the search button and finds this.
void ReceiveDone(IAsyncResult^ ar) {
Socket^ s = safe_cast<Socket^>(ar->AsyncState);
try {
int bytesRead = s->EndReceive(ar);
String^ read = Encoding::ASCII->GetString(buffer, 0, bytesRead);
sb->Append(read);
TimesRead++;
if (ReadingHeaders == true) {
Int32 index = sb->ToString()->IndexOf("\r\n\r\n");
if ((index != -1) && (ContentLength != 0)) {
TimesRead = 0;
sb->Remove(0, index + 4);
ReadingHeaders = false;
}
else if (ContentLength == 0) {
array<String^>^ seperators = gcnew array<String^>{"\r\n", ": "};
array<String^>^ headers = sb->ToString()->Split(seperators,StringSplitOptions::None);
Int32 index = sb->ToString()->IndexOf("Content-Length:");
if ((index != -1) && (index + 10 < sb->Length)) {
for (int i = 1; i < headers->Length; i++) {
if ((headers[i] == "Content-Length") && (headers[i+1]->ToString() != "")) {
Int32::TryParse(headers[i+1]->ToString(), ContentLength);
ReadsRequired = (ContentLength / buffer->Length);
if (ContentLength % buffer->Length > 0)
ReadsRequired++;
}
}
}
}
}
if ((ReadingHeaders == true) || (TimesRead < ReadsRequired))
sock->BeginReceive(buffer, 0, buffer->Length,
SocketFlags::None, gcnew AsyncCallback(this, &StatsSock::ReceiveDone), sock);
else
ParseDelegate->Invoke(sb->ToString(), this);
}
catch (Exception^ e) { MessageBox::Show(e->ToString()); }
}
|
|
|
|
|
I tryed SetFocus() but it didn't work.
Moreno
|
|
|
|
|
Use GotoDlgCtrl() instead.
example:
GotoDlgCtrl(GetDlgItem(IDC_MYCONTROL));
Mark
|
|
|
|
|
Hello everyone,
I am looking for an efficient way to implement matrix multiplication in C/C++. Are there any existing good ways?
The matrix is stored in an one-dimentional array.
thanks in advance,
George
|
|
|
|
|
Hello,
I'm trying to add the following lib: [url]http://id3lib.sourceforge.net/[/url]
to my VS2003 project, I don't understand the instructions:
[code]
B)***Your project wants to link id3lib static, and has mfc linked dynamic or has no MFC:
1) Rename config.h.win32 to config.h
2) include libprj/id3lib.dsp and zlib/prj/zlib.dsp to your workspace
3) make your project dependend on id3lib, and make id3lib dependend on zlib
4) Add /D ID3LIB_LINKOPTION=1 to your project options (settings, C/C++ tab)
5) Add the following include dirs to your program:
/I <path_to_id3lib>\\include /I <path_to_id3lib>\\include\\id3
6) (add your code which uses id3lib)
7) Try to compile, and see if you need any of the following:
(debug) /nodefaultlib:"msvcprtd" or(release) /nodefaultlib:"msvcprt"
(debug) /nodefaultlib:"MSVCRTD" or(release) /nodefaultlib:"MSVCRT"
(debug) /nodefaultlib:"libcmtd" or(release) /nodefaultlib:"libcmt"
different programs may require different 'nodefaultlib' 's, or none at all, these worked for me.
If none you try work, revert to C)
[/code]
Please help, without this lib I can't go on with my project.
Thank you.
|
|
|
|
|
Which bit do you not understand ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
2 - 5
I'm not sure what do they want me to do.
I'm sorry if this question is really stupid, I'm just really new to VS, I'm not sure where to put all of this.
|
|
|
|
|
They are VC6 instructions. Which means the code may not even compile in VC2003. I'd start by loading the project in VC2003 and see if it compiles. Adding projects to the solution is set 2.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I tried to add this to a project, but I'm not sure where am I suppose to add all this in VS2003, as I said, I've never done linking before in VS.
|
|
|
|
|
Hi,
how should I make my MFC single dialog box application so that, it could change main dialog box?
My application allows one instance (I used CSingleInstanceApp), so I want to change dialox box after user tryied to run it more time (with different parameters).
It is posible to assing CWinApp::m_pMainWnd another dialog box during aplication runs ?
rudozkv
-- modified at 5:17 Sunday 15th October, 2006
|
|
|
|
|
When you start the second instance, and you get acknowledged that another instance is running you can find that app. and send it a registered message.
Then you'll be able to handle that message in the first application.
Hope this helps.
|
|
|
|
|
Hi,
I need to sort the items in a listbox in assending/descending order. To sort in ascending order I copy the list item into a CStringList object then destroy the listbox and recreate it with style LBS_SORT . Then I add the items back again.
But how do I sort it in the descending order?
Thanks.
Fortitudine Vincimus!
|
|
|
|
|
The visual style LBS_SORT is not intended to sort anything automatically, it is only in order to allow you to click on the header of the column and receive a notification message in order to be able to handle that notification.
In other words, this is not handled automatically so you'll need to get this notification message and then sort it programatically.
Hope this helps.
|
|
|
|
|
Hi all:
Thanks for the suggestions in my original post... I think I should have worded my question differently though.
Thre original question:
"I am working on an MFC application (Visual Studio/C++) that has to grab a screen shot from a frame grabber and send it to the default printer with landscape orientation. This has to be done with no operator intervention other than clicking on a "Print" button in the main dialog - no preview or print dialog. I'm able to grab the frame, but I'm having no success with the printing."
What I really have is not a bitmap in the MFC sense, but a pointer to a big bunch of pixels. I can not seem to figure out how to get those pixels in a form that I can print - what comes out of the printer is just a black rectangle.
Again, any help would be appreciated.
Bob.
|
|
|
|
|
Did you use CreateDIBitmap[^] to get a HBITMAP? How exactly are you passing your bitmap to the printer?
|
|
|
|
|
I think you aksed this question if your problem is with bitmaps see here[^] maybe its some helpful for you
|
|
|
|
|
Hi, I've been programming for years but I learned by doing rather than by anyone teaching me, and as such I have a few gaps in my knowledge.
One is memory allocation: My question is this, if I use a locally defined buffer rather than a global buffer, does it take more overhead in terms of processor power? Also, how exactly is the memory allocated (of course the global variable is allocated when the program initiates, but what about the locally defined one? Is a new instance re-allocated each time the function is called, which would certainly cost more crunch time..?). What I'm mostly interested in is: which one is more efficient, and by how much/why?
So here's an example of what I mean.
Globally defined:
char buf[128];
void do_something()
{
buf[0] = 0;
}
As opposed to locally defined:
void do_something()
{
char buf[128];
buf[0] = 0;
}
Thanks so much!
KR
|
|
|
|
|
This is from memory so I hope I'm close...
KellyR wrote: how exactly is the memory allocated
Local one is on the stack.
KellyR wrote: Is a new instance re-allocated each time the function is called
Yes but it only takes one instruction - an adjustment to the stack pointer.
Build code with both, run it in the debugger, and check the disassembly window.
You'll see the difference in the way the array is indexed.
My guess is that in instruction cycles it's real close.
Mark
|
|
|
|
|
When the array is a local variable in the function, a new array is allocated on every call. However, all that means is the stack pointer is decremented by a different amount (an extra 128 bytes).
As for which is more efficient, the dominant effect will probably be that the local variable array will already be in the L2 cache, whereas the global array may not be on the first access.
However, unless this is in a very very tight loop, I'd be shocked if you noticed any difference in execution time. Of course, the only way to be sure it to run both versions of the code and measure.
|
|
|
|
|
Michael Dunn wrote: As for which is more efficient, the dominant effect will probably be that the local variable array will already be in the L2 cache
Cool
|
|
|
|