|
Hello everybody
I would appreciate it if I can get help adding a picture into my program. I'm using visual c++ 6. This must really be simple, I just need the picture on my main dialog, but the program should be able to run without having the bitmap with it.
thanx...
KOM UIT DAAAAA!!!
|
|
|
|
|
You can import bmp file to resource and use of CBitmap::LoadBitmap for load use of WM_PAINT or WM_ERASEBKGND for draw it,but my suggestion is you reading your file from disk instead import it to your project because it increase size of your exe
|
|
|
|
|
How should i add the bitmap to the resources? The size of the exe isn't a issue in this case, thanx for the help....
KOM UIT DAAAAA!!!
|
|
|
|
|
Right click on resource window and select Add Resource and click import button and select your file and click open button now this file insert to resources now you can use from this code in your program
<br />
CBitmap p;<br />
p.LoadBitmap(IDB_BITMAP1);<br />
and then on WM_PAINT try to draw it
Resource Window->Add Resource->Import->Select File->click open
--------------------
But if you have a picture on clipboard and you want to insert it to resource you can create a bitmap on resource and if Color file is True Color then select True Color on resource and then use of Shift+Insert now this picture paste on resource
|
|
|
|
|
I have somewhat of a strange problem. I have designed a custom window in which the title bar is inside the window as opposed to on top. I process all the mouse messages to correctly handle clicks and whatnot within this new area. The problem relates to the WM_NCLBUTTONUP message. I added this to handle the button clicks, but it is never trapped, infact when a button is double clicked the WM_NCLBUTTONUP works. WM_NCLBUTTONDOWN works as it should, but to process button clicks this is in appropriate. Also the WM_NCLBUTTONDBLCLK works as should. Can anybody think of a reason why my WM_NCLBUTTONUP handler only responds to double clicks?
case WM_NCHITTEST:
pt.x = LOWORD(lParam);
pt.y = HIWORD(lParam);
ScreenToClient(hWnd,&pt);
SetRect(&rc,RECT_NONCLIENT);
if ( PtInRect(&rc,pt) )
{
SetRect(&rc,RECT_CLOSE);
if ( PtInRect(&rc,pt) )
return HTCLOSE;
return HTCAPTION;
}
return HTNOWHERE;
case WM_NCLBUTTONUP:
switch ( wParam )
{
case HTCLOSE:
SendMessage(hWnd,WM_CLOSE,0,0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
|
|
|
|
|
Never mind, my own stupid fault. I hadn't included a WM_NCLBUTTONDOWN handler to prevent DefWindowProc from messing thing up.
|
|
|
|
|
My colleague wrote the following code and I wander why there are no "delete" statement for the two string variables *pSNew and *pSN.
Is there a memory leak?
Urgent! Thanks
void CCommTSP32View::OnPMDeviceFound( long _id, long _device )
{
// now it critical!
EnterCriticalSection( &m_csCommunicationSync ) ;
string *pSNew ;
string *pSN ;
// Init
pSNew = new string ;
pSN = (string*)_device ;
*pSNew = *pSN ;
PostMessage( WM_SPY_DEVICE_FOUND, _id, (long)pSNew ) ;
// release critical section
LeaveCriticalSection( &m_csCommunicationSync ) ;
}
ccp
|
|
|
|
|
string *pSNew should really be deleted after the call to PostMessage, but since the pointer is being passed to another part of the code, it's possible it is being deleted there. Take a look at the WM_SPY_DEVICE_FOUND handler to verify what is happening to the lParam.
Generaly, it's bad practice to allocate and deallocate memory in seperate parts of the code. As a rule, any time I delete something, I will set it to NULL, then, at the same place of allocation, I will try to delete again if no longer required.
|
|
|
|
|
why do u need to set it to Null before delete?
|
|
|
|
|
ccp999 wrote: why do u need to set it to Null before delete?
Actually, this is nonsense.
By setting a pointer to NULL you are invalidating it, not deleting the memory it points to.
Its the other way round: delete it, then set it to NULL (so that no one would use that pointer which does no longer point to memory you own again).
delete on a NULL-pointer does no harm, though.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
What is the purpose of this code?
pSNew = new string ;
pSN = (string*)_device ;
*pSNew = *pSN ;
why can't just use _device directly?
|
|
|
|
|
Without seeing the whole code it's hard to say, but what it is doing is making a copy of the variable.
You have to set the pointer to null otherwise delete will throw an exception.
|
|
|
|
|
I'm afraid that you can not delete the string because the PostMessage method posts the message and immediately returns. Note SendMessage sends the message and waits until it is processed. So if you delete the string the method which will process the message (sent via PostMessage) will probably crash because the pointer is invalid. Therefor the message processing should delete the string.
Moreover if this message is posted to different application it is even complicated. In that case I recommend to use GlobalAddAtom and GlobalDeleteAtom. But probably this is not your case...
|
|
|
|
|
Let's see how would I say this I have never really used visual C++ for anything. If any one could start me off in the right direction with a good tutorial that would be nice. Or at least tell me some of the abbreviations for certain things. Thanks.
I'm a true failure.
|
|
|
|
|
|
|
it is a nice site.
http://www.functionx.com/visualc
|
|
|
|
|
Is it possible to use the tab order set for edit controls in the dialog editor in the program? Is it possible to access an edit box via its tab order?
I can access by the control ID like this:
CWnd* pt;
pt = AfxGetApp()->m_pMainWnd->GetDlgItem(IDC_EDIT1); <-----uses IDC_EDIT1
pt->SetWindowText("AAAAA");
Or I can access a different edit box by an offset to the first ID Like this:
pt = AfxGetApp()->m_pMainWnd->GetDlgItem(IDC_EDIT1 + 8); <----uses IDC_EDIT1 + 8
Or I can set up the IDs in an array, and access like this:
pt = AfxGetApp()->m_pMainWnd->GetDlgItem(IDArray[5]); <----uses ID stored in array
So, this leads me to ask if there is some way to use the tab order defined in the dialog editor to do something similar.
Thanks
|
|
|
|
|
You can iterate through the controls in their tab order with GetNextDlgTabItem()
|
|
|
|
|
The tab order determines what order the controls are placed on the dialog window
by changing the order of the control statements in the dialog resource.
I suppose you could enumerate all the child windows of the dialog with GetTopWindow() and
GetNextWindow() (which would iterate through the controls in reverse tab order) or use
EnumChildWindows(). For each child window, check its class with GetClassName() to see if it's an
edit control. If it's an edit control then process it accodingly.
This seems like a lot of work considering you have full control over which controls are in
the dialog and what all of their IDs are, even if you add or remove controls at runtime. Unless
controls are being added/removed by another process...
If I knew what you are trying to do I could maybe give you a more specific code example
Mark
|
|
|
|
|
Hi all, I was trying to change the application icon through the windows class by changing the icon macros loaded into windows class as shown below, but no matter what icon macro I choose the icon displayed is the application icon from IDI_APPLICATION macro.
<br />
windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
...<br />
...<br />
windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);<br />
Could please tell how to change the icons by icon macros. Any help would be greatly appriciated.
Thanks
Scody
|
|
|
|
|
if you run this code wcex.hIconSm= LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); what happens?
From the MSDN
HICON LoadIcon(HINSTANCE hInstance,LPCTSTR lpIconName);
hInstance
[in] Handle to an instance of the module whose executable file contains the icon to be loaded. This parameter must be NULL when a standard icon is being loaded
|
|
|
|
|
Hi WhiteSky,
I have just tried the code as you suggested
<br />
windowClass.cbSize = sizeof(WNDCLASSEX);<br />
windowClass.style = CS_HREDRAW | CS_VREDRAW;<br />
windowClass.lpfnWndProc = WndProc;<br />
windowClass.cbClsExtra = 0;<br />
windowClass.cbWndExtra = 0;<br />
windowClass.hInstance = hInstance;<br />
windowClass.hIcon = LoadIcon(windowClass.hInstance, (LPCTSTR)IDI_WINLOGO);
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.hbrBackground = NULL;
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = "AeroClass";<br />
windowClass.hIconSm = LoadIcon(windowClass.hInstance, (LPCTSTR)IDI_WINLOGO);<br />
but still the default application icon is displayed. I would like to use standard icon Windows logo to be displayed on my application window, so I was using NULL in my code in the previous posting.
All I want to do is change the icon on my application window to Windows logo using standard icon macro IDI_WINLOGO.
Any help would be greatly appriciated.
Thanks
Scody
|
|
|
|
|
open the resource header file, find the definition for the icons. Give the icon you want the smaller number. The default Icon for an exe is the first icon found (the one with the smallest number).
|
|
|
|
|
You can override PreCreateWindow() to use your custom window class instead of the default...
This example assumes szMyRegisteredWindowClass points to the class name associated with your
"windowClass"
BOOL MyWindowClass::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CBaseWndClass::PreCreateWindow(cs) )
return FALSE;
cs.lpszClass = szMyRegisteredWindowClass;
cs.style = <possible override default window style here>;
cs.dwExStyle = <possible override default extended window style here>;
return TRUE;
}
|
|
|
|