|
Qualvis wrote:
void CDialogTestApp::OnTest1()
{
CDialog1 d1;
d1.AddListBox();
d1.DoModal();
}
I believe that would be your problem. You are instantiating the dialog but then trying to add things to a control that doesn't exist yet.
Artificial intelligence is no match for natural
stupidity.
|
|
|
|
|
Hello
I have in my app. print button. My app. must print in "landscape" mode
only, because there are some long tables to print.
Could someone tell me how to set up this option (page orientation) programatically? Or some tips. Anything will do
thank you
Chris
|
|
|
|
|
If its an MFC app, it will have an DEVMODE object which is a member of your CWinApp class. Call these functions and pass throught the required page orientation
bool SetPrintOrientation(HANDLE &hDevMode, int mode) const
{
if (hDevMode == INVALID_HANDLE_VALUE)
return false ;
switch (mode)
{
case DMORIENT_PORTRAIT :
{
LPDEVMODE pDevMode = (LPDEVMODE)::GlobalLock(hDevMode) ;
pDevMode->dmOrientation = DMORIENT_PORTRAIT ;
::GlobalUnlock(hDevMode) ;
}
break ;
case DMORIENT_LANDSCAPE :
{
LPDEVMODE pDevMode = (LPDEVMODE)::GlobalLock(hDevMode) ;
pDevMode->dmOrientation = DMORIENT_LANDSCAPE ;
::GlobalUnlock(hDevMode) ;
}
break ;
default :
ASSERT(FALSE) ;
return false ;
}
return true ;
}
int GetPrintOrientation(HANDLE &hDevMode)
{
int val = DMORIENT_PORTRAIT ;
if (hDevMode != INVALID_HANDLE_VALUE && hDevMode != NULL)
{
LPDEVMODE pDevMode = (LPDEVMODE)::GlobalLock(hDevMode) ;
val = pDevMode->dmOrientation ;
::GlobalUnlock(hDevMode) ;
}
return val ;
}
Roger Allen - Sonork 100.10016
Strong Sad:
Clever I am? Next to no one.
Undiscovered and soggy.
Look up. Look down. They're around.
Probably laughing. Still, bright, watery.
Listed among the top. Ten.
Nine. Late night. Early morn.
Early mourn. Now I sleep.
|
|
|
|
|
thanks. it looks good. And Yes it Is MFC application but there is a problem.
i tried it on:
protected:
HGLOBAL m_hDevMode;
member of CWinApp
and in pInfo->m_pPD->m_pd.hDevMode in CPrintInfo.
And the problem is that this variables are always 0 and i have an exception
in SetPrintOrientation(..) function
Can you give me some more tips?
thanks in advance
-- added later ---
ok i found solution
i must call GetPrinterDeviceDefaults(..) first
|
|
|
|
|
OK, I think I might know what the answer to this is going to be, put I'll post my problem anyway, as you never know, there may be a simpler solution...
I have a service app that listems for incoming socket connections using good old Berkeley style socket code - I have code that creates the socket to listen on and then a thread that uses "select" to wait for the connections, spawning a new thread per-connection to handle the data, e.g.:
<br />
for ( ; ; )<br />
{<br />
...<br />
fd_set read;<br />
FD_ZERO(&read);<br />
FD_SET(m_hSocket, &read);<br />
int nResult = ::select(-1, &read, NULL, NULL, &tv);<br />
if (nResult == 1)<br />
{<br />
SOCKET s = ::accept(read.fd_array[i], NULL, NULL);<br />
AfxBeginThread(...);<br />
}<br />
}<br />
The problem is that if I hammer the app using a test program that creates lots of simultaneous connections to the server (using a separate thread for each all started at once), before long some of these connections will fail with WSAECONNREFUSED. This seems to be because creating the thread to handle the accepted socket in the code above is expensive in terms of CPU and the incoming connections piling up whilst I am doing this are causing the backlog (5 sockets?) to be exceeded.
I *think* the answer will be to use IO completion ports but this is going to be a big job. The threads I create to process each socket are short-lived, and I know IOCP can ensure fewer are needed but will it also help with this backlog problem or is there another more generic way to handle this? At some point in the distant future I may want to port the code to Linux (yikes!) so I wanted to avoif anything MS specific.
Comments?
The Rob Blog
|
|
|
|
|
Why spawn a thread *AFTER* a connection attempt? Prepare a pool of worker threads all waiting on a single semaphore would be the easiest fix I believe(least effort on your part)... after all, triggering a single semaphore event should cost a fraction of AfxBeginThread(...)
try Recycle all threads instead of respawn... and dont harm any animals.
-Dan
|
|
|
|
|
Cheers for the tip - I will investigate further...
The Rob Blog
|
|
|
|
|
First, you should be able to set the backlog value to much higher than 5. This will ease most problems immediatley. You've not shown the listen section so I will assume you've used a large value.
Second, you could split the code into two threads:
Thread 1 sits waiting for new connections, accepts them, and puts the socket handle into a queue. Thats all it does - it then immediatley resumes accepting other connections. Thread 2 sits on the queue, and creates a thread for each socket.This detachs the (slow) thread creation process from the (fast) accept process, and you should be able to pretty much reach the maximum accept rate you can.
|
|
|
|
|
Using winsock2, the maximum backlog value is apparently now 0x7fffffff (SOMAXCONN) but I tried this without any success. I will experiment with new values.
I also tried two threads as you suggested, using a shared array of SOCKETs - the accept thread adds the accepted socket to the list and then signals the second thread via a semaphore, but still I had problems. I used a critical section to protect the shared socket array, but perhaps I need to revisit this.
Thanks for the advice - switching to IOCP and AcceptEx is a major task that itself looks fraught with problems if my search of Google Groups is anything to go by!
The Rob Blog
|
|
|
|
|
I have a framework that does IOCP/AcceptEx/System Thread Pool stuff for Windows based network servers. It's (n)ill documented at present but you can take a look here.
The intent is to be able to support multiple listening sockets on multiple adaptors using multiple network protocols (primarily IPv4 and IPv6 I suppose) and exploit the Windows good stuff for networking.
The idea was to impose a minimum of dependency between the server framework and the rest of the application, you have to provide a 'per connection' class that must implement a minimal interface, but after that it's up to you. No inheritance required, namespaces are used so that my idea of a CRITICAL_SECTION wrapper doesn't collide with yours, etc etc.
I believe it would be possible to construct a framework for Unix type systems that would be compatible with such a 'per connection' class and be reasonably efficient in that environment. Time will tell.
Paul
|
|
|
|
|
I want to do the following in a seperate app:
WindowFromPoint() using mouse location, and then read the DC of that window into a BMP of some sort, the only way I can see it to create a transparent window on top of the window I have just "spied".
At the end of the day, I want to read the location of a rectangle drawn into the DC of the "spied" upon window. I then want to create a edit control in the same size as the rectangle underneath it. The last bit is easy, it's how to even try to read the DC/bitmap of another window I have no clue how to do.
Any clues.;)
Conrad B
Always do badly to start off, that way when you get the hang of it suddenly, everyone is surprised.
|
|
|
|
|
Hi, I want to create a GUI for a C program and I don't know where to start! I've never used Visual C++ before,can anybody give me any help???
Cheers.
|
|
|
|
|
in Visual C++, use the Win32 Application wizard (File->New Project or such) and let it create a simple Win32 program for you... you can see how the fundamental ideas in win32 apps work (window messages, the message loop, creating windows, registering window classes)
r -€
|
|
|
|
|
I have tried to run simple programs using the Win32 App wizard a few times but I keep getting errors when I build it. I have even tried to build a Hello World program but it wouldnt work for me. The first time I built it, it gave me the C1010 error about precompiled headers and then when I followed the instructions, from the microsoft support website, to fix this problem I got the LNK2005 and LNK1169 errors. By letting it create a simple Win32 message, what exactly do you mean? Sorry, but I'm really new to this!!
Thanks for the prompt reply though.
|
|
|
|
|
C1010 error about precompiled headers
#include "StdAfx.h"
or
not use precompiled headers
To be or not to be!
|
|
|
|
|
Ok, I've got rid of that error, thanks a million! Now, how do I link a .C file to the GUI...again I'm new to this so I need a lot of help!
Thanks again
|
|
|
|
|
By letting AppWizard create the application for you, you will have a working (albeit not very useful) application. No compiler or linker errors (until you start adding more code to it).
Start with a dialog-based application. They are good entry-level projects.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
DavidCrow wrote:
No compiler or linker errors (until you start adding more code to it).
you pretty much summed up what development is.
MSN Messenger.
prakashnadar@msn.com
"If history isn't good, just burn it." - Sidhuism.
|
|
|
|
|
Also, do you know of any books that have step-by-step approaches to building guis? I'm really stuck...it's for my final year project.
Cheers.;)
|
|
|
|
|
|
Im a novice at C++ and Im working on VisualC++.NET on w2k, what am I doing wrong here:
Code:
BSTR McName = SysAllocString(TEXT("DaveMachine"));
Error:
error C2664: 'SysAllocString' : cannot convert parameter 1 from 'const char [11]' to 'const OLECHAR *'
Any help is really appreciated.
We have a mathematician, a different kind of mathematician, and a statistician!
|
|
|
|
|
SysAllocString takes a Unicode string as it's parameter. If you don't have _UNICODE defined - TEXT() evalulates to nothing.
Always pass a Unicode string to SysAllocString like this
BSTR McName = SysAllocString(L"DaveMachine");
|
|
|
|
|
Excellent, that got rid of a few errors, just one to go.
This is the code:
wsprintf(sz, TEXT("Load Percentage: %s\n"), V_BSTR(&vVal));
wprintf(sz);
and the error is pretty similar to the last one:
error C2664: 'wprintf' : cannot convert parameter 1 from 'TCHAR [260]' to 'const wchar_t *'
Cheers
We have a mathematician, a different kind of mathematician, and a statistician!
|
|
|
|
|
Same thing - if Unicode is not defined TEXT = nothing, if it is TEXT = L.
Thats fine, but your using the wide (UNICODE) version of wsprintf so its expecting a Unicode string. Either change TEXT to L or use char neutral APIs.
Basically, never use TEXT with the explicilty wide (say wsprintf) or explictly narrow (say sprintf) versions of functions as you know what type of char to pass ("" in narrow, or L"" in wide).
Use TEXT when you want to be char neutrual - using the <TCHAR> API's - _stprintf.
With UNICODE defined _stprintf = wsprintf and TEXT = L"".
Without UNICODE define _stprintf = sprintf and TEXT = "".
|
|
|
|
|