|
From: Daniel G. <dgo...@eh...> - 2006-12-31 02:42:00
|
I need a windows application to check/uncheck treeview checkboxes. But
it is unable to when compiled with the mingw cross-compiler.
The windows compiler (compile directly on windows PC) says "gcc version
3.4.2 (mingw-special)". The checkbox IS checked when the program starts.
The linux cross-compiler (i586-mingw32msvc-gcc) says "gcc version 3.4.2
(mingw-special)". But checkbox IS NOT checked when the program starts.
I like using the cross-compiler, because it lets me centralize all
development on linux computer.
I included the test program below with single treeview checkbox. Anybody
know why the checkbox is not getting checked in the cross-compiled
version? Am I doing something wrong? One of TreeView_SetCheckState,
TreeView_SetItemState, or TVM_SETITEM not working correctly?
I tried looking on the mingw-crosscompile archive, could not view it (I
am registered), so I'm also posting to mingw-users list so I can read
response.
Thanks,
Daniel Goldman
#define _WIN32_IE 0x0500
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
HWND Tree_g;
HWND MainWin_g ;
HINSTANCE HInstance_g ;
#if !defined TreeView_SetCheckState
#define TreeView_SetCheckState(hwndTV, hti, fCheck) \
TreeView_SetItemState(hwndTV, hti, \
INDEXTOSTATEIMAGEMASK((fCheck)?2:1), TVIS_STATEIMAGEMASK)
#endif /* #if !defined TreeView_SetCheckState */
#if !defined TreeView_SetItemState
#define TreeView_SetItemState(w,i,d,m) \
{ \
TVITEM _tvi;\
_tvi.mask=TVIF_STATE;\
_tvi.stateMask=m;\
_tvi.state=d;\
SNDMSG((w),TVM_SETITEM,0,(LPARAM)(TVITEM*)&_tvi);\
}
#endif /* #if !defined TreeView_SetItemState */
LRESULT CALLBACK WndProc (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
HDC hdc ;
PAINTSTRUCT ps ;
HTREEITEM hItem ;
TVITEM tvi;
TVINSERTSTRUCT tvis;
switch (message)
{
case WM_CREATE:
return 0 ;
case WM_PAINT :
hdc = BeginPaint (hwnd, &ps) ;
TreeView_DeleteAllItems (Tree_g);
memset (&tvis, 0, sizeof (tvis));
memset (&tvi, 0, sizeof (tvi));
tvi.mask |= TVIF_TEXT;
tvi.pszText = "1";
tvis.hParent = TVI_ROOT;
tvis.hInsertAfter = TVI_LAST;
tvis.item = tvi;
hItem = TreeView_InsertItem (Tree_g, &tvis);
TreeView_SetCheckState (Tree_g, hItem, TRUE);
EndPaint (hwnd, &ps) ;
return 0 ;
case WM_DESTROY :
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
static TCHAR szAppName[] = TEXT ("chkbox2") ;
MSG msg ;
WNDCLASS wndclass ;
DWORD dwStyle;
wndclass.style = CS_HREDRAW | CS_VREDRAW ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
HInstance_g = hInstance;
RegisterClass (&wndclass);
InitCommonControls();
MainWin_g = CreateWindow (szAppName, TEXT ("chkbox2"),
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL) ;
Tree_g = CreateWindow (WC_TREEVIEW, NULL,
TVS_HASBUTTONS | WS_VISIBLE | WS_BORDER | WS_CHILD,
10, 10, 100, 100, MainWin_g, (HMENU) 3, HInstance_g, NULL) ;
dwStyle = (DWORD) GetWindowLongPtr (Tree_g, GWL_STYLE);
dwStyle |= TVS_CHECKBOXES;
SetWindowLongPtr (Tree_g, GWL_STYLE, (LONG_PTR) dwStyle);
ShowWindow (MainWin_g, iCmdShow) ;
UpdateWindow (MainWin_g) ;
while (GetMessage (&msg, NULL, 0, 0)) {
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}
|
|
From: Brian D. <br...@de...> - 2006-12-31 03:23:35
|
Daniel Goldman wrote: > I included the test program below with single treeview checkbox. Anybody > know why the checkbox is not getting checked in the cross-compiled > version? Am I doing something wrong? One of TreeView_SetCheckState, > TreeView_SetItemState, or TVM_SETITEM not working correctly? I don't know enough about treeview controls to audit your code, sorry. But I suggest that you not focus on the red herring of native/cross, and instead search for undefined behavior (e.g. accidently using a value uninitialized.) This sort of thing -- behavior that changes with compiler versions or other environmental factors that should logically have no effect -- is the classic trademark of unknowingly or accidently invoking undefined behavior, which is quite easy to do in modern C. Compile with -Wall and rectify all warnings, check the return value of all function calls, and so on. (The latter is good programming practice anyway, so I would do it regardless of any debugging efforts.) Brian |
|
From: Daniel G. <dgo...@eh...> - 2006-12-31 04:51:32
|
Brian Dessent wrote:
> Daniel Goldman wrote:
>
>
>>I included the test program below with single treeview checkbox. Anybody
>>know why the checkbox is not getting checked in the cross-compiled
>>version? Am I doing something wrong? One of TreeView_SetCheckState,
>>TreeView_SetItemState, or TVM_SETITEM not working correctly?
>
>
> I don't know enough about treeview controls to audit your code, sorry.
> But I suggest that you not focus on the red herring of native/cross, and
> instead search for undefined behavior (e.g. accidently using a value
> uninitialized.) This sort of thing -- behavior that changes with
> compiler versions or other environmental factors that should logically
> have no effect -- is the classic trademark of unknowingly or accidently
> invoking undefined behavior, which is quite easy to do in modern C.
>
> Compile with -Wall and rectify all warnings, check the return value of
> all function calls, and so on. (The latter is good programming practice
> anyway, so I would do it regardless of any debugging efforts.)
>
> Brian
>
I double-checked with -Wall (which I usually do but had not here). There
were
no warnings. Thanks for the good advice.
You're right, it's probably something wrong I'm doing, but there is a
slight
chance it's something wrong with cross-compiler.
Here's the relevant code (complete code in original post), for anyone
familiar with treeview controls:
Tree_g = CreateWindow (WC_TREEVIEW, NULL,
TVS_HASBUTTONS | WS_VISIBLE | WS_BORDER | WS_CHILD,
10, 10, 100, 100, MainWin_g, (HMENU) 3, HInstance_g, NULL) ;
dwStyle = (DWORD) GetWindowLongPtr (Tree_g, GWL_STYLE);
dwStyle |= TVS_CHECKBOXES;
SetWindowLongPtr (Tree_g, GWL_STYLE, (LONG_PTR) dwStyle);
Here's the code for adding item with checkbox:
TreeView_DeleteAllItems (Tree_g);
memset (&tvis, 0, sizeof (tvis));
memset (&tvi, 0, sizeof (tvi));
tvi.mask |= TVIF_TEXT;
tvi.pszText = "1";
tvis.hParent = TVI_ROOT;
tvis.hInsertAfter = TVI_LAST;
tvis.item = tvi;
hItem = TreeView_InsertItem (Tree_g, &tvis);
TreeView_SetCheckState (Tree_g, hItem, TRUE);
Thanks,
Daniel
|
|
From: Keith M. <kei...@us...> - 2006-12-31 07:13:23
|
On Sunday 31 December 2006 02:42, Daniel Goldman wrote: > I need a windows application to check/uncheck treeview checkboxes. But > it is unable to when compiled with the mingw cross-compiler. Like Brian (Dessent), I don't have sufficient experience of using treeview controls, to offer advice specific to your problem -- in fact, I have zero experience in this area. > The windows compiler (compile directly on windows PC) says "gcc version > 3.4.2 (mingw-special)". The checkbox IS checked when the program starts. > > The linux cross-compiler (i586-mingw32msvc-gcc) says "gcc version 3.4.2 > (mingw-special)". But checkbox IS NOT checked when the program starts. You don't say, but given the hideous name, I'd guess that you've obtained that from some prebuilt Linux package set, (Debian or Gentoo, perhaps). If you suspect that you have issues with that cross-compiler suite, then I'm afraid you will have to take them up with the original packager. Alternatively, you might like to try building a more recent version from scratch, using the build script which *we* support: http://downloads.sourceforge.net/mingw/x86-mingw32-build.sh-0.0-20061107-1.tar.bz2 To capture the most recent runtime library updates, you might also like to grab this CVS update: http://mingw.cvs.sourceforge.net/*checkout*/mingw/xscripts/x86-mingw32-build.sh.conf?revision=1.2 > I like using the cross-compiler, because it lets me centralize all > development on linux computer. So do I :-) Mine is called i586-mingw32-gcc, and announces itself as version 3.4.5 (mingw special). FWIW, I don't even have Woe32 on my development box. Regards, Keith. |
|
From: Daniel G. <dgo...@eh...> - 2007-02-04 19:24:05
|
I upgraded my debian linux from sarge to etch (a bother because dist-upgrade did not work, so I had to install from scratch)..., which let me install the newest 3.4.5 version of mingw cross-compiler (new version requires etch, wouldn't install to sarge)..., which solved the problem (TreeView_SetCheckState works now). Thanks, Daniel Goldman Keith Marshall wrote: > On Sunday 31 December 2006 02:42, Daniel Goldman wrote: > >>I need a windows application to check/uncheck treeview checkboxes. But >>it is unable to when compiled with the mingw cross-compiler. > > > Like Brian (Dessent), I don't have sufficient experience of using treeview > controls, to offer advice specific to your problem -- in fact, I have zero > experience in this area. > > >>The windows compiler (compile directly on windows PC) says "gcc version >>3.4.2 (mingw-special)". The checkbox IS checked when the program starts. >> >>The linux cross-compiler (i586-mingw32msvc-gcc) says "gcc version 3.4.2 >>(mingw-special)". But checkbox IS NOT checked when the program starts. > > > You don't say, but given the hideous name, I'd guess that you've obtained that > from some prebuilt Linux package set, (Debian or Gentoo, perhaps). If you > suspect that you have issues with that cross-compiler suite, then I'm afraid > you will have to take them up with the original packager. Alternatively, you > might like to try building a more recent version from scratch, using the > build script which *we* support: > http://downloads.sourceforge.net/mingw/x86-mingw32-build.sh-0.0-20061107-1.tar.bz2 > > To capture the most recent runtime library updates, you might also like to > grab this CVS update: > http://mingw.cvs.sourceforge.net/*checkout*/mingw/xscripts/x86-mingw32-build.sh.conf?revision=1.2 > > >>I like using the cross-compiler, because it lets me centralize all >>development on linux computer. > > > So do I :-) Mine is called i586-mingw32-gcc, and announces itself as version > 3.4.5 (mingw special). FWIW, I don't even have Woe32 on my development box. > > Regards, > Keith. > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > MinGW-users mailing list > Min...@li... > > You may change your MinGW Account Options or unsubscribe at: > https://lists.sourceforge.net/lists/listinfo/mingw-users > |