|
code an algorithm on your own, I've never heard of any other way.
Don't try it, just do it!
|
|
|
|
|
HOW I CAN HIDE MY FIRST DIALOG IN A MFC APP?
|
|
|
|
|
You can hide any window using ShowWindow(SW_HIDE)
MSN Messenger.
prakashnadar@msn.com
"If history isn't good, just burn it." - Sidhuism.
|
|
|
|
|
Hi,
I am working with the MFC which is connected to the database using recordset. However, I currently encounter some problem. Let me explain further what this program is abt.
For this program that i am working on now, i have an update button. Also, there are 3 parameters which i want to keep changing the values on its own once the update button is being clicked. This might need to use "while loop" and i would like to change the values between the range of 1 to 5 only. This looping will only stop when i click the close on the window itself.
However, the problem now is that i need to change the values when i input it myself and press the update button before it can be stored inside the database.
So i am hoping that anyone who knows how to get this thing workin to give me some ideas on how to go abt doin this.
Thanks
|
|
|
|
|
The solution is very simple: THREADS (it's easy too )
I give the sample code in Windows API. I m sure u can port it to MFC. I have given MFC portions that i can predict(lol, i dont know much MFC).
//First of all this is the thread which will continiously update ur value when update button is clicked.
<small>
HANDLE hthread; <small>
int idThread; <small>
DWORD WINAPI UpdateThread(LPVOID lpParameter)<br />
{<br />
while(1) <small>
{<br />
<small>
}<br />
} //
This function is called when Update Button is clicked(name it according to ur program)
OnUpdateButtonClick()<br />
{<br />
<small>
hThread=CreateThread(NULL,0,UpdateThread,0,0,&idThread);<br />
<small>
} Now thread executes repeatedly irrespective of ur main program code.
We want to stop the thread when STOP button is clicked. So we write the following code:
OnStopButtonClick()<br />
{<br />
<small>
TerminateThread(hThread,0)<br />
<small>
}
I think, this will solve ur problem, ask if u have any doubts.
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|
|
Hi hi,
Thanks for the codings that is provided. Much appreciated. However, i am unfamiliar with using THREADS. But will give it a try on the codings that you provided. In the meantime, is there any other solution to this problem??
Thanks lots
|
|
|
|
|
Hey, i've got another solution for u (that too WITHOUT threads )
//----------make a global var----------
//glo can take two values>>
//0:do nohting; 1:update the values; int glo=0;
DO idle-time processing- i think the function is OnIdle() for CwinApp (i'm not sure about MFC, find it urself)
The OnIdle function is executed when ur window doesnt receive any key input.
OnIdle is executed all time but it will update ur values only when glo is 1.
The following code will ensure this:
CWinApp::OnIdle()<br />
{<br />
if(glo==0)<br />
;
else if(glo==1)<br />
{<br />
}<br />
}
Inside Update Button click function, all u have to do is to set the value of glo to 1.
//---------Update button click rotine-----
OnUpdateClick()<br />
{<br />
glo=1;<br />
}
Inside Stop Button click function, all u have to do is to reset the value of glo to 0. This will stop the update.(;))
//---------Update button click rotine-----
OnStopClick()<br />
{<br />
glo=0;<br />
<br />
}
Thats allllllll...........
...Avenger
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|
|
Hi,
For this thread function, i have some doubts which i have stated below. Can kindly explain to me? Thanks
For this function that you have stated:
DWORD WINAPI UpdateThread(LPVOID lpParameter)
I just need to copy down or do i have to state any values to the lpParameter?
Here, i have also attached part of the codings that i have done, but i have tried the methods that you have given but it dun seems to work the way as you state. The coding stated below, the while loop is working and the database will be updated on click the UpdateDB. however, once i click on the update button, the whole program seems to hang.
<br />
int check_exit=0;<br />
<br />
void CUpdateView::OnUpdatedb() <br />
{<br />
<br />
CUpdateDoc* pDoc = GetDocument();<br />
UseRecordset* pUseRecordset = &pDoc->m_UseRecordset;<br />
int x = 5;<br />
do<br />
{<br />
pUseRecordset->Edit();<br />
<br />
pUseRecordset->m_propatime = m_propagation*x;<br />
<br />
pUseRecordset->Update();<br />
<br />
if (check_exit = 0)<br />
check_exit=1; <br />
}while(check_exit!=1);<br />
<br />
}<br />
<br />
void CUpdateView::OnExit() <br />
{<br />
check_exit = 0;<br />
}
Thanks a million,
dreamerzz
|
|
|
|
|
if (check_exit = 0)
If this is what you have coded, then change it to:
if (check_exit == 0)
LOOK CLOSE AT UR PROGRAM, it doesnt come out of the do-while loop
Well, if you have written that by mistake and are actually using if (check_exit == 0) then your program is hanging because it keeps looping inside the do-while LOOP. ACTUALLY UR PROGRAM APPEARS TO HANG(loops & loops and loops) AS IT DOESNT RETURN CONTROL BACK TO WINDOWS(ur main program), so you can no longer interact with any other buttons.
The trick is to run a continious LOOPING do-while LOOP, but we want it to run seperately from our main program. HERE COMES THE THREAD:::>>>
int loop=1;
DWORD WINAPI UpdateThread(LPVOID lpParameter)
{
CUpdateDoc* pDoc = GetDocument();
UseRecordset* pUseRecordset = &pDoc->m_UseRecordset;
int x = 5;
while(loop==1)
{
pUseRecordset->Edit();
pUseRecordset->m_propatime = m_propagation*x;
pUseRecordset->Update();
}
}
THE ABOVE FUNCTION DOES NOTHING. IT DOESNOT START A NEW THREAD. It is like any ordinary function function defination. Its has to be called from somewhere to make it execute. BUT UNLIKE ORDINARY FUNTIONS, we will not call UpdateThread(<<something>>) as it will not start a new thread.
And the name "UpdateThread" is purely arbitrary. You can name the thread as "dreamerzz Thread()" or "CrapThread()" or "BoomBoom()" or whatever you want.
Now, we want this thread to start when we click Update buttom. so, we write::>>>
HANDLE hthread;
int idThread;
void CUpdateView::OnUpdatedb()
{
hThread=CreateThread(NULL,0,UpdateThread,0,0,&idThread);
}
You dont have to explicitly end the thread as it will automatically terminate when the value of "loop" becomes 0. (To explicitly terminate a thread you can use the function TerminateThread(hThread,0); )
void CUpdateView::OnExit()
{
loop = 0;
}
Ask if u have doubts
...Avenger
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|
|
Hi,
Thanks for the help given.;)
dReaMerzZ
|
|
|
|
|
BOOL CTest02Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
|
|
|
|
|
Normally, when a dialog opens, Windows will set the focus to the first control in the dialog in the tab order. You can override this behavior in OnInitDialog() by setting the focus yourself to some other control. If you return FALSE from OnInitDialog() , Windows assumes that you've set the focus to the control you want, and it will not set the focus as it usually does. Return TRUE to get the normal behavior.
Software Zen: delete this;
|
|
|
|
|
Hi,
Can anyone equivalent APIs of GetNetworkParams & GetAdaptersInfo to work on Windows NT 4.0.
Thanks,
|
|
|
|
|
Hi, I'm working on an app using a view class based on CScrollView. As the doc is BIG, I've hit the 32768 'limit' of SetScrollSizes(). I'm sure I remember seeing an article on CP about getting around this problem, but can I find it ?? Can someone point me in the right direction please !! ?
Doug
|
|
|
|
|
Use SetScrollInfo instead.
Software Zen: delete this;
|
|
|
|
|
Hi Gary, Yes, I've just stumbled over that and am now over the problem. Thanks, Doug
Doug
|
|
|
|
|
Can someone please explain 1) the effect of "op" in each of these three map initializations below, 2)why op needs to be a class or struct as an overloaded () operator , and 3) why when I use #3 I loose the ability to access an element using map[key], such as ++map[key]. Thanks!
1) map<key, elem,="" op=""> m;
2) map<key, elem=""> m(op);
3) map<key, elem,="" op=""> m(op);
Where I've seen these for reference:
1) The C++ Standard Library, page 196.
2) Accelerated C++, page 137.
3) Accelerated C++, page 321.
Matthew
|
|
|
|
|
Sorry, the examples didn't print out right:
1) map<key, elem, op> m;
2) map<key, elem> m(op);
3) map<key, elem, op> m(op);
Matthew
|
|
|
|
|
how to make button control colorful .
|
|
|
|
|
MSDN Documentation states:
Buttons with the BS_PUSHBUTTON, BS_DEFPUSHBUTTON, or BS_PUSHLIKE styles do not use the returned brush. Buttons with these styles are always drawn with the default system colors. Drawing push buttons requires several different brushes-face, highlight and shadow-but the WM_CTLCOLORBTN message allows only one brush to be returned. To provide a custom appearance for push buttons, use an owner-drawn button.
Gurmeet S. Kochar
If you believe in God, it's because of the Devil
|
|
|
|
|
is this[^] color full enough
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
so far i am able to convert HWND to string but i am not able to find a way to convert string to HWND .
There is a way to convert hex string to int but not hex.
so either someone tell me int to hex conversion or direct string to hex.
Unmanaged in a .NET world
|
|
|
|
|
string sApple = "463A";
long lNum;
char* pE;
lNum = strtol(sApple.c_str(), &pE, 16);
printf("0x%X\n", lNum);
HWND hW = (HWND)lNum;
<b>Maxwell Chen</b>
|
|
|
|
|
Thanx very much , it really worked , thanx
Unmanaged in a .NET world
|
|
|
|
|
hi all,
I would like my dialog-based app to pop up a message box right after the dialog itself is shown on the screen... anyone knows how to do that?
If I put a message box in my dialog's OnInitDialog like this:
BOOL CTestDlg::OnInitDialog()<br />
{<br />
CDialog::OnInitDialog();<br />
......<br />
AfxMessageBox("hello"); <br />
return TRUE;
}
the message box pops up before the main dialog appears, but I want the message box to pop up AFTER the main dialog appears. I've tried handling WM_SHOWWINDOW message, i.e., put the AfxMessageBox in the dialog's OnShowWindow() function, but it was the same thing as putting the AfxMessageBox in OnInitDialog() -- the message box still pops up before the main dialog appears.
Thanks for your help in advance
|
|
|
|
|