|
Is the About dialog's static set to type BITMAP?
|
|
|
|
|
The settings are:
ID: IDC_STATIC
Type: Bitmap
Image: IDB_BITMAP2
There is a valid bitmap resource called IDB_BITMAP2. The thing I can't understand is why it works in the main dialog, but no bitmaps appear in the About dialog??
|
|
|
|
|
Hi,
I'm working on an application with many forms, i designed a layout for all the forms, but i wanted to build a class that had OnDraw(CDC* pDC) so i didn't have to override it from all my CFormView derived classes.
I created a CLayout Class with OnDraw(CDC* pDC) function and now i would like to call it from other classes so i could draw and paint the forms.
But, how can i get the pDC of this form?
And i also need the hWnd pointer in my CLayout::OnDraw Function
In my derived call i wrote:
HWND* hWnd=NULL;
hWnd=(HWND*)this->operator HWND();
CDC pDC=::GetDC(*hWnd);
CLayout ly(hWnd);
ly.OnDraw(&pDC);
...but GetDC function returns a HDC no CDC...
This is my OnDraw Function...
void CLayout::OnDraw(CDC* pDC)
{
//cria os objectos
CBrush brush(RGB_FUNDO);
CBrush* pTempBrush = NULL;
CBrush OrigBrush;
CString sFormName="New Machines";
CFont hFont;
CRect rc;
try
{
//cria a fonte para as letras de identificação do form
VERIFY(hFont.CreateFont(40, 15, 0, 0, FW_NORMAL,FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial Bold"));
//define a area total do ecran
GetClientRect(*hWnd,&rc);
ScreenToClient(*hWnd,&rc);
//seleciona o brush (cor) a usar
pTempBrush = (CBrush*)pDC->SelectObject(brush);
//guarda o brush original
OrigBrush.FromHandle((HBRUSH)pTempBrush);
//desenha o rectangulo a pintar com aquele brush
pDC->Rectangle(0, 0, rc.Width() , rc.Height());
//defino a cor do texto
pDC->SetTextColor(RGB_WHITE);
//elimino o bkgrn do texto
pDC->SetBkMode(TRANSPARENT);
//associa-lhe a fonte criada
pDC->SelectObject(hFont);
pDC->DrawText(sFormName, -1, CRect(15, 0, rc.Width(),80), DT_LEFT|DT_SINGLELINE|DT_VCENTER);
}
catch(CResourceException* e)
{
e->ReportError();
e->Delete();
}
pDC->SelectObject(&OrigBrush);
}
What am i doing wrong
Thank you for your time
rui
|
|
|
|
|
You could try
<br />
CClientDC dc( this );<br />
CLayout ly( *this );<br />
ly.OnDraw( &dc );<br />
but if this code gets called in OnPaint then you should use CPaintDC instead.
You also might get away with supplying the hWnd of the form because CDC has a member function GetWindow( ) which returns the window associated with the device context (if there is a window BTW - returns NULL during printing for instance).
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Thank you dabs,
I changed my code, now in my CFormView derived class OnInitialUpdate() i did like:
ClientDC dc( this );
CWnd* cWnd=dc.GetWindow();
CLayout ly(cWnd );
ly.OnDraw( &dc );
then, i CLayout
CRect rc;
cWnd->GetClientRect(&rc);
GetClientRect((HWND)cWnd, &rc);
cWnd->ScreenToClient(&rc);
but rc is like : tagRECT: {top=32730 bottom=32730 left=32768 right=32768}
well, i forced other values, and it didn't draw the same, but in debug mode, i follow the pointer and it seems ok.
What can i be doing wrong?
Thanks once more for your time
|
|
|
|
|
Looks like you are using a CWnd* as a HWND. I recommend using Hungarian notation to be able to spot such problems - your variable would be called pWnd in that case. Secondly, you don't need that ScreenToClient call since GetClientRect uses client coordinates already.
So change this code:
<br />
CRect rc; <br />
cWnd->GetClientRect(&rc);<br />
GetClientRect((HWND)cWnd, &rc);<br />
cWnd->ScreenToClient(&rc);<br />
to this:
<br />
CRect rc; <br />
cWnd->GetClientRect(&rc);<br />
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Thank you dabs for the recommendation,
I changed my code, it runs, in debug mode it passes without any problem by all code lines.
Maybe the way i'm passing the pWnd pointer is incorrect, i'm doing like:
CLayout::CLayout(CWnd* pWnd1)
{
pWnd=pWnd1;
}
pWnd is a member variable of CLayout
My class is :
class CLayout
{
public:
CLayout(CWnd* pWnd1=NULL);
~CLayout(void);
CWnd* pWnd;
public:
virtual void OnDraw(CDC* pDC);
};
Should it be derived from CFormView also?
I don't understand, it just don't draw, well, now rc is 0 for the four items...so it couldn't draw
I'm suspicious about the pWnd that i pass from one class to another.
What do you think?
Thank you for your patience
|
|
|
|
|
The CWnd declaration and initialization is correct. And no, this class should not derive from CFormView unless you want to create another form
What happens in your Form's OnDraw and/or OnPaint functions?
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Well, i'm just Using OnDraw()
The function is :
void CLayout::OnDraw(CDC* pDC)
{
//cria os objectos
CBrush brush(RGB_FUNDO);
CBrush* pTempBrush = NULL;
CBrush OrigBrush;
CString sFormName="New Machines";
CFont hFont;
CRect rc;
try
{
//cria a fonte para as letras de identificação do form
VERIFY(hFont.CreateFont(40, 15, 0, 0, FW_NORMAL,FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial Bold"));
//define a area total do ecran
pWnd->GetClientRect(&rc);
//seleciona o brush (cor) a usar
pTempBrush = (CBrush*)pDC->SelectObject(brush);
//guarda o brush original
OrigBrush.FromHandle((HBRUSH)pTempBrush);
//desenha o rectangulo a pintar com aquele brush
pDC->Rectangle(0, 0, rc.Width() , rc.Height());
//defino a cor do texto
pDC->SetTextColor(RGB_WHITE);
//elimino o bkgrn do texto
pDC->SetBkMode(TRANSPARENT);
//associa-lhe a fonte criada
pDC->SelectObject(hFont);
pDC->DrawText(sFormName, -1, CRect(15, 0, rc.Width(),80), DT_LEFT|DT_SINGLELINE|DT_VCENTER);
}
catch(CResourceException* e)
{
e->ReportError();
e->Delete();
}
pDC->SelectObject(&OrigBrush);
}
I used this function in a OnDraw override from CFormView in my other class and i never thought it would be so dificult to make a class just for the propose...
I would appreciate very much if you could still hepl me with this, thanks a lot
|
|
|
|
|
Aside from the fact that you are casting a CBrush* to HBRUSH (which won't work) and that you forget to deselect your font out of the device context then there's nothing inherently wrong with this code. But why don't you simply use the resource editor in Visual C++ to arrange the form in a way you want? There are controls available that allow you to change the color of static text easily and if you want another background color in your form you can handle WM_ERASEBKGRND to change it. You actually don't need to do anything at all in OnDraw if you don't want to. Or are there other requirements that I'm not aware of?
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
I'm working with vc.nte, i don't know if it makes a diference...
That cast is part of a piece of code i got and it worked, i hope that is not the reason this doesn't work.
And, honestly, i don't know how to deselect my font out of the device context.
The main reason i'm trying to do this is because the forms layout isn't completly defined, so if later i had to make changes in all, it would be easier, and if i could spare from creating more objects in my forms it would be better, but maybe that is what i'm going to do...
Thank you a lot for your time and dedication
rui
|
|
|
|
|
Well you are correct - it shouldn't have to be that hard to display the form And it does not have to be - as I said I think you would be better off by using the dialog editor in VC++.
The brush handle vs pointer can easily be resolved though if you want to but since this code isn't working then there's not much point in it really...
And to deselect the font you should use a similar technique as with the brush - i.e. save the old font and select it back when you are done with the one you are using.
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
Hi all,
I'm trying to implement a custom windows control, (not ActiveX control) and basically cannot succeed when using MFC.
I'm very familiar with straight Win32 programming in C/C++ and built some custom controls from scratch using WTL, but I cannot do it in MFC. It seems the problem lies in the way MFC handles a permanent map. I couldn't do this from either a regular DLL using MFC as a shared-library, nor an MFC-extension DLL.
Please, note that the DLL doesn't export any class. Only a single function InitWindowsControls() that registers the appropriate window class for the controls implemented in the DLL.
Any pointers?
Cheers.
--
Maxime Labelle
maxime.labelle@freesurf.fr
|
|
|
|
|
Hi,
I am using MSComm32 ActiveX in my application. I have a little problem with the following:
If I open the Com port using my app. and then try using the HyperTerminal to open the same com port, the HyperTerminal informs us that the port is already being used by some other program. If I close my app. the HyperTerminal can then open the port.
When I first open the com port with HyperTerminal and then try opening the com port with my app. the ActiveX also informs us that the port is already open. But if I close the HyperTerminal and try with my app. again, the ActiveX indicates that the port is closed and then when I try to open it I get an error.
The only way I can then get access is by resetting the modem attached to the com port and opening the com port.
Does anyone know how to fix this? Have you had the same problem?
Thanks
Regards
Rui
|
|
|
|
|
|
Only one application may have a given port open at a time. For example, if HyperTerminal has COM1 open, your application can not open COM1 as well.
If you want to use HyperTerminal to test your application, connect a null modem cable between COM1 and COM2. Run HyperTerminal using COM2, and your application using COM1.
Software Zen: delete this;
|
|
|
|
|
I'm a beginner and I already know how to use dc.MoveTo() and dc.LineTo(), but how can I draw a fine dotted line instead of solid?
Using a pen doesn't help here, it doesn't provide a fine pattern. Do I need to create a brush and how would I do this?
The line should look like this (vertical, 3 pixel width, X = black pixel):
x x
x
x x
x
x x
thanks for help and sorry for asking again!
|
|
|
|
|
I honestly don't know if this is possible using predefined DC functions but I'm not aware of such a function. You could experiment with creating a brush using the HS_DIAGCROSS style but I don't think it will be as fine grained as you wish. You might end up creating your own bitmap and blit it onto the DC (using BitBlt, StretchBlt or other methods) although I don't know what that will look like if the lines are neither horizontal nor vertical.
Your best bet would probably be to create a pen based on a LOGBRUSH since you can define a LOGBRUSH as using a bitmap as a pattern. Check out CPen::CreatePen, the LOGBRUSH struct and specially the BS_PATTERN Logbrush style.
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
dabs wrote:
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
okie, I'll try. thx!
|
|
|
|
|
I think you are going to have to use
LineDDA[^].
|
|
|
|
|
can anyone give me a small example of sharing a socket across the two different processes where one process receives data and the other process sends the data .
|
|
|
|
|
The two processes would not 'share' a socket. One process would act as the server end, and the other would act as the client end. Look up "Windows Sockets" in the MSDN.
Software Zen: delete this;
|
|
|
|
|
Hi!
How it is possible remember position bands on Rebar and further to insert bang into the necessary position with necessary displacement?
|
|
|
|
|
in my PocketPC2002 app, I create a CAysncSocket object to
send a file to the server. The PocketPC uses diap-up
connection to the Internet. I got some problems:
Case 1> I don't specify the operating mode of the socket.
while the sending is is progress, if the dial-up
connection is disconnected, the mySock.Send() does NOT
return! so my program hangs! Seems like CAsyncSocket
operates in blocking mode, but the documentation says
the default mode is non-blocking!
Case 2> I specify the operating mode like following:
unsigned long mode = 1;
ioctlsocket(mySock.m_hSocket, FIONBIO, &mode);
// explicitely set it to non-blocking mode
then, after a few KBs of data are sent, i get two
WSAEWOULDBLOCK errors and then mySock.Send() always
returns 0. The whole file can NOT be sent. While in the
first case, the whole file can be sent successfully
if the network is available throughout the transfer.
I'm very confused and frustrated as well! Please HELP!
Thanks a million!
Wenrich
|
|
|
|
|
Wenrich wrote:
Case 1> I don't specify the operating mode of the socket.
while the sending is is progress, if the dial-up
connection is disconnected, the mySock.Send() does NOT
return! so my program hangs! Seems like CAsyncSocket
operates in blocking mode, but the documentation says
the default mode is non-blocking!
I can not reproduce this behaviour.
An asynchronous Send() doesn't usualy block, it rather gives the data to your TCP/IP stack. Which will then send when it "feels good" for sending (NAGLE algorithm etc). But CAsnycSocket has a problem when connecting sockets, if you use hostnames instead of IPs, the DNS could (or will) block a short time.
M
|
|
|
|
|