|
here's some sample code also. I just put this in my OnButton1() function just to demonstrate. but here's a red rectangle being drawn. Of course you would have to put this in your paint event or something like that.
CClientDC dc(this);
CBrush b( RGB(255, 0, 0));
CBrush* pOldBrush = dc.SelectObject(&b);
dc.Rectangle(100,100,110,110);
dc.SelectObject(pOldBrush);
If it's broken, I probably did it
bdiamond
|
|
|
|
|
How to make a non-resizeable window?
|
|
|
|
|
if it's a dialog you should be able to set the appropriate border style property. Or if not, try handling the WM_SIZE (or WM_RESIZE) message so that it calls a this->Move(0,0,100,100) or whatever your original size is, or try handling it so that it does nothing.
If it's broken, I probably did it
bdiamond
|
|
|
|
|
It is SDI application with CFormView. I want to prevent resizing the main window. I tried handling WM_SIZE in CMainFrame and CFormView to do nothing, but it didn't work out. If I put MoveWindow() then the window starts resizeing but when you release a mouse button it goes back. But this solution is not what I wanted.
Is there a parameter that you can pass to Create() so it makes window non-resizeable, or some similar solution?
|
|
|
|
|
Depends on what kind of window library you're using. (MFC? WTL? Raw Win32?)
If you're using the raw Win32 API, you simply set the appropriate window style when calling CreateWindow() or CreateWindowEx(). It's the WS_THICKFRAME style that adds the resizable border, so don't use it. Also don't use WS_TILEDWINDOW or WS_OVERLAPPEDWINDOW, as those styles include use WS_THICKFRAME.
Try (WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU) as your window style. It will probably be exactly what you want.
|
|
|
|
|
It is SDI application with CFormView. I want to prevent resizing the main window. I put parameters you told me for CMainFrame and it worked. Thanx.
|
|
|
|
|
Glad it worked for you.
|
|
|
|
|
Try handling the WM_SIZING message.
...Plug & Pray...
|
|
|
|
|
Hello all
I have a application that reads the message sent from the printer.
the printer sends the window message, like DOC_START.
I have to register the same message that the printer registered.
<br />
BlackIcePrintMessage = RegisterWindowMessage(szREGISTERMESSAGE);<br />
if (!BlackIcePrintMessage)<br />
{<br />
dwError = GetLastError();<br />
return 0;<br />
} <br />
but how to get/read the message sent from printer..
here the sample code, it works.. but i'm using MFC, dialog based application and the sample code is not for MFC.. the sample code uses WNDCLASS wc and then register with RegisterClass(&wc).
<br />
int PASCAL WinMain(HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, LPSTR lpszCmdLine, int nCmdShow)<br />
{<br />
..<br />
..<br />
..<br />
WNDCLASS wc;<br />
<br />
<br />
wc.style = 0;<br />
wc.lpfnWndProc = TestWndProc;<br />
wc.cbClsExtra = 0;<br />
wc.cbWndExtra = 0;<br />
wc.hInstance = hInst;<br />
wc.hIcon = LoadIcon(hInst, TEXT("TestIcon"));<br />
wc.hCursor = LoadCursor(NULL, IDC_ARROW);<br />
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);<br />
wc.lpszMenuName = TEXT("TESTMENU");<br />
wc.lpszClassName = szMyClass;<br />
<br />
if (!RegisterClass(&wc))<br />
return FALSE;<br />
HWND hwndMyWindow = CreateWindow(szMyClass, TEXT("Black Ice printer Driver Message Capture Sample"),<br />
WS_OVERLAPPEDWINDOW | WS_VISIBLE, CW_USEDEFAULT, 0,<br />
CW_USEDEFAULT, 0, NULL, NULL,<br />
hInst, NULL );<br />
<br />
if ( !hwndMyWindow )<br />
return FALSE;<br />
<br />
ShowWindow (hwndMyWindow, SW_SHOW);<br />
<br />
while ( GetMessage(&msg, NULL, 0, 0 ) )<br />
{<br />
TranslateMessage(&msg);
DispatchMessage(&msg);
}<br />
return (int) msg.wParam;
how can i also register my window class? would it be a right thing to use CCmdTarget class?
Thank you
|
|
|
|
|
Look up ON_REGISTERED_MESSAGE in MSDN for example on how to handle registered messages.
Ignore the sample code for WinMail (that you posted) - you do not need it in MFC.
Get trial copy of comment generating tool CommentMakerPro, std::string and std::string containers viewer FeinEvaluatorPro and windows manager for Microsoft Visual Studio .NET FeinWindows at www.FeinSoftware.com
|
|
|
|
|
Thank you very much..
it is really really helpful hint.
|
|
|
|
|
Hello!!
i'm starting with MFC, and i created a SDI app. I've got the main window (a CFrameWnd) and i want to add a listbox. In the
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
i wrote this line (before that wrote m_LBoxPpal as a CListBox object atribute to the CMainFrame class) :
this->m_LBoxPpal.Create(WS_CHILD | WS_VISIBLE | WS_BORDER,CRect(100, 40, 400, 500),this,ID_LBoxPpal);
and it creates me a listbox. Now i want to add scroll bars to it. Is this an efficient way to do it? I know how to edit dialogs with the resorce editor (to add buttons and stuff). How can i do it with a CFrameWnd?
Thanks!
|
|
|
|
|
If you want to add the scroll bar into the listbox, just specify 'WS_VSCROLL' for a vertical (up-down) scrollbar and 'WS_HSCROLL' for a horizontal (left-right) scrollbar to the style flags of the listbox (WS_CHILD, WS_VISIBLE, WS_BORDER). Using the list-box style flag 'LBS_DISABLENOSCROLL' will prevent the scrollbars from being hidden when there are less than the required amount of items in the box for the scrollbar to appear normally. By default, the scrollbar is hidden if there are not enough many items.
If you desire the scrollbars for the frame window, you need to step into a function called 'PreCreateWindow'. If this function does not exist for your CFrameWnd-derived class, you can use ClassWizard to add it. Then use boolean-OR operation '|' to add style flags into the CREATESTRUCT structure's 'style' member. For example:
BOOL PreCreateWindow( CREATESTRUCT cs )
{
cs.style =| WS_HSCROLL | WS_VSCROLL;
...
} This would add the scrollbars to your frame window. Hope these tips will help you out.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
|
Hi Everybody,
I am trying to write a platform independent C++ library.
I have seen some C++ code in the past where __WINDOWS__ or __WIN32__ is used for windows includes and __UNIX__ for solaris includes. But when I try to use it, it does not work.
1. Do we need to explicity #define these?
2. If yes, where in the code do we do that and how?
Any help would be greatly appreciated.
Thanks,
-Mahesh Shimpi
Ideas multiply by sharing!!
|
|
|
|
|
Mash wrote:
1. Do we need to explicity #define these?
Yes.
Mash wrote:
2. If yes, where in the code do we do that and how?
The actual defines are passed to the compiler. In the code you then do a
#ifdef WIN32<br />
... Do stuff, that is specific to windows, say an optimised verison of a socket class.<br />
class Socket...<br />
class ThreadWrapper<br />
#else<br />
... Do stuff for Unix in here, if you are only working with 2 platforms.<br />
class Socket...<br />
class ThreadWrapper<br />
#endif
Each class will have the same public methods, but depending on the comiler you use will then only compile the code wrapped by the defines passed to it.
A good example of using the defines can be seen when writting plain C++ dll library classes where the classes need to be exported into the function table with a __declspec(dllexport) and need to be imported by the code that used the library with the class headers preceeded by a __declspec(dllimport)
To see this in VS.NET, create a new Win32 project, and make it a dll class library project, and select export symbols, which is where the defines are used for the liker.
#ifdef MYLIB_EXPORTS // specified in compiler options<br />
#define MYLIB_API __declspec(dllexport)<br />
#else<br />
#define MYLIB_API __declspec(dllimport)<br />
#endif<br />
<br />
class MYLIB_API CSampleClass {<br />
public:<br />
CSampleClass(void);<br />
};
A good thing to do would be to have a look an an existing cross platform library like wxWindows, which is an MFC like gui library for Linux and Windows.
http://www.wxwindows.org/[^]
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
Thanks for the clarification Giles.
I can use it now. I defined the respective flags during compilation and used them in the code.
Thanks once again.
-Mahesh Shimpi
Ideas multiply by sharing!!
|
|
|
|
|
_WIN32 is always defined when compiling with Visual C++. I do not know if there is an equivalent which is always defined for GCC, for example.
|
|
|
|
|
You should look at tools like GNU autoconf/automake. I don't know if they work on windows, but they help a lot in dealing with the differences between various Unix versions.
Of course if you only target one Unix (Solaris) you won't care, and even with two it might not be worth the trouble. If you want to make an attempt at supporting more (say all of them...) you will want some help.
|
|
|
|
|
How can I reach pixels of an pictureBox for changing their color attributes.
|
|
|
|
|
IPicture interface returns HDC
HRESULT get_CurDC(
HDC* phdcOut //Receives a pointer to device context
);
Use
COLORREF GetPixel(
HDC hdc, // handle to DC
int nXPos, // x-coordinate of pixel
int nYPos // y-coordinate of pixel
);
COLORREF SetPixel(
HDC hdc, // handle to DC
int X, // x-coordinate of pixel
int Y, // y-coordinate of pixel
COLORREF crColor // pixel color
);
|
|
|
|
|
I've recently upgraded (downgraded, you decide which) to VStudio 7.1 from VC6 and start development of a new app. Everything was working fine (cursing was being kept to a minimum) when the properties window decide to stop displaying properties, i.e., the window appears but with no fields - just a big blank gray window!
Any suggestions on how to get it back? (Its really tough designing dialogs without the property window!!)
Regards,
Kylur.
|
|
|
|
|
The property window displays the properties of the active dialog/class. Remember to click on the dialog or the class implementation file (Open it, and click somewhere) to update the properties window.
If this does not help, back up your projects, uninstall both VC6 and VC7, then do a fresh install of VC7. I have never experienced this problem myself, so it might be a result of unsuccesfull installation.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
I've just started a new MFC program and the main window opens with a size i'd like to change.
there's no create i can find. How do i resize the window? should i do it in the CMainFrame::OnCreate?
thanks
|
|
|
|
|
see "The MFC Answer Book", E. Kain, FAQ 3.9.
Basically put a MoveWindow(...) in the OnCreate method.
Regards,
Kylur
|
|
|
|