|
I've used 2 different approaches:
1. Define a static class called CGlobal and define it with static variables and functions.
2. Make it a member of your Application class and use theApp.m_connectionstring
My articles
BlackDice
|
|
|
|
|
I tend to put them in stdafx.cpp, and extern them in stdafx.h.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
sdancer75 wrote: Is there any way in MFC to have global variables ? I need this, for example to have access to a database connection string, from anywhere in the program not only in the Document/View but in the Dialogs too.
I believe in making Singleton class and use it object in while application!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
my app send 1 byte (value='11111111') to LPT1. In one PC (Win2K-PRO) I see value:'11111111' but in other PC I see value:'00111111', pin D7,D6 always is '0'.
Why ? How to set LPT ?
|
|
|
|
|
To input using the data byte (pins 2-9), the port should be configured as bi-directional; i.e, can input and output on the same pins. There is a bit in I believe (forgot the address, either 0x379, or 0x37A), which needs to be set to input data from the port, instead of the usual output.
If you have already made it bi-directional, then there is something wrong with the wiring, or the port, or it is something else.
this is this.
|
|
|
|
|
Outport(0x378,ch) that is ok, but Inport(0x378) always give last value, that was Outport before.
- How to read data in ?
|
|
|
|
|
Hi all,
I am looking for an advice how to write data into exactly location in a file name in MFC VC++ 2003. I have sections as [DDS] and [DC offset].
I know how to iplement it in builder c++ 6, but I failed in MFC VC++ 2003 (it is hard to me). Where I can get info. Thanks.
Editbox1 contains 10 which is written in to section [DDS] with ID (Start Freq)
ex: myfile.ini contains
[DDS]
Start Freq : 10 ;Mhz comment
Stop Freq : 25 ;Mhz
Step : 1 ;Khz
[DC offset]
I : 220
Q : 245
MilkyWay
|
|
|
|
|
Loc Milkyway wrote: I am looking for an advice how to write data into exactly location in a file name in MFC VC++ 2003. I have sections as [DDS] and [DC offset].
What about this class :-
http://www.codeproject.com/cpp/CIni.asp#xx660934xx[^]
Anyways
Loc Milkyway wrote: [DC offset]
I : 220
Q : 245
Ini generally contain = (Equal to Sign) to seperate key and value instead of : (Colon)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Thank you for advice. The class and demo are good. But I don't know how to use GetInt(...). I made a simple GUI with 1 button and i edit box, when button is clicked, the key value should be displayed on edit box. But default value is displayed. Something is wrong I could not figure out.
Here is my
ini file contains
[SECTION1]
Key1 = String
Key2 = 14
[SECTION2]
Key1 = 20.5
Key2 = a
simple GUI contains
void CsimpleINIfileTestDlg::OnBnClickedButton4()//open file
{
CString Str; //ok here
Str = "3"; //ok here
m_ebSECT1KEY2.SetWindowText(Str); //ok here - 3 is displayed on edit box
CFileDialogEx dlg(TRUE, _T("ini"), NULL, /*OFN_HIDEREADONLY | */ OFN_OVERWRITEPROMPT,
_T("Ini Files (*.ini)|*.ini|All Files (*.*)|*.*||"),
this);
if (dlg.DoModal() == IDOK)
char m_sSectionX[]= "SECTION1";
char m_sKEYX[] = "KEY2";
Str.Format(_T("%d \n"), m_ini.GetInt(m_sSectionX , m_sKEYX, 7, BASE_DECIMAL));
m_ebSECT1KEY2.SetWindowText(Str);
/* always get value 7 - result as 4 above lines
CString m_sSection = _T("SECTION1"); //m_sSection will be destroyed by next line CString m_sKEY = _T("KEY2");
CString m_sKEY = _T("KEY2");
Str.Format(_T("%d \n"), m_ini.GetInt(_T("SECTION1"), _T("KEY2"), 7, BASE_DECIMAL));
m_ebSECT1KEY2.SetWindowText(Str);
*/
}
MilkyWay
|
|
|
|
|
Loc Milkyway wrote: CFileDialogEx dlg(TRUE, _T("ini"), NULL, /*OFN_HIDEREADONLY | */ OFN_OVERWRITEPROMPT,
_T("Ini Files (*.ini)|*.ini|All Files (*.*)|*.*||"),
this);
if (dlg.DoModal() == IDOK)
Problem Lies here, you forget to set path of selected Ini file.
m_ini.SetPathName(dlg.GetPathName());
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Good advice my dear.
MilkyWay
|
|
|
|
|
Hi all,
Do you know how to simulate a left button mouse click on another application ? (use SendMessage api ?)
Thanks,
ken
|
|
|
|
|
You will need the HWND of the window to which you want to send the mouse-click. Actually it is the WM_LBUTTONDOWN and WM_LBUTTONUP messages which need to be sent.
You can:
::SendMessage(hWnd,WM_LBUTTONDOWN,0,MAKELPARAM( x, y ));<br />
::SendMessage(hWnd,WM_LBUTTONUP,0,MAKELPARAM( x, y ));
It seems that the toolbars, menus, caption bars etc do not respond to this technique, however I am not sure.
this is this.
|
|
|
|
|
kendao wrote: Do you know how to simulate a left button mouse click on another application ? (use SendMessage api ?)
Better Use mouse_event Function or SendInput function for Simulating mouse on your or other window
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
hi, How a window exract text from another window(eg: MSWord,Excel..).Is there any API to exract text. Or there is any other way to exract. If any one has answer please help me.
For eg: Capturing tools like SnagIt captures from different window. I want to know how do these capturing tools like SnagIt do it.
Jewel Nandy,
Mumbai,India
|
|
|
|
|
Try FindWindowEx() to find the main window, then use it again passing the main window as the parent, and it will go through the child windows one at a time. Maybe that'll be a start. I think the first time you have to pass a null as the parent window's handle and just specify the window caption.
My articles
BlackDice
|
|
|
|
|
Jewel Nandy wrote: How a window exract text from another window(eg: MSWord,Excel..).Is there any API to exract text. Or there is any other way to exract. If any one has answer please help me.
Have a look at this article :-
http://www.codeproject.com/threads/winspy.asp[^]
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Hi,
I speak of the class std::queue / #include <queue>
In my case the question is:
1. Is it safe to execute m_queue.push from thread A,
while thread B executes m_queue.pop ?
2. Is it safe to execute m_queue.push from thread A,
while thread B executes m_queue.empty ?
3. Is it safe to execute m_queue.push from thread A and also from thread B?
I hope you understand what i mean,
thanks in advance
Snow.
|
|
|
|
|
None of the STL objects are thread safe. Wrap the calls in critical sections.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Thanks for your answer Tim.
I found an MSDN article "Thread Safety in the Standard C++ Library" which statet that some of the STL
container classes are threadsafe (but only in certain cases). But I think it will be better to write a wrapper for the queue class as you wrote before. It seems to be the only way to be on the safe side.
Thanks,
Snow.
|
|
|
|
|
I have on my form one Clist Control And One Button so that when I click on it, I see my data.
But my problem is this, every time I click on this button, the number of columns on my CList control is increasing. How can I avoid this problem
I learn my self
|
|
|
|
|
You probably keep inserting the column over and over again.
You need to completely clear out the control, or else set up the columns in OnInitDialog and don't keep adding the columns over again. You can add data items to the existing columns separately - when your button is pressed.
|
|
|
|
|
|
Dear ALL,
I would like to add a menu to my starting dialog window using WinAPI (I know how to do it with MFC). The code until now looks like I attached it at the end of the message.
But I dont know how to modify the "DialogBox(hInstance,MAKEINTRESOURCE
(IDD_MAIN), NULL, DlgProc);" - command to make it include my menu "IDR_MENU1" from the "resource.h"-file also.
Thanks for your comments.
FRANK REICH
<br />
#include <windows.h><br />
<br />
#include "resource.h" <br />
<br />
HBRUSH g_hbrBackground = NULL;<br />
<br />
BOOL CALLBACK DlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)<br />
{<br />
switch(Message)<br />
{<br />
case WM_INITDIALOG:<br />
g_hbrBackground = CreateSolidBrush(RGB(180, 180, 180));<br />
<br />
SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(NULL, <br />
MAKEINTRESOURCE(IDI_APPLICATION)));<br />
SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(NULL, <br />
MAKEINTRESOURCE(IDI_APPLICATION)));<br />
break;<br />
<br />
case WM_CLOSE:<br />
EndDialog(hwnd, 0);<br />
break;<br />
<br />
case WM_CTLCOLORDLG: <br />
return (LONG)g_hbrBackground;<br />
<br />
case WM_CTLCOLORSTATIC:<br />
{<br />
HDC hdcStatic = (HDC)wParam;<br />
SetTextColor(hdcStatic, RGB(255, 255, 255));<br />
SetBkMode(hdcStatic, TRANSPARENT);<br />
return (LONG)g_hbrBackground;<br />
}<br />
break;<br />
case WM_COMMAND:<br />
switch(LOWORD(wParam))<br />
{<br />
case IDOK:<br />
EndDialog(hwnd, 0);<br />
break;<br />
<br />
case IDCANCEL:<br />
EndDialog(hwnd, 0);<br />
break;<br />
}<br />
break;<br />
case WM_DESTROY:<br />
DeleteObject(g_hbrBackground);<br />
break;<br />
default:<br />
return FALSE;<br />
}<br />
return TRUE;<br />
}<br />
<br />
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,<br />
LPSTR lpCmdLine, int nCmdShow)<br />
{<br />
return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc);<br />
}<br />
|
|
|
|
|
Frank Reich wrote: would like to add a menu to my starting dialog window using WinAPI (I know how to do it with MFC). The code until now looks like I attached it at the end of the message.
But I dont know how to modify the "DialogBox(hInstance,MAKEINTRESOURCE
(IDD_MAIN), NULL, DlgProc);" - command to make it include my menu "IDR_MENU1" from the "resource.h"-file also
Attach the Menu Directly to the Dialog Box.. you will option of that on right clicking on the dialog box resource
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|