|
I think the easiest way to avoid the details of calculating an appropriate size is to start with
the default font (in a dialog, that's set by the dialog) and adjust the height up or down from
the default.
You can use CWnd::GetFont() and CFont::GetLogFont() to get a LOGFONT for the dialog's font.
Adjust the height in that struct, create the edit control font (using CFont::CreateFontIndirect()
and set the control's font to that font.
Not you need to do this in OnInitDialog() or later since CWnd::GetFont() requires a valid HWND.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
If you just want to change the face color of the button, you can use CTLCOLOR_BTN in OnCtlColor same as that you do for edit control.
- NS -
|
|
|
|
|
In general you can use of these messages:
WM_CTLCOLORBTN for button
WM_CTLCOLORDLG for dialog
WM_CTLCOLOREDIT for edit
WM_CTLCOLORLISTBOX for listbox
WM_CTLCOLORSCROLLBAR for scrollbar
WM_CTLCOLORSTATIC for static control.
|
|
|
|
|
I created a IE browser process using the MFC createprocess function.
Later on in my main program, I want to set focus on and put the IE broswer process as the top window using SetWindowPos function. It tried this and it doesn't work when SetWindowPos is called. If I launch a MS paint program using the same functionality, the SetWindowPos function does bring the MS paint window to the top and with focus.
Here is some sample code.
Create the IE process and get the window handle to it.
HANDLE hProcess = NULL;
PROCESS_INFORMATION processInfo;
STARTUPINFO startupInfo;
::ZeroMemory(&startupInfo, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
if(::CreateProcess("C:\\Program files\\Internet Explorer\\iexplore.exe",
"",
NULL, // process security
NULL, // thread security
FALSE, // no inheritance
0, // no startup flags
NULL, // no special environment
NULL, // default startup directory
&startupInfo,
&processInfo))
{ /* success */
Sleep(1500);
::EnumWindows(&EnumWindowsProc, processInfo.dwThreadId);//Iterate all windows
hProcess = processInfo.hProcess;
} /* success */
int CALLBACK EnumWindowsProc(HWND hwnd, LPARAM param)
{
DWORD pID;
DWORD TpID = GetWindowThreadProcessId(hwnd, &pID);//get process id
if (TpID == (DWORD)param)
{
apphwnd=hwnd;//hwnd is the window handle
return false;
}
return true;
}
// later on in the program I try to bring the window for the IE process on top and into focus
if(apphwnd!=NULL)//check for window handle
{ // window exists already
CString windowText ;
CWnd* window = CWnd::FromHandle(
apphwnd);
if (window != NULL )
{
BOOL res =::SetWindowPos(apphwnd, HWND_TOP, 0, 0, 0, 0,SWP_NOMOVE | SWP_SHOWWINDOW); window->SetFocus();
}
The result of this is the IE window does not get put on top.
I then trie the same code with the MS paint program process (at "C:\\WINDOWS\\system32\\mspaint.exe") and it does work. The window gets put on top. What do I need to do to get IE to respond to my call ?
Stephen Da-Terminator
SCI Solutions
|
|
|
|
|
What happens if you pass the PROCESS_INFORMATION.dwProcessId to EnumWindows() instaed of the thread Id?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for the reply. That didn't work either (same result) but I found out how to make it work. Apparently multiple windows (within IE) had the same processId and I needed to find the main window for IE in order to get the right handle. So it works no with the code below.
Stephen
//Function to enumerate all windows.
int CALLBACK EnumWindowsProc(HWND hwnd, LPARAM param)
{
DWORD pID;
DWORD TpID = GetWindowThreadProcessId(hwnd, &pID);//get process id
if (pID == (DWORD)param)
{
TCHAR windowClass[256];
CString windowText, msg, aclass ;
CWnd* window = CWnd::FromHandle(
hwnd);
if (window != NULL )
{
window->GetWindowText( windowText);
GetClassName(hwnd, windowClass, sizeof(windowClass));
msg.Format(_T("processId %d: windowclass %s: windowtext %s \n"),pID,windowClass, windowText);
TRACE(msg);
}
aclass = windowClass ;
if (apphwnd == NULL && aclass.CompareNoCase("IEFrame") == 0)
{
apphwnd=hwnd;//hwnd is the window handle
apID = pID ;
}
}
return true;
}
Stephen Da-Terminator
SCI Solutions
|
|
|
|
|
i want to pass a struct as the parameter to my thread function.
typedef struct tagTHREADPARMS {
CWnd* pWnd;
CEvent* pKillEvent;
CEvent* pOutputEvent;
CMultithreadingTestDlg* pDlg;//error
} THREADPARMS;
i got plenty of syntax errors, such as:
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
what's the cause?
|
|
|
|
|
Make sure your structure and thread are member of same class or have been declared globally.
I hope you have type casted the pointer to the structure as LPVOID in the CreateThread() or BeginThread()
|
|
|
|
|
yes, they are both declared globally.
is it possible that i'm missing some header file, because the exact same error occured when i declared a CEvent object, however, the error is gone after i include "afxmt.h"
|
|
|
|
|
it seems like if i change CMultithreadingTestDlg* pDlg to CDialog*pDlg, the error is gone...
but i need a pointer to CMultithreadingTestDlg class...
|
|
|
|
|
You just do a forward declaration of CMultithreadingTestDlg, where you declared the structure (if it is in any header file). And in the cpp file you include the header of CMultithreadingTestDlg.
- NS -
|
|
|
|
|
I am coding an application which has a menu and a document. The menu has few radio buttons and check boxes. Based on user selection on the menu, I need to display description of what user's choices mean [few lines of text for each selection] on the document.
I know CEdit class has GetLine() GetLineCount() to get the lines in a multi line document. But how do I display text sequentially on the document using CEdit class?
|
|
|
|
|
I might not get the true meaning of your question, but you can provide the user with 'tool tips' (yellow box with text) to explain what each item does. Would that help with what you are trying to accomplish?
John P.
|
|
|
|
|
You can use SetWindowText . Also you can use ReplaceSel to insert text in the current cursor position if nothing is selected.
|
|
|
|
|
Hi,
I am working on a MDI application. I use CDaoDatabase (so I include AFXDAO.h) for my application. After doing some manipulation wiht the data, I close my dialog box, which has a "Close" button with the ID "IDCANCEL". So, when I close my dialog box, the whole application is getting closed.
But the dialogs which are not using this afxdao.h is working fine. That means, it closes only the dialog and not the application.
Could anyone, please help me in this regard.
PS: I am using VC++ 6.0.
Thanks in advance.
Regards
saravana
|
|
|
|
|
Put a breakpoint on CMainFrame::OnClose()...then in debug mode look at the call stack to understand why you reach that point of the code.
Hope it helps
Russell
|
|
|
|
|
may be the dialog sends PostQuitMessage() , what type of dialog is that and it is dervied from ?
If u can Dream... U can do it
|
|
|
|
|
Hi I'm trying to write a function that will return an array this is what I have
unsigned char sendbuf[6];
sendbuf[0] = myclass::makesendbuffer(SendPacket);
unsigned char myclase::makesendbuffer(Packet SendPacket){
unsigned char sendbuf2[6];
if(SendPacket.data < 0){
SendPacket.data += 65536;
}
sendbuf2[0] = SendPacket.data % 256;
sendbuf2[1] = floor(double(SendPacket.data/256));
sendbuf2[2] = SendPacket.address % 256;
sendbuf2[3] = floor(double(SendPacket.address/256));
sendbuf2[4] = SendPacket.command;
return *sendbuf2;
}
The return is just giving me the value of the first element and everything else is not used. Any ideas of what I'm doing wrong here would be great thanks!
Simon
|
|
|
|
|
simoncoul wrote: return *sendbuf2;
and
simoncoul wrote: unsigned char myclase::makesendbuffer(Packet SendPacket)
the functions needs to return an unsigned char , not a pointer (to an array) ...something could be wrong...
I think that you want to pass all the array...then:
unsigned char* myclase::makesendbuffer(Packet SendPacket)<br />
and then something like
return sendbuf2;
But you can't return a pointer to a local variable if you want that everything runs well....
The solution could be pass to the function a pointer to a vector and fill it inside the function
-- modified at 14:14 Wednesday 8th August, 2007
Russell
|
|
|
|
|
Thanks for the help I got it to work
unsigned char sendbuf[6];
myclass::makesendbuffer(SendPacket, sendbuf);
unsigned char myclase::makesendbuffer(Packet SendPacket, unsigned char sendbuf2[6]){
unsigned char sendbuf2[6];
if(SendPacket.data < 0){
SendPacket.data += 65536;
}
sendbuf2[0] = SendPacket.data % 256;
sendbuf2[1] = floor(double(SendPacket.data/256));
sendbuf2[2] = SendPacket.address % 256;
sendbuf2[3] = floor(double(SendPacket.address/256));
sendbuf2[4] = SendPacket.command;
return sendbuf2;
}
Made much for sense to send a pointer to the array and do stuff to in in the function then what ever I was trying to do!
|
|
|
|
|
And this very code does work as expected?
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
Yeah that code works perfectly, since I'm sending the point of sendbuf, I am able to manipulate it as if it was being declared inside of the function. I dunno if this is the correct C++ way of doing it but it makes sense to me(but I know know C).
|
|
|
|
|
I just asked, because your format of the second parameter is, well, uncommon.
And you are using the identifier sendbuf2 twice.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
simoncoul wrote: I dunno if this is the correct C++ way of doing it but it makes sense to me
hmmm...
Maybe take another look
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
simoncoul wrote: unsigned char myclase::makesendbuffer(Packet SendPacket, unsigned char sendbuf2[6])
{
unsigned char sendbuf2[6];
There's no way you could have gotten this to compile.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|