|
Baltoro wrote: In the underlying Win32 API (the way it was done before GDI+), the client area of a window is painted by a call to BitBlt (or similar function), and then Invalidate, and finally Update.
A similar functionality exists in NET, but it is packaged differently. The Control class (which acts as a container for your image display) implements the Invalidate and Update methods. It's confusing at first glance, but, the Windows graphics system considers rendering a graphic to a window (or control surface) an expensive operation, so the Invalidate method exists so that windows stores the area to be repainted and then, when it recieves the next WM_PAINT message it actually displays the graphic. This is why when you resize or move a window it displays the refreshed image (a Re-size or move generate a WM_PAINT message.) If you call Update() on your control immediately after your drawing code is executed it should immediately display the refreshed image.
what is the function in NET, I use standard windows lib.
i'm using VS 2008, .NET 3.5
modified on Monday, January 12, 2009 12:52 PM
|
|
|
|
|
Valdyr wrote: Bitmap FrameBuffer((BITMAPINFO*) &((*BMPSlika).InfoHeader), (*BMPSlika).PixelData);
That line is suspicious to me....If you can't do it without casting
Bitmap FrameBuffer(&(BMPSlika->InfoHeader), BMPSlika->PixelData);
then something's wrong.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
yes, the BMPSlika is a pointer to another bitmap class. it's not in gdi, i created that structure based on information from this page http://www.fortunecity.com/skyscraper/windows/364/bmpffrmt.html[^] . it does work, and the image is displayed correctly but gdi+ Bitmap class needs another structure as argument (BITMAPINFO) so i needed to cast it.
The image is displayed correctly but it doesn't get refreshed, only when I do something with the window like resizing it, minimizing, (driving it off screen and back)...
this is the wndproc function
LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam){
PAINTSTRUCT ps;
HDC hdc;
switch(message){
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
Prikaz(hdc);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
SnimiBitmap();
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
as Baltoro said the WM_PAINT case is executed only when the window needs an update (when i resize it, minimize...) but it is executed also when I hold a mouse pointer over the window, but then the image doesn't get refreshed... the WM_PAINT case calls for Prikaz() and it is executed every time but when i hold a mouse pointer over the window it is called and executed but then the displayed image doesnt get refreshed...
|
|
|
|
|
You mentioned something about a loop in your first post - where is this loop and
what is it (supposed to be) doing?
WM_PAINT is posted to your window's message queue by the system. The parameters are
not in your control, nor are they wrong, nor should you be trying to send/post a WM_PAINT
message yourself.
Window rendering has been the same since the beginning of Windows....the problem is in YOUR code,
not some problem in MFC (which you're not using apparently), .NET (which you're not using apparently),
or the system.
void Prikaz(HDC hdc){
Graphics graphics(hdc);
Render();
Bitmap FrameBuffer((BITMAPINFO*) &((*BMPSlika).InfoHeader), (*BMPSlika).PixelData);
graphics.DrawImage(&FrameBuffer,0,0);
}
This code has nothing to do with WM_PAINT or Invalidatexxxx() functions. The bitmap will be rendered
immediately if the HDC and the Bitmap are valid.
According to your comments, your WM_PAINT handling code is working fine, so where else are
you calling this from and how are you obtaining the HDC?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
there is a problem and I cant use invalidate, i'll work on that. in the meanwhile here is WndProc procedure, it might bee something here that prevents image being refreshed. I think some of the variables in PAINTSTRUCT ps, HWND hWnd, and HDC hdc are not properly set for the image to be refreshed; (firstly I think it has something to do with PAINTSTRUCT);
LRESULT CALLBACK WndProc(HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam){
PAINTSTRUCT ps;
HDC hdc;
switch(message){
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
Prikaz(hdc);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
SnimiBitmap();
return 0;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
this is WndProc process, in case it can solve my problem. I think there is something with this WM_PAINT case, it is called only when I resize, minimize, move it offscreen OR when i hold mouse pointer over the (display) window.
In first three situations when I resize, minimize, or move offscreen, the image does get refreshed, (the WM_PAINT case is executed and in it the Prikaz(hdc) iz executed which displays new image)
In the fourth situation, when I hold a mouse pointer over the display window, the WM_PAINT case is switched and the Prikaz(hdc) does get executed (including all the functions in Prikaz(hdc)), but the image doesn't get refreshed...?
this leads me to conclusion that something is not "properly" set in this line, (since the Prikaz(hdc) uses argument hdc):
hdc = BeginPaint(hWnd, &ps);
I have seen the variables in ps (which is an PAINTSTRUCT structure), the hWnd (which is of HWND type) and hdc (HDC type (:lol))... In each situation they hold different values except for ps.fErase, ps.fIncUpdate, ps.fRestore. they are allways set to value 0;
there is allso ps.rgbReserved which is an pointer to an array of bytes but i'll examine it more closely.
if anyone knows about PAINTSTRUCT structure or hWnd and hdc, what is wrong with them when the image doesn't get refreshed, please let me know. in meanwhile I will try something with ps.rgbReserved, and try to get invalidate() function to include in my code, (this has something to do with .NET namespaces to do i think)....
(i have posted this message also in the graphics forum under the same name of the question. At the time i first asked the question i didn't know weather to post it in this forum or graphics because this has something to do with MFC, (with the MFC function: invalidate(), and the thing that i'm not being able to use this function)...)
|
|
|
|
|
Hi dear,
I would like to enable my application to be run only once (instance) per system.
In another word, I would like to avoid executing application more than once per system.
I knew I can save something in the Windows-Registry, but I'm interested in solving
it in another way.
Thanks in advance.
|
|
|
|
|
So see Avoiding Multiple Instances of an Application[^](Learn the right way to limit your application to run only one instance).
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Hi all
<code>
#include <windows.h>
HWND handle;
int main ()
{
handle = GetForegroundWindow();
SetWindowText(handle,"Hello!");
return 0;
}
</code>
When i compile my program it's not working and give me the error say
Cannot convert parameter 2 from char[7] to LPCWSTR in SetWindowText function.
Regards
-*-*-*-*-*-*-*-*-*
To Be Or Not To Be
(KARFER)
-*-*-*-*-*-*-*-*-*
|
|
|
|
|
Its SetWindowText(handle,_T("Hello!"));
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
thank's for all replays
-*-*-*-*-*-*-*-*-*
To Be Or Not To Be
(KARFER)
-*-*-*-*-*-*-*-*-*
|
|
|
|
|
You project settings are set to Unicode but you're using ANSI strings.
Steve
|
|
|
|
|
Hi,
I've a requirement to find how many database exists in a SQL Server.
I want this to be done VC++ 6.0. There is some method to do it using CDataSource, CSession, CSchemata etc but not aware of how to do it. Can any body help me out in this?
User Name, Password and Server (IP/Hostname) name will be provided as argument. I want the list all the database present in the SQL Server. This will be a small C++ program as this needs to work from SQL Server 2000 and above.
The method will be as follows
CStringArray FindDatabase(CString szHostName, CString szUserName, CString szPassword)
This method should return the list all the database instance of SQL server of the specfied IP.
Please help.
Thanks in advance.
Unni
|
|
|
|
|
Did you seeEnumerate SQL Server using SQL DMO[^]?
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
Thanks.
I thought that's obsolete technology.
I think this is possible using OLEDB. After googling i got some hints but don't know how to proceed.
I'm looking for a code snippet. Something like this - but don't know how to proceed
HRESULT hResult;
hResult = ::CoInitialize(0);
if (SUCCEEDED(hResult)){
CDataSource dataSource;
hResult = dataSource.OpenFromInitializationString(OLESTR("Provider=SQLNCLI.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Data Source=NEWCOMPUTER\\SQLEXPRESS"), false);
if (SUCCEEDED(hResult)){
CSession session;
hResult = session.Open(dataSource);
if (SUCCEEDED(hResult)){
// now get the list of database using CSchemata or something like that
// dont know what to do
session.Close();
printf("Success");
}
dataSource.Close();
}
::CoUninitialize();
}
Thanks,
Unni
|
|
|
|
|
Look at SYSTABLES , specifically the dbname field.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
At last I got the solution.
#define DB_S_ENDOFROWSET ((HRESULT)0x00040EC6L) //added for VC6
CDataSource dataSource;
hResult = dataSource.OpenFromInitializationString("Provider=SQLOLEDB.1;Password=****;Persist Security Info=True;User ID=*****;Data Source=myIPAddress); // Or Open using other parameters
CSession session;
hResult = session.Open(dataSource);
CCatalogs catalog;
hResult = catalog.Open(session);
catalog.MoveFirst();
while( SUCCEEDED(hResult) && hResult!= DB_S_ENDOFROWSET )
{
cout << catalog.m_szName << endl;
hResult = catalog.MoveNext( );
}
catalog.Close();
session.Close();
dataSource.Close();
CoUninitialize();
And this worked fine for me
Thanks,
Unni
|
|
|
|
|
<br />
typedef int (WSAAPI *Pconnect)<br />
(SOCKET s, struct sockaddr *name, int *namelen);<br />
<br />
<br />
int WSAAPI myconnect(SOCKET s, struct sockaddr *name, int *namelen)<br />
#define SIN(name) ((struct sockaddr_in *)(name))<br />
{<br />
struct sockaddr_in *paddr =(struct sockaddr_in *)name;<br />
<br />
char *ip =inet_ntoa(SIN(name)->sin_addr);<br />
int port =ntohs(paddr->sin_port);<br />
<br />
if (port == 101) <br />
{<br />
SIN(name)->sin_addr.s_addr = 0x0100007f;<br />
return ((Pconnect)hookconnect.pTrampoline)(s, name, namelen);<br />
}<br />
<br />
return ((Pconnect)hookconnect.pTrampoline)(s, name, namelen);<br />
}<br />
<br />
I found this function to redirect everytime application try to connect 101 port and connect localhost, but i have to listen same port as the application is, is there a way to edit this function make to connect diff. port?
thank you
|
|
|
|
|
Can't you simply redirect it to a different port just as you redirected it to a different IP?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
Like i said i found this code, and i don't know anything about C++ anything at all. that is the problem hahaha.... i believe you can but the reason is how? hahah..
|
|
|
|
|
Well, try something like this:
if (port == 101)
{
SIN(name)->sin_addr.s_addr = 0x0100007f;
paddr->sin_port = htons(PORT_NUMBER_YOU_WANT_TO_REDIRECT_TO);
return ((Pconnect)hookconnect.pTrampoline)(s, name, namelen);
}
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
|
|
|
|
|
|
Hi,
I have an (owner drawn) list control and handle the LVN_ODFINDITEM message. For testing purposes:
void CIndexDlg::OnLvnOdfinditemData(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLVFINDITEM pFindInfo = reinterpret_cast<lpnmlvfinditem>(pNMHDR);
*pResult = (rand() % 999) + 1;
}
</lpnmlvfinditem>
This works good when typing something inside the control.
But now I also want to have an external way to find an entry. So I places an edit control in the dialog and want to call FindItem manually:
LVFINDINFO fi;
ZeroMemory(&fi, sizeof(fi));
fi.flags = LVFI_PARTIAL | LVFI_STRING;
fi.psz = m_strWhat;
m_ctrlData.FindItem(&fi);
But in this case, my OnLvnOdfinditemData handler never gets called! I also tried sending manually with SendMessage but it did not work either.
What could be the problem?
|
|
|
|
|
- Could you use Spy++ to investigate what messages (with wparam and lparam? Not sure if Spy++ tracks those) are sent when doing an incremental search using the keyboard
- Have you verified your
FindItem call is successful with a non-virtual/non-owner data list control?
Aside from that, can't see as you're doing anything wrong
|
|
|
|
|
Hi and thank you for the help!
I tried it with Spy++ and for testing, I typed an 'a'. The message is sent:
<00004> 00070E74 S LVM_FINDITEMA iStart:-1 plvfi:0012E8D8
<00005> 00070E74 R LVM_FINDITEMA iIndex: 86
I really don't know why my message handler is not called
Niki
|
|
|
|
|
I know what is my error:
FindItem and SendMessage(LVM_FINDITEMA) only gives back the index of the found item but the control does not scroll automatically to that position.
Is there a way to implement this?
I already tried UpdateWindow() and also SetSelectionMark()...
Thank you!
|
|
|
|
|