|
ruzu wrote: //Timer that triggers my paint panel:
public: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
panel1->Paint += gcnew System::Windows::Forms::PaintEventHandler( this, &Form1::panel1_Paint);
panel1->Invalidate();
}
Why do you subscribe to Paint (using the += operator) inside every timer tick? It should be sufficient to do this once, preferably in the constructor after the InitializeComponent method call.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
That would explain why the "CPU load increases linearly". If I understand the code properly each "+=" operation on the delegate adds another entry to the delegates list of functions to call. Looks like after running for a bit panel1_Paint is probably getting called god knows how many times (when once would suffice).
Steve
|
|
|
|
|
#define WIN32_LEAN_AND_MEAN // no to MFC
///////////////////////////////////////////////////////////////////////////////////////////
// INCLUDE DIRECTIVES /////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <d3d9.h>
#pragma warning( disable : 4996 ) // disable deprecated warning
#include <strsafe.h>
#pragma warning( default : 4996 )
///////////////////////////////////////////////////////////////////////////////////////////
// DEFINES ////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
// for D3D objects that don't have an explicit release function
#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } }
// free up anything allocated with "new"
#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } }
// anything allocated with new []
#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p); (p)=NULL; } }
// The window caption.
#define WINDOW_CAPTION L"D3D Tutorial 01: CreateDevice"
// The window class.
#define WINDOW_CLASS L"D3D Tutorial"
///////////////////////////////////////////////////////////////////////////////////////////
// FUNCTION PROTOTYPES ////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
HRESULT InitD3D( HWND hWnd );
VOID Cleanup();
VOID Render();
///////////////////////////////////////////////////////////////////////////////////////////
// GLOBAL VARIABLES ///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
LPDIRECT3D9 g_pD3D = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; // Our rendering device
///////////////////////////////////////////////////////////////////////////////////////////
// FUNCTION DEFINITIONS ///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
HRESULT InitD3D( HWND hWnd )
{
// Create the D3D object, which is needed to create the D3DDevice.
if( ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) == NULL )
{
return E_FAIL;
}
// Set up the structure used to create the D3DDevice. Most parameters are
// zeroed out. We set Windowed to TRUE, since we want to do D3D in a
// window, and then set the SwapEffect to "discard", which is the most
// efficient method of presenting the back buffer to the display. And
// we request a back buffer format that matches the current desktop display
// format.
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
// Create the Direct3D device. Here we are using the default adapter (most
// systems only have one, unless they have multiple graphics hardware cards
// installed) and requesting the HAL (which is saying we want the hardware
// device rather than a software one). Software vertex processing is
// specified since we know it will work on all cards. On cards that support
// hardware vertex processing, though, we would see a big performance gain
// by specifying hardware vertex processing.
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}
// Device state would normally be set here
return S_OK;
}
VOID Cleanup()
{
SAFE_RELEASE(g_pd3dDevice)
SAFE_RELEASE(g_pD3D)
}
VOID Render()
{
if( g_pd3dDevice == NULL )
{
return;
}
// Clear the backbuffer to a blue color
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
// Begin the scene
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
// Rendering of scene objects can happen here
// End the scene
g_pd3dDevice->EndScene();
}
// Present the backbuffer contents to the display
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
Cleanup();
PostQuitMessage( 0 );
return 0;
case WM_PAINT:
Render();
ValidateRect( hWnd, NULL );
return 0;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
// Register the window class
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_CLASSDC;
wc.lpfnWndProc = MsgProc;
wc.cbClsExtra = 0L;
wc.cbWndExtra = 0L;
wc.hInstance = GetModuleHandle(NULL);
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = WINDOW_CLASS;
wc.hIconSm = NULL;
RegisterClassEx( &wc );
// Create the application's window
HWND hWnd = CreateWindow( WINDOW_CLASS, WINDOW_CAPTION,
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
NULL, NULL, wc.hInstance, NULL );
// Initialize Direct3D
if( SUCCEEDED( InitD3D( hWnd ) ) )
{
// Show the window
ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );
// Enter the message loop
MSG msg;
while( TRUE )
{
if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
if ( msg.message == WM_QUIT )
{
break;
}
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
}
UnregisterClass( WINDOW_CLASS, wc.hInstance );
return 0;
}
IM PROUD TO BE A GMAIL;
|
|
|
|
|
How to determine how much data stored in pipe object without reading it with ReadFile, that is some equvalent that we are able to determine amount of bytes in internet windows socket to allocate buffer and read it all in one function call.
9ine
|
|
|
|
|
In your protocol you could make it so that the first few bytes help determine or provide the size for the next command. The other end of the pipe would then always write an atomic operation for the protocol size. You then have this common header for your protocol in which you would read first to determine the size of the next packet. You could do it in 2 steps or you could allocate a buffer which reads as much data as it can off and parses the protocol through and if a packet is cut off then simply re-read. If you want to ensure that you would never get the packet cut off then simply ensure that all packets are the same size and create the buffer as a multiple.
Otherwise I do not know of an API to peek the amount of data in the pipe currently however it is a handle so you could attempt to experiment with some APIs to see what results they yeild.
8bc7c0ec02c0e404c0cc0680f7018827ebee
|
|
|
|
|
I have a graph control in my application where i plot a series of values .I need to show the specific x and y coordinate values on the graph.
For the code what i have written it is working fine for print preview but when i print the graph, i could just see a rectangle outline on the graph but not the text content in it.But its working fine for the print preview. i have written the same code for both, passing the respective DC values whenever the respective flag is set.
Pls let me know the reason .
Regards
James
|
|
|
|
|
Are u using MFC's Print & Print Preview functions?
|
|
|
|
|
i am calling the OnPrint() function where i have created a compatibleDC() using createCompatibleDC() for the printer and passed the dc to onDraw() along with the device-independent bitmap which i need to print.
The OnDraw() function handles the code for both printpreview and printing based on the appropriate flag.
|
|
|
|
|
i have create an win32 application with mfc as a shard dll option.i am not able to access classwizard.the menu is disabled.how can i use classwizard?
|
|
|
|
|
Try erasing the class wizard file(your_project.clw file)
and try enter again to class wizard(ctrl + w).
Regards,
Eli
|
|
|
|
|
there is class wizard file
|
|
|
|
|
sorry there is no class wizard file.
|
|
|
|
|
Is this MFC project?
if so,try ctrl + W to create new class wizard file and
choose "Add all" button to add al classes to class wizard.
|
|
|
|
|
|
HI,
How can I determinate the mouse click position within an CListCtrl::OnColumnClick handler relative to the upper left corner of the headers column rectangle.
It seems that the NMLISTVIEW ptAction member is not used for this notification message ?
Thx.
|
|
|
|
|
Use GetMessagePos() to get the mouse position of the last message retrieved with GetMessage() . This should solve your problem.
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"
|
|
|
|
|
Hello!
Suppose that we have a list of printer names and papers in CComboBox.
Is there a way to get the printer DC from these info or technically :
<br />
CDC* getPrinter(LPCTSTR printerName, LPCTSTR paper, int landscape=1);<br />
Your comments & ideas are really helpful.
Thanks
|
|
|
|
|
use CreateDC(...) and pass in a properly filled devmode.
Vipin - MVP
|
|
|
|
|
Thank you very much for your comments. It really works
Sovann.
|
|
|
|
|
Hello,
I'd like to have more information about Web-Style based GUI for MFC application. There is an article here at Codeproject. However, I need more information than it provides.
I'd be very pleased if you can give some sites or articles to read.
Thanks
Allad
|
|
|
|
|
The custom control is associated with a class derived from CScrollView,
works fine, but when I try to handle WM_CREATE in OnCreate, I found that OnCreate isn't called.
I don't know where to put the initial code after the control is created and before displayed.
Thanks for help.
|
|
|
|
|
You can try to call CView::OnInitialUpdate
It is called before the control is displayed.
Cheers,
Allad
|
|
|
|
|
It's not called either.
PreSubClassWindow is ok.
|
|
|
|
|
Because when your class is ready to handle messages, the control has already been created.
So you should insert your initlizing code in PreSubClassWindow().
|
|
|
|
|
If your custom control is on a dialog or form view (created from a dialog template) then your class's OnCreate() is never called. That is because the contol window is created when the dialog is created, and then your control subclasses the window. Use PreSubclassWindow to handle the code that you would normally handle in OnCreate .
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|