|
One possible reason of many is that in the original (vc++ 6) structured exception handling was enabled and now it isn't. This would mean that divide by 0 exceptions were being thrown but not being caught (possibly). Now they are just crashing the program.
Unhandled divide by zero is bad so don't worry about why it did/did not. Just fix the problem now. Structured exception handling is a very good way of doing that.
Peter Wasser
"The whole problem with the world is that fools and fanatics are always so certain of themselves, and wiser people so full of doubts." - Bertrand Russell
|
|
|
|
|
Hello there,
I am using CDHtmlDialog in my MFC application to create a UI with HTML, CSS & JavaScript.
In my project there's one dialog created from CDHtmlDialog and a corresponding HTML file for that dialog.
Now during run time i want to change the contents of the HTML file.
Not just the HTML part, i want to change the CSS & JavaScript too.
So basically what am trying to do is, change the entire content of the default HTML file.
Is this possible? If yes, how can i do that?
Thanks in advance!
|
|
|
|
|
I have a static control area, it is about 4 lines height.
if I only have one string to display, How can I make it horizontal and vertical center?
Thanks
|
|
|
|
|
|
For the horizontal center, use SS_CENTER, there is not vertical center for CStatic ( or Cedit), you will have to do it manually.
I'd rather be phishing!
|
|
|
|
|
I use \r\n, almost got vertical center effect
|
|
|
|
|
If you want it to be exact then you need to use a different control (possibly a RichEdit) or subclass the label and do your own painting of the text.
|
|
|
|
|
Exactly what Richard said above just subclass a static text box and you can use it over and over again.
I have a standard code I use to do what you are doing and it also allows you to change the font, text color and background color as well which is all fairly trivial.
Let me know if you want to see how to code it as I wont paste that amount of code if you don't need it.
|
|
|
|
|
We have a client-server application developed using MFC. The client-server communication is via TCP/IP sockets within a LAN network.
Now we want to convert this application to a web application. Could you please provide me with any guidelines how to start and proceed.
|
|
|
|
|
|
Yo need to write a web based VM that supports the win32 spi.
"The whole idea that carbon dioxide is the main cause of the recent global warming is based on a guess that was proved false by empirical evidence during the 1990s." climate-models-go-cold
|
|
|
|
|
You would be much better learning ASP.NET and starting from scratch. Converting MFC to ASP.NET would be much more difficult.
|
|
|
|
|
I like the idea of building a web based VM, shouldn't take him more than a few years dint you think?
"The whole idea that carbon dioxide is the main cause of the recent global warming is based on a guess that was proved false by empirical evidence during the 1990s." climate-models-go-cold
|
|
|
|
|
im using visual studio 2010.im new to this.i have a button and a text box. i want to enter a string in the text box.eg:"hello". and if i click the button it should count the number of characters in the string and return the value..eg: in this case "hello" ,when i click the button it should count each letter and display the value "5"(string "hello" contains 5 characters).can any1 help me by sending the exact code?
|
|
|
|
|
Have you looked at the WM_GETTEXTLENGTH message? If you are using MFC, check out GetWindowTextLength().
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
He has to handle WM_COMMAND first.... then the button ID..... then get the window handle to the edit control....
This guy needs to go back and start form scratch and read some books/do some tutorials on Win32/MFC.
"The whole idea that carbon dioxide is the main cause of the recent global warming is based on a guess that was proved false by empirical evidence during the 1990s." climate-models-go-cold
|
|
|
|
|
Ok here is a skeleton program it does a bit more than you asked it deals with resizing the window, closing etc and is really complete enough for you to build on and get the idea.
#include <windows.h>
#include <commctrl.h>
#define IDC_TEXT 100 // Edit box ID
#define IDC_BUTTON 101 // Button ID
#define IDC_ANSWER 102 // Static text box to show answer
LRESULT CALLBACK MainWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_CREATE:
{
CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, TEXT("SOME TEXT HERE"),
ES_LEFT | WS_CHILD | WS_VISIBLE,
0, 0, 0, 0, hWnd, (HMENU)IDC_TEXT, 0, NULL);
CreateWindowEx(0, WC_BUTTON, TEXT("&Count text"),
BS_PUSHBUTTON |
WS_CHILD | WS_VISIBLE,
0, 0, 0, 0, hWnd, (HMENU)IDC_BUTTON, 0, NULL);
CreateWindowEx(0, WC_STATIC, TEXT("0"),
SS_LEFT |
WS_CHILD | WS_VISIBLE,
0, 0, 0, 0, hWnd, (HMENU)IDC_ANSWER, 0, NULL);
}
return 0;
case WM_GETMINMAXINFO:
{
LPMINMAXINFO lpInfo = (LPMINMAXINFO)lParam;
if(lpInfo) {
lpInfo->ptMinTrackSize.x = 300;
lpInfo->ptMinTrackSize.y = 300;
};
}
return 0;
case WM_WINDOWPOSCHANGING:
case WM_WINDOWPOSCHANGED:
{
HDWP hDWP;
if(hDWP = BeginDeferWindowPos(3)){
hDWP = DeferWindowPos(hDWP, GetDlgItem(hWnd, IDC_TEXT), NULL,
10, 10, 250, 25, SWP_NOZORDER | SWP_NOREDRAW);
hDWP = DeferWindowPos(hDWP, GetDlgItem(hWnd, IDC_BUTTON), NULL,
10, 40, 80, 25, SWP_NOZORDER | SWP_NOREDRAW);
hDWP = DeferWindowPos(hDWP, GetDlgItem(hWnd, IDC_ANSWER), NULL,
10, 70, 250, 25, SWP_NOZORDER | SWP_NOREDRAW);
EndDeferWindowPos(hDWP);
RedrawWindow(hWnd, NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN |
RDW_ERASE | RDW_NOFRAME | RDW_UPDATENOW);
}
}
return 0;
case WM_COMMAND:
switch (LOWORD(wParam)) {
long Li;
char Buffer[256];
HWND Wnd;
case IDC_BUTTON:
if (HIWORD(wParam) == BN_CLICKED){
Wnd = GetDlgItem(hWnd, IDC_TEXT);
Li = SendMessage(Wnd, WM_GETTEXTLENGTH, 0, 0);
_ltoa_s(Li, &Buffer[0], sizeof(Buffer), 10);
Wnd = GetDlgItem(hWnd, IDC_ANSWER);
SendMessage(Wnd, WM_SETTEXT, 0, (LPARAM)&Buffer[0]);
return (0);
};
break;
};
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, INT nShowCmd)
{
OSVERSIONINFO lpVer;
WNDCLASSEX wcex;
DWORD dwExStyle;
HWND hWnd;
MSG msg;
RECT R;
ZeroMemory(&msg, sizeof(MSG));
ZeroMemory(&wcex, sizeof(WNDCLASSEX));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.hInstance = hInst;
wcex.lpszClassName = TEXT("TESTCLASS");
wcex.lpfnWndProc = MainWindowProc;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wcex.hIconSm = wcex.hIcon;
wcex.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);
if(!RegisterClassEx(&wcex))
return 1;
dwExStyle = WS_EX_APPWINDOW;
lpVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(GetVersionEx(&lpVer) && (lpVer.dwMajorVersion > 5 ||
(lpVer.dwMajorVersion == 5 && lpVer.dwMinorVersion == 1)))
dwExStyle |= WS_EX_COMPOSITED;
GetClientRect(GetDesktopWindow(), &R);
hWnd = CreateWindowEx(dwExStyle, wcex.lpszClassName, TEXT("TEST APPLICATION"),
WS_OVERLAPPEDWINDOW, R.left+20, R.top+20, R.right-R.left-40, R.bottom-R.top-140,
HWND_DESKTOP, NULL, hInst, NULL);
if(hWnd){
ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);
while(GetMessage(&msg, NULL, 0, 0))
{
if(!IsDialogMessage(hWnd, &msg)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
return (int)msg.wParam;
}
modified 22-Apr-14 5:35am.
|
|
|
|
|
Hi,with the following code, I marked 3 statements, with the following statements, nothing on the screen,I mean no "TEST,TEST" string and no black box.
pStatic->GetWindowRect(&rect); ScreenToClient(&rect);
while with
/pStatic->GetClientRect(&rect);
"TEST,TEST",black background box display well.
Is anybody know the reason?
Thanks
void CStaticTextTstDlg::OnPaint()
{
if (IsIconic())
{
...
}
else
{
CDC *pDC = GetDC();
CBitmap memBmp;
CBitmap *pBmpOld;
CDC memDC;
CStatic *pStatic = (CStatic*)GetDlgItem(IDC_STATIC_TXT1);
pStatic->ModifyStyle(0, BS_OWNERDRAW);
CRect rect;
pStatic->GetWindowRect(&rect); ScreenToClient(&rect);
memBmp.CreateCompatibleBitmap(pDC,176,50);
memDC.CreateCompatibleDC(NULL);
pBmpOld = memDC.SelectObject(&memBmp);
memDC.SetTextColor(RGB(0,230,0));
memDC.SetBkMode(TRANSPARENT);
memDC.FillSolidRect(rect.left,rect.top,176,50,RGB(0,0,0));
memDC.DrawText(_T("TEST TEST"),-1,&rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
CPaintDC dc(this);
dc.BitBlt(137,107,176,50,&memDC,rect.left,rect.top,SRCCOPY);
memDC.SelectObject(pBmpOld);
memBmp.DeleteObject();
memDC.DeleteDC();
CDialog::OnPaint();
}
}
Thanks
modified 9-Apr-14 9:20am.
|
|
|
|
|
Message Removed
modified 18-Dec-23 17:47pm.
|
|
|
|
|
GetClientRect returns the area of the drawable area inside the window. It will usually return something like 0,0,width,height in your rect structure
GetWindowRect returns the co-ordinates of the Window itself relative to the upper left of the screen so they will be rather large.
If you try to use GetWindowRect co-ordinates to draw on the window they will be way outside the right and bottom and the drawing wont be visible unless you drag the window right up to the top left off screen.
You need to use GetClientRect co-ordinates to draw with.
Looking at your code I am guessing this line is the problem if you have a position problem
dc.BitBlt(137,107,176,50,&memDC,rect.left,rect.top,SRCCOPY);
Are you sure that is right?
|
|
|
|
|
Hi, in a program, I want to judge if a CDC object is exist, or NULL.
don't know how can I do it.
Thanks in advance for any suggestions
|
|
|
|
|
can I use m_hDC == NULL to decide it?
|
|
|
|
|
In a clean scenario, it should be enough.
Veni, vidi, vici.
|
|
|
|
|
I am kind of not understand what is a clean scenario. did you mean a clean scenario, the m_hDC is NULL?
|
|
|
|
|
For instance, messing MFC with WINAPI is NOT a clean scenario: you could call ::DeleteDC(m_hDC) and then the GDI object would exist no more but m_hDC would be NOT NULL .
Veni, vidi, vici.
|
|
|
|
|