|
In my opinion ,I don't put code in CMyView::OnInitialUpdate()". It may be better to use a menu named "Link DataBase",
the user click the menu ,then the application link to the DB accesss. If access failed ,you can give the user an
Error MessageBox . Thus you can put the DB access code in CMyView::On****( ).
libo
|
|
|
|
|
Have you considered putting the database-access code in a separate thread? This would allow the primary thread, which owns the GUI, to remain active and responsive.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Hello All
I am accessing DB using user defined message handler.
Due to more number of threads i have avoided using one more thread. But thanks for your solution.
Have nice time
Ravi
|
|
|
|
|
Hi,
I would like to create an owner draw CListCtrl in thumbnail mode. Can somebody please help me by giving some pointers in doing this. I have done owner draw list controls for the detail view, But for the icon view, I am very much confused.
Some articles or code sample would be really helpful.
Looking forward for a reply.
Thanks and Regards
San
"A robust program is resistant to errors -- it either works correctly, or it does not work at all; whereas a fault tolerant program must actually recover from errors."
|
|
|
|
|
I am karnal and nowadys learning Vc.
I have a problem
"I have a Dialog based MFC program via i captured Bitmap, now i want to print this captured bitmap on default network printer,
The code for capturing bitmap is as follows
-------------------------------
void WriteBmp(char* filename,BITMAP *bmp,int* data)
{
BITMAPINFO Bmi;
memset(&Bmi,0,sizeof(BITMAPINFO));
Bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
Bmi.bmiHeader.biWidth = bmp->bmWidth;
Bmi.bmiHeader.biHeight = bmp->bmHeight;
Bmi.bmiHeader.biPlanes = 1;
Bmi.bmiHeader.biBitCount = bmp->bmBitsPixel;
Bmi.bmiHeader.biCompression = BI_RGB;
Bmi.bmiHeader.biSizeImage = bmp->bmHeight*bmp->bmWidth*bmp->bmBitsPixel/8;
FILE* image = fopen (filename,"wb");
if(image==0)
return;
int h = abs(Bmi.bmiHeader.biHeight);
int w = abs(Bmi.bmiHeader.biWidth);
Bmi.bmiHeader.biHeight=h;
Bmi.bmiHeader.biWidth=w;
int sz = Bmi.bmiHeader.biSizeImage;
BITMAPFILEHEADER bfh;
bfh.bfType=('M'<<8)+'B';
bfh.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
bfh.bfSize=sz+bfh.bfOffBits;
bfh.bfReserved1=0;
bfh.bfReserved2=0;
fwrite(&bfh,sizeof(bfh),1,image);
fwrite(&Bmi.bmiHeader,sizeof(BITMAPINFOHEADER),1,image);
fwrite(data,sz,1,image);
fclose(image);
}
void CFullscreenDlg::OnShowWindow()
{
HANDLE hBitMap =(HBITMAP) ::LoadImage(AfxGetInstanceHandle(),
m_bmp.m_str,IMAGE_BITMAP,0,0,
LR_LOADFROMFILE | LR_CREATEDIBSECTION); // put here the handle of the window you would like to caputre
CBitmap bmp;
bmp.Attach((HBITMAP)hBitMap);
BITMAP bitmap;
bmp.GetBitmap(&bitmap);
int size = bitmap.bmWidth*bitmap.bmHeight*bitmap.bmBitsPixel/8;
BYTE *lpBits = new BYTE[size];
::GetBitmapBits((HBITMAP)hBitMap,size,lpBits);
WriteBmp("c:\\test.bmp",&bitmap,(int*)lpBits);
delete []lpBits;
}
-----------------------------------------------
so plz help me to solved out my printing problem.
Thanking u all
Karnal
karnal
|
|
|
|
|
How to create a .jpg file using VC++?
aasstt
|
|
|
|
|
|
I have a menu with several items, one of which is a submenu. Normally, I use Class Wizard and ON_UPDATE_COMMAND_UI to enable or disable menu items.
But I'm not able to use the same technique to gray a submenu name itself because it doesn't have a command ID associated with it. Is it possible to gray a submenu item using MFC?
Mallikarjun Avanna Lavate
|
|
|
|
|
i HAD GOT THE ANSWER.....
OnUpdateFLOWMASTERVERSION3(CCmdUI* pCmdUI)
{
// decide here whether to enable or disable pop-up menu:
if (pCmdUI->m_pSubMenu != NULL)
{
BOOL bEnable = TRUE; //if we want disable then writ false otherwise true
pCmdUI->m_pMenu->EnableMenuItem(pCmdUI->m_nIndex,
MF_BYPOSITION | (bEnable ? MF_ENABLED :
(MF_DISABLED | MF_GRAYED)));
}
}
|
|
|
|
|
Maybe it's difficult to use CmdUIUpdate.
The way I know is:
//Suppose the popup menu is the first item in the first drop-down menu.
CMenu* pMainMenu = GetMenu(); //"this" is CMainFrame
CMenu* pSubMenu = pMainMenu->GetSubMenu(0);//0 is the first window menu
pSubMenu->EnableMenuItem(0, MF_BYPOSITION | MF_GRAYED); //0 is the popup menu
Lane Yu
China
|
|
|
|
|
Hi,
I derived a CButtonEx from CButton. I implemented it as general purpose dll.
The problem is that the PreTranslateMessage is not working.
Is there any problem with PreTranslateMessage and a dll?
- NS -
|
|
|
|
|
According to MS, a custom DLL that is statically linked to the MFC library needs to have a CWinApp-derived class and a single object of that application class, as does an executable MFC application. The CWinApp object of the DLL, however, does not have a main message pump, as does the CWinApp object of an application. If the DLL opens modeless dialogs or has a main frame window of its own, the application's main message pump must call a routine exported by the DLL, which in turn calls the CWinApp::PreTranslateMessage member function of the DLL's application object.
See coding example and more info on the topic here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample98/html/_sample_mfc_dlltrace.asp[^]
SkyWalker
|
|
|
|
|
Thank you.
Does it mean that we can't write a stand alone button control (library) using dll (that is without processing the message specially for the button in the application)?
- NS -
|
|
|
|
|
You can write whatever dll you want
I would recommend you using the following:
<br />
Overwrite the PreTranslateMessage()for your window derived class (whatever that may be):<br />
BOOL CDllWnd::PreTranslateMessage(MSG* pMsg)<br />
{<br />
if (IsDialogMessage(pMsg))<br />
return TRUE;<br />
<br />
return CWnd::PreTranslateMessage(pMsg);<br />
}<br />
-----------<br />
Export then a function<br />
extern "C" DllExport BOOL FAR PASCAL FilterDllMsg(LPMSG lpMsg)<br />
{<br />
AFX_MANAGE_STATE(AfxGetStaticModuleState())<br />
TRY<br />
{<br />
return AfxGetApp()->PreTranslateMessage(lpMsg);<br />
}<br />
END_TRY<br />
<br />
return FALSE;<br />
}<br />
-----------<br />
In user application: <br />
BOOL CYours::PreTranslateMessage(MSG* pMsg)<br />
{<br />
if (CTheBaseClass::PreTranslateMessage(pMsg))<br />
return TRUE;<br />
<br />
return FilterDllMsg(pMsg);<br />
}<br />
SkyWalker
-- modified at 6:53 Monday 3rd October, 2005
|
|
|
|
|
|
In my application i want to have a sys tray icon which has a Menu like
A
B
C --> C.1
C.2
C.3
D --> D.1
D.2
D.3
E --> E.1
E.2
A and B do not have pop-ups and are present to invoke some defined shortcuts
In my resource editor I have created a MEnu resource having the following
A
B
C
D
E
F
Elements for C , D and E and added and removed at run-time .
I want to be able to create functionality to be add the same . I was unable to find any routines where I would be able to add a CMenu (for say menu containing C.1 ,C.2 etc) to an existing CMenu(GetSubMenu(0)) .
Please help
THanks
-- modified at 21:58 Sunday 2nd October, 2005
|
|
|
|
|
is there a way to simulate a hardware interrupt in C++? i want to generate an interrupt for lets say mouse movement or keyboard press. is this possible?
thanks!
|
|
|
|
|
|
I'd like to create a program that will send a file (.txt) to its server. I came across articles regarding TCP/IP, Socket, WinSock, etc.. Which of these do I have to focused into in creating a simple server/client connections? of course these methods have their own advatages/disadvantages or limitations. There's a NDK program/article here in codeproject but I don't know if I'll just use it or better create network programming on my own.
One more thing, is it possible for a program to detect if the computer it currently resides into is the server or the client? So that my program will automatically shift into server mode/client mode depending where it is being launched. Thanx
|
|
|
|
|
For simple network comunication any article on Socket or Winsock should be enough.
If you want to indentify the current computer you can use gethostname() and then gethostbyname() if you want the IP address.
|
|
|
|
|
Look try to study and use the
socket , it the basic element
for networking.CSocket is a
usefull class provided by VC.
If u have defined the port range
say from 7000 to 8000 . Then u
can try connecting to it as a
Client .If there is successfull
connection then u can know that
the opposite machine is a Server
else it is Client .The program
just have to use a FOR loop.
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
benjnp wrote:
I'd like to create a program that will send a file (.txt) to its server. I came across articles regarding TCP/IP, Socket, WinSock, etc.. Which of these do I have to focused into in creating a simple server/client connections? of course these methods have their own advatages/disadvantages or limitations. There's a NDK program/article here in codeproject but I don't know if I'll just use
Having used the NDK library I can tell you it’s got a nice interface and works well. To send text files (or any files for that matter) you will need to add that functionality. There is however another simple project here that demonstrates sending files.
Network Transfer Of Files Using MFC's CSocket Class
[^]
benjnp wrote:
or better create network programming on my own.
As far as writing your own, go ahead there is no better way to learn network programming than doing it your self.
benjnp wrote:
One more thing, is it possible for a program to detect if the computer it currently resides into is the server or the client? So that my program will automatically shift into server mode/client mode depending where it is being launched. Thanx
That should be easy enough, when the main dialog or view starts, read the servers location (computer name) from where ever (registry or ini file) compare it to the local host (see gethostbyname()) if they are the same then start the app in server mode.
Good Luck...
DEBUGGING : Removing the needles from the haystack.
|
|
|
|
|
thanx for your help guys, i'll start looking for topics regarding socket programming right away
|
|
|
|
|
How can I make my computer a SERVER and have other computers connected to the INTERNET as client? My computer is a part of a LAN which connects to the internet through a gateway.
Ranjan
|
|
|
|
|
Hi Dear
Socket progamming is so nice, you can use CSocket & CAsyncSocket.
you can find meny sample in
Here]
Iman Ghasrfakhri
|
|
|
|