|
1)
I recently try to create a password protection program!!! But the problem was when I press "ENTER" in the edit box it will exit the program!!!! Anyone know how to fix this problem!!!(I want the Password check box checked in the property of edit box)!!
2)
Are there a WM_KEYDOWN event for the edit box control???? What I want to do is when the user press "enter" key in the edit box it will checks to see if the password entered is it correct or not!!!!
Any Help with these 2 problems????
THANKS FOR THE HELPER!~!!!!
|
|
|
|
|
You need to override PreTranslateMessage for your dialog, then when you recieve a WM_KEYDOWN message that is VK_RETURN, check to see if the window handle of the message is equal to the window handle of the edit box, if so handle the message, otherwise pass it on to the base class.
|
|
|
|
|
You can use this metod:
dlg.h file add:
virtual void OnOK();
dlg.cpp file add:
void CDlg::OnOK()
{
// TODO: Add extra validation here
////CDialog::OnOK(); nothing do if Enter press
}
OlegO
|
|
|
|
|
Hi,
I think the solution for both problems is to override the
"OnOK" handler of the dialog:
void MyDialog::OnOK()
{
UpdateData( TRUE );
if( m_sPassword != "PASSWORD" )
{
AfxMessageBox( "Wrong Password" );
return;
}
CDialog::OnOK();
}
Best regards
Holger
|
|
|
|
|
I have already created a Tab control on a Dialog window with 3 tab on it!!! But I don't know how can I display a dialog on it!!! Any Help??
Thanks
|
|
|
|
|
Exclamation points simply make you appear silly.
You need to create your dialogs and show them when the proper tab is selected.
|
|
|
|
|
Jeff Prosise wrote an article called “Wicked Code” for MSDN Magazine on this topic. Go to http://msdn.microsoft.com/library/period00/wicked0600.htm to see it.
|
|
|
|
|
Greetings. Thank you for reading my post.
I have a piece of equipment that I have controlled through the parrellel port of a PC with a utility I wrote in C under DOS. I used the "biosprint" function.
Under Visual C++, I am getting conflicting information on whether the _outpw function, which is supposed to work like biosprint, is supported. In any case, I can't get it to work.
How would you send a simple integer to a printer port? (I am not writing to a file - and I am not sending charactors, just data).
Thanks ahead of time for suggestions. Much appreciated.
|
|
|
|
|
Hello! I'm trying to make a class that uses the Windows multimedia timer services. The function to start a timer is this one: (Microsoft's timer function)
MMRESULT timeSetEvent(
UINT uDelay, /*How often the timed event should occur, in milliseconds.*/
UINT uResolution, /*accuracy of the Timer*/
LPTIMECALLBACK lpTimeProc, /*pointer to the CALLBACK funtion*/
DWORD dwUser, /*user-defined data*/
UINT fuEvent /*event type*/
)
The name of my multimedia timer class is CMMTimer. Its function to start a timer is called Start, and it used all the same arguments as timeSetEvent above.
I also have a dialog-based MFC program, and the CDialog-derived class is called CDlgTest. This class also contains an instance of the class CMMTimer, called m_Timer.
How can I make a member function in CDlgTest, and send the address of this function to the lpTimeProc variable of m_Timer?
Any help would greatly be appreciated.
C. Hampton
|
|
|
|
|
Hi C.,
One possible solution is:
- make a static member function in CDlgTest and pass its address to CMMTimer::Start() function
- use the dwUser argument to pass a pointer to the dialog itself
- in the static function call a non-static function using the dwUser argument
Obviously do this only if you need to. If you're not using member variables in your TimeProc you don't need to use the dwUser argument that way.
Your code could be like this:
static void CALLBACK MyTimeProc(UINT uID, UINT Msg, DWORD dwUser, DWORD dw1, DWORD dw2);
void CALLBACK CTestDlg::MyTimeProc(UINT uID, UINT Msg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
CTestDlg* me = (CTestDlg*)dwUser;
me->WhateverYouLike();
}
m_timer.Start(delay, res, MyTimeProc, (DWORD)this, event);
Hope this helps,
Paolo.
|
|
|
|
|
Hello fellow developers,
Please help me diagnose why this piece of code crashes my simple MFC Dialog based application. Essentially this code is supposed to retrieve the SID of the currently logged in user. When I pass through debugger I do see the SID being retrieved properly, SID also passes the IsValisSid() API call and all return codes tally. However, after passing through this code segment, the memory gets corrupted (m_hWnd = ??? among other things) and the app crashes. Stack trace is leading me no where. Please let me know what might be wrong, or what else I can do to figure out the problem or if there is a better way of doing this in the first place.
Many thanks.
Sai
#define SIDS 1
#if SIDS // USER NAME START
SID userSID ;//NULL;
DWORD cbUserSID = 0;
char *szDomain = NULL;
DWORD cbDomain = 0;
PSID_NAME_USE peUse = NULL;
SID_NAME_USE tSnu;
BOOL fAPISuccess = FALSE;
char *szUserName = NULL;
DWORD cbUserName = 0;
fAPISuccess = GetUserName(szUserName, &cbUserName);
// API should have failed with insufficient buffer.
if (fAPISuccess)
{
return;
}
else if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
printf("GetUserName() failed. Error %d\n", GetLastError());
return;
}
szUserName = new char[cbUserName];
if (!szUserName)
{
printf("HeapAlloc() failed. Error %d\n", GetLastError());
return;
}
fAPISuccess = GetUserName(szUserName, &cbUserName);
if (!fAPISuccess)
{
printf("GetUserName() failed. Error %d\n", GetLastError());
return;
}
// STEP 2: Get SID for current user.
//
fAPISuccess = LookupAccountName((LPSTR) NULL, szUserName,
&userSID, &cbUserSID, szDomain, &cbDomain, peUse);
// API should have failed with insufficient buffer.
if (fAPISuccess)
{
return;
}
else if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
printf("LookupAccountName() failed. Error %d\n",
GetLastError());
return;
}
szDomain = new char[cbDomain];
if (!szDomain)
{
printf("HeapAlloc() failed. Error %d\n", GetLastError());
return;
}
fAPISuccess = LookupAccountName((LPSTR) NULL, szUserName,
&userSID, &cbUserSID, szDomain, &cbDomain, &tSnu);
if (!fAPISuccess)
{
printf("LookupAccountName() failed. Error %d\n",
GetLastError());
return;
}
if (szUserName)
{
delete szUserName;
}
if (szDomain)
{
delete szDomain;
}
if(IsValidSid(&userSID))
{
m_pSid = &userSID;
}
#endif // USER NAME END
|
|
|
|
|
Hi,
I created this service and it´s used to create,destroy and to keep track of created processes. It receives a commando via sockets and executes it. This socketcommunication works fine. But it also starts other processes that want to communicate with a servlet via a socket. Rather complicated solution but it has it reasons. Anyway this other socketcommunication don´t work. It connects but the data that we want to send isn´t received on the other side of the channel.
It works when I debug the service, but when I install it as a service it don´t work.
I've tried to change the service "Log on as" to my account.
Did not work.
Hoping for answer.
Andreas
|
|
|
|
|
Hi there,
I am having problems creating Type Libraries (TBLs) out of an IDL-file using the MIDL-compiler shipped with Visual C++ 6.0 professional edition (no service packs).
I have a lot of IDL-files where several COM-interfaces are declared in. Then I have one IDL-file where I create a library:
...
[
uuid(...),
version(1.0),
helpstring("...")
]
library XyzObjects {
importlib("stdole32.tlb");
And then I import all the IDL-files containing the interface declarations. Before closing the library block, I declare all the interfaces, I would like to have in the resulting type library the way
import "interface1.idl";
import "interface2.idl";
...
interface IInterface1;
interface IInterface2;
...
}
where "interface1.idl" contains the declaration of "IInterface1"...
The problem is, that the resulting TBL does not contain *all* interfaces declared that way and there is really no reason why. I.e. there is an idl-file which contains two interface declarations. I am importing this one inside of the library block and declaring both interfaces after that, but, though the midl-compiler does not bring up any errors, there is only one of the both interfaces in the resulting TBL.
Does someone know this problem? Does someone know the solution?
Regards...
Sven
|
|
|
|
|
I have recently been developing a class that needs to provide Listbox funtionality as a view. I initially created a CListbox derived class that supplies the needed owner draw implementation. Then I created a CView derived class, say CMyView, that, in turn, creates an instance of the ownerdraw listbox in its OnCreate(...) member. The CMyView::OnSize(...) member then sizes the ownerdraw listbox so that it occupies the entire CMyView client rect.
This implementation works fine, but it is my understanding that the CCtrlView class provides the functionality needed to use just about any control as a view. I have had some success in getting a CCtrlView derived view class that behaves as a listbox to work properly. However, I am unable to get the CCtrlView derived view class to receive the WM_DRAWITEM and WM_MEASUREITEM messages necessary for performing the owner draw tasks associated with the listbox.
If anyone knows how this task can be accomplished, please let me know.
|
|
|
|
|
How create transparency window, with posible size and move.
OlegO
|
|
|
|
|
Can somebody show me how to use the tool tip control in a dialog app? Could Microsoft have made this any harder?
|
|
|
|
|
Create a member function in your head file...
CToolTipCtrl m_ToolTips;
then.....
BOOL CJVFAccessDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
switch(pMsg->message)
{
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MOUSEMOVE:
m_ToolTips.RelayEvent(pMsg);
}
return cdxCSizingDialog::PreTranslateMessage(pMsg);
}
BOOL CJVFAccessDlg::OnInitDialog()
{
m_ToolTips.Create(this);
m_ToolTips.SetDelayTime(200);
m_ToolTips.SetDelayTime(TTDT_AUTOPOP, 50000);
m_ToolTips.SetMaxTipWidth(200);
m_ToolTips.AddTool(GetDlgItem(IDD_REPORTS), winmesgs[7]);
m_ToolTips.AddTool(GetDlgItem(IDD_PERSONNEL), winmesgs[8]);
:
:
etc etc etc
return TRUE;
}
|
|
|
|
|
There are two MSDN documents that cover this:
"How to Add Tooltips for Controls to an MFC Modal Dialog Box"
(on the CD set)
- and -
"Tiptoe Through the ToolTips With Our All-Encompassing ToolTip Programmer's Guide"
(http://msdn.microsoft.com/library/periodic/period97/S245A9.htm)
Also, it is a good idea to put in an option to turn off tooltips in your dialog boxes. They can get annoying once you are familiar with using the application.
Good Luck
Jonathan Craig
|
|
|
|
|
Hi:
I am looking for the example source code for the Common Internet File System on the server and client site.
Can anybody tell me where to find it?
Thanks a lot....^_^
|
|
|
|
|
I recently have diffculty of using the Tab control!!! Anyone can help me out?? Thanks~!~
|
|
|
|
|
The number of pages to print from my document can vary from 4 to 10 pages. The printwork consist in a cover page as first page followed by 3 to 9 data pages. Each data page has a header and footer line. I correct the m_rectDraw in the pInfo structure for this header and footer line as indicated in the Scribble tutorial or by Prosise and Kruglinsky in their books. Printing is done in mapping mode MM_TEXT. With my "old" HP600 inktjet printer printing works fine and even the print preview works fine. But printing goes wrong on a HP Laserwriter, HP 1600CM inktjet printer and Lexmark OptraE laser printer on starting the 3rd page this is the 2nd data page,if the document has more than 7 data pages in a lane. How can I solve this problem ?
|
|
|
|
|
Here is some code I used for printing multi-page documents. It doesn't use the m_rectDraw for calculating the number of pages. It gets a printer device context from the current selected printer. Then calls GetDeviceCaps(HORZRES) and GetDeviceCaps(VERTRES) to get the printer page size.
BOOL CInfoWindowView::OnPreparePrinting(CPrintInfo* pInfo)
{
pInfo->SetMaxPage(GetNumberOfPrintPages(pInfo));
// default preparation
return DoPreparePrinting(pInfo);
}
WORD CInfoWindowView::GetNumberOfPrintPages(CPrintInfo* /*pInfo*/)
{
PRINTDLG PrtDlg;
HDC hDC;
//// Create a printer DC
if(!AfxGetApp()->GetPrinterDeviceDefaults(&PrtDlg))
{
TRACE("No default printer.\n");
// use screen DC for calculations
// It's OK to do this because this CDC will not be used for any
// output.
hDC = ::CreateDC("display",NULL,NULL,NULL);
}
else
{
CPrintDialog dlg(FALSE);
dlg.m_pd.hDevMode = PrtDlg.hDevMode;
dlg.m_pd.hDevNames = PrtDlg.hDevNames;
hDC = dlg.CreatePrinterDC();
}
CDC* pDC = CDC::FromHandle(hDC);
// This is a printer DC, so set m_bPrinting
// this is necessary so CScrollView::OnPrepareDC won't modify the
// ViewportOrg, and cause LPtoDP to return an inappropriate result.
pDC->m_bPrinting = TRUE;
//// Calculate print stuff.
CFont font;
CFont *pOldFont;
CSize size;
CInfoWindowDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
//Setup the font.
font.CreatePointFont(INFO_WINDOW_FONT_SIZE, INFO_WINDOW_FONT_FACE, pDC);
pOldFont = pDC->SelectObject(&font);
size = pDC->GetTextExtent("X");
//// Get the printer page sizeS.
LONG lHeaderHeight;
LONG lFooterHeight;
LONG lPageWidth, lPageHeight;
lPageWidth = pDC->GetDeviceCaps(HORZRES);
lPageHeight = pDC->GetDeviceCaps(VERTRES);
//Header height is 4 lines.
lHeaderHeight = size.cy * 4;
//Footer height is 2 lines.
lFooterHeight = size.cy * 2;
//Set header, page, and footer rects.
m_rectPrintHeader.SetRect(0, 0, lPageWidth, lHeaderHeight);
//Print area for info.
m_rectPrintPage.SetRect(0, m_rectPrintHeader.bottom,
lPageWidth, m_rectPrintHeader.bottom +
(lPageHeight - (lHeaderHeight + lFooterHeight)));
//Footer area.
m_rectPrintFooter.SetRect(0, m_rectPrintPage.bottom,
lPageWidth, lPageHeight);
(size.cy * 1));
//Calculate other stuff.
m_wLinesPerPrinterPage = WORD(m_rectPrintPage.Height() / size.cy);
m_wPrinterPages = (WORD)ceil((double)pDoc->GetNumberOfTextLines() / m_wLinesPerPrinterPage);
m_wPrinterPages = (WORD)__max(m_wPrinterPages, 1);
//// Clean up.
pDC->SelectObject(pOldFont);
pDC->DeleteDC();
return m_wPrinterPages;
}
I hope this helps.
Jonathan Craig
|
|
|
|
|
Here you will find how I finally solved the problem. I thank Jonathan for his kind suggestion not to rely on the m_rectDraw in the CInfo structure. But even this does not solve the problem but it helps to have more consistent printwork between different printers.
I found a go around the problem by splitting the document in a view with, in my case, three sections as to keep the total number of pages under 8 pages for wich the standard MFC print functions work fine.
|
|
|
|
|
I have an application with more then 400 strings in the string table. Every time the string table grows over a certain number of strings, one of the strings of the string table appears in the alert message boxes instead of the system string to prompt when you have to save to file on closing a window or other error message box. Unwanted parts of a string from the string table apperas as caption in buttons on the print preview window. It seems that something goes wrong in the text segment and the string table overwrites some system strings. How can this be avoided or what I am doing wrong ?
|
|
|
|
|
So far I did'nt receive any reaction on my question. Are you all developing applications with low number of strings in the string table or are you not using the string table at all? I try to explain my problem on another way. What could be the reason when a string or parts from a string from the string table appears unwanted in a message box in stead of a system string, or on a static control or in a button caption as in the print preview ?
|
|
|
|
|