visual c++ 2012 application won't run under windows xp - updated - c++

hello and welcom every one
am using visual c++ 2012 ultimate with the update 3, i have a project should be executed in an xp pack 3 envirement, i change the toolset as explained in this blog
Windows XP Targeting with visual studio 2012
on my windows xp machine i install svcedit.exe visual 2012 update 3, but the probleme is that the code couldn't run, and show me no error at all.
i don't really no what the probleme is!!
Example - Source file
main.cpp
#include <WindowsX.h>
#include <Windows.h>
#include <tchar.h>
#include <stdio.h>
#include "resource1.h"
#define my_PROCESS_MESSAGE(hWnd, message, fn) \
case(message): \
return( \
SetDlgMsgResult(hWnd, uMsg, \
HANDLE_##message((hWnd), (wParam), (lParam), (fn)) )) \
LRESULT CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
BOOL Cls_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam);
void Cls_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify);
int WINAPI _tWinMain( HINSTANCE hInstance,
HINSTANCE,
LPTSTR,
int iCmdShow )
{
DialogBoxParam( hInstance,
MAKEINTRESOURCE(IDD_DLLINJECTOR),
NULL,
(DLGPROC) DlgProc,
NULL
);
return 0;
}
LRESULT CALLBACK DlgProc( HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam )
{
switch (uMsg)
{
my_PROCESS_MESSAGE(hWnd, WM_INITDIALOG, Cls_OnInitDialog);
my_PROCESS_MESSAGE(hWnd, WM_COMMAND, Cls_OnCommand);
default:
break;
}
return FALSE;
}
BOOL Cls_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
SetDlgItemText( hwnd,
IDC_DEBUG,
_T("Zirek: Some text\r\n")
);
return TRUE;
}
void Cls_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch (id)
{
case IDCANCEL:
EndDialog(hwnd, id);
break;
default:
break;
}
return;
}
resource1.h
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Resource.rc
//
#define IDCANCEL2 3
#define IDCANCEL3 4
#define IDD_DIALOG1 101
#define IDD_DLLINJECTOR 101
#define IDC_TREE1 1001
#define IDC_EDIT1 1002
#define IDC_DEBUG 1003
#define IDC_LIST1 1004
#define IDC_EDIT4 1005
#define IDC_EDIT3 1007
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1006
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
Resource.rc
// Microsoft Visual C++ generated resource script.
//
#include "resource1.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource1.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DLLINJECTOR DIALOGEX 0, 0, 559, 255
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "DLL Injector"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "&Close",IDCANCEL,494,54,50,14
CONTROL "",IDC_TREE1,"SysTreeView32",WS_BORDER | WS_HSCROLL | WS_TABSTOP,7,7,125,221,WS_EX_CLIENTEDGE
EDITTEXT IDC_EDIT1,7,234,125,14,ES_AUTOHSCROLL,WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE
EDITTEXT IDC_DEBUG,138,149,414,99,ES_MULTILINE | ES_AUTOHSCROLL,WS_EX_CLIENTEDGE
CONTROL "",IDC_LIST1,"SysListView32",LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,138,7,125,137,WS_EX_CLIENTEDGE
CTEXT "Zirek\r\nAT4RE\r\nDLL Injector",IDC_STATIC,486,23,66,26,0,WS_EX_CLIENTEDGE
EDITTEXT IDC_EDIT3,269,130,226,14,ES_AUTOHSCROLL,WS_EX_DLGMODALFRAME
PUSHBUTTON "&Inject",IDCANCEL2,494,74,50,29
EDITTEXT IDC_EDIT4,269,7,211,117,ES_AUTOHSCROLL,WS_EX_CLIENTEDGE
DEFPUSHBUTTON "&Open",IDCANCEL3,502,130,50,14
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_DLLINJECTOR, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 552
TOPMARGIN, 7
BOTTOMMARGIN, 248
END
END
#endif // APSTUDIO_INVOKED
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
the code run correctly on windows 8 and windows 7, but in windows xp whene i click the application nothing happen at all.
Best,
Zirek

You need to install the VC++ 2012 Redistributables on any machine where you want to run the application. Make sure you download and install the redistributables that match your Visual Studio version including Update (for instance, if you have VS2012 Update 2, distribute that version, not the redistributables for VS2013 Update 3).

I don't know what the problem is either, but in general using dependencywalker is a good start. It will tell you if your app depends on functions not available in winxp, or if you forgot to deploy some runtime dll.

Related

WinAPI GUI: Is Status Bar possible with dialog box?

I'm using dialog box-based Win API C++ GUI. Just read the docs and there is CreateStatusWindow API which is used to create the status bar, but I don't know how it can be fit into mine, because I'm using CreateDialogW.
CreateStatusWindow is obsolete, CreateWindow is recommended.
Note This function is obsolete. Use CreateWindow instead
#include <Windows.h>
#include "resource.h"
// Enable Visual Styles
#pragma comment(linker, "\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
// Set Windows GUI Subsystem
#pragma comment(linker, "/SUBSYSTEM:WINDOWS")
// Required for LV_COLUMN and ListView_x
#include <CommCtrl.h>
INT_PTR CALLBACK DialogProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_INITDIALOG:
{
// Load icon
const auto icon = static_cast<HICON>(LoadImageW(GetModuleHandleW(nullptr), MAKEINTRESOURCEW(IDI_ICON1), IMAGE_ICON, 64, 64, 0));
SendMessageW(hWnd, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(icon));
// Load menu
const HMENU menu = LoadMenuW(GetModuleHandleW(nullptr), MAKEINTRESOURCEW(IDR_MENU1));
SetMenu(hWnd, menu);
// Add ListView columns
LVCOLUMNW col{};
col.mask = LVCF_TEXT | LVCF_WIDTH | LVIF_IMAGE;
col.cx = 60;
wchar_t c0_txt[] = L"Title";
col.pszText = c0_txt;
ListView_InsertColumn(GetDlgItem(hWnd, IDC_LIST1), 0, &col);
return TRUE;
}
case WM_NCDESTROY:
PostQuitMessage(0);
return FALSE;
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
DestroyWindow(hWnd);
break;
default:
break;
}
return FALSE; // we didn't handle that particular `msg` completely, therefore we should return FALSE. It can also depend on `wParam` and `lParam`.
}
default:
return FALSE;
}
}
int WINAPI WinMain(
_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine,
_In_ int nShowCmd
)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
HWND hWnd = CreateDialogParamW(hInstance, MAKEINTRESOURCEW(IDD_MAIN), nullptr, &DialogProc, 0);
if (!hWnd)
{
MessageBoxW(nullptr, L"Dialog Creation Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);
MSG msg;
while (GetMessageW(&msg, nullptr, 0, 0))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return msg.wParam;
}
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_MAIN, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 448
TOPMARGIN, 7
BOTTOMMARGIN, 213
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_MAIN DIALOGEX 0, 0, 455, 220
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Test"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "",IDC_LIST1,"SysListView32",LVS_REPORT | LVS_ALIGNLEFT | WS_BORDER | WS_TABSTOP,21,25,396,160
END
/////////////////////////////////////////////////////////////////////////////
//
// AFX_DIALOG_LAYOUT
//
IDD_MAIN AFX_DIALOG_LAYOUT
BEGIN
0
END
/////////////////////////////////////////////////////////////////////////////
//
// Menu
//
IDR_MENU1 MENU
BEGIN
POPUP "Control Panel"
BEGIN
MENUITEM "Exit", ID_CONTROLPANEL_EXIT
END
END
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON1 ICON "Hopstarter-Sleek-Xp-Basic-Folder.ico"
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
Edit (Fixed the chinese characters):
I was able to add it on WM_INITDIALOG, but unfortunately it doesn't resize along with the window's resizing and its encoding is chinese.
// Add Status Bar
RECT client_rect{};
GetClientRect(hWnd, &client_rect);
HWND status = CreateWindowExW(0, STATUSCLASSNAMEW, nullptr, WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0,
client_rect.bottom - client_rect.top - 20,
client_rect.right - client_rect.left, 20, hWnd, nullptr, hInstance,
nullptr);
int status_parts[2] = { client_rect.right - client_rect.left - 170,
client_rect.right - client_rect.left };
SendMessageW(status, SB_SETPARTS, 2, reinterpret_cast<LPARAM>(&status_parts));
SendMessageW(status, SB_SETTEXT, 0, reinterpret_cast<LPARAM>(L"Test"));
SendMessageW(status, WM_SIZE, 0, 0);
When creating a dialog from a resource template the system sends a WM_INITDIALOG message to the dialog procedure:
Sent to the dialog box procedure immediately before a dialog box is displayed. Dialog box procedures typically use this message to initialize controls and carry out any other initialization tasks that affect the appearance of the dialog box.
If a dialog needs a dynamically created Status Bar control, that's where it should be created. Since
the window procedure for the status bar automatically sets the initial size and position of the window, ignoring the values specified in the CreateWindowEx function
you can pass arbitrary values for x, y, width, and height:
case WM_INITDIALOG:
CreateWindowExW(0, STATUSCLASSNAMEW, nullptr, WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP,
0, 0, 0, 0, hWnd,
reinterpret_cast<HMENU>(IDC_STATUS_BAR), GetModuleHandleW(nullptr), nullptr);
return TRUE;
For this to compile you will have to create a symbolic constant IDC_STATUS_BAR to act as a control identifier (used later when resizing). One way is to add it to the resource.h file, e.g.:
#define IDC_STATUS_BAR 101
That creates a properly positioned and sized status bar control. Instructions on how to keep it in the desired relative position when its parent is resized are documented as well:
The window procedure [for the status bar] automatically adjusts the size of the status bar whenever it receives a WM_SIZE message. Typically, when the size of the parent window changes, the parent sends a WM_SIZE message to the status bar.
Again, the status bar control ignores the width and height, so sending a WM_SIZE message with arbitrary values is fine. Add the following to the dialog procedure:
case WM_SIZE:
SendMessageW(GetDlgItem(hWnd, IDC_STATUS_BAR), WM_SIZE, 0, 0);
return FALSE;
and the status bar control will automatically follow its parent's client area.
For the last two questions:
From the fact that your WinMain accepts LPSTR (and not LPWSTR) - I assume that you are NOT building for UNICODE. Then SB_SETTEXT requires an ANSI character string, while you are passing wide string here:
SendMessageW(status, SB_SETTEXT, 0, reinterpret_cast<LPARAM>(L"Test"));
You should either pass a narrow string:
SendMessageW(status, SB_SETTEXT, 0, reinterpret_cast<LPARAM>("Test"));
or use SB_SETTEXTW:
SendMessageW(status, SB_SETTEXTW, 0, reinterpret_cast<LPARAM>(L"Test"));
And for the position of your status bar - you create it at a fixed position within the client window:
HWND status = CreateWindowExW(0, STATUSCLASSNAMEW, nullptr, WS_CHILD | WS_VISIBLE | SBARS_SIZEGRIP, 0,
client_rect.bottom - client_rect.top - 20,
client_rect.right - client_rect.left, 20, hWnd, nullptr, hInstance,
nullptr);
When you resize your window - the status bаr stays at the same client coordinates. You should process the WM_SIZE message and move the status bar accordingly.
You should only use dialog-based app if you need only the features provided by the dialog box.
As soon as you start adding status bar, menu bar, accelerators, serialization, etc. - you would be better off using a regular windows app.

WM_CLOSE doesn't work and the application is not resizable

When I attempt to close the dialog, I expect the application to close, but it doesn't. I assume something is wrong with WM_CLOSE.
The application is not resizable. How do I make it so?
Do I really need UpdateWindow(hWnd)?
#include <Windows.h>
#include "resource.h"
#pragma comment(linker, "\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#pragma comment(linker, "/SUBSYSTEM:WINDOWS")
INT_PTR CALLBACK DialogProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch (Message)
{
case WM_INITDIALOG:
return TRUE;
case WM_CLOSE:
DestroyWindow(hwnd);
PostQuitMessage(0);
return FALSE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
EndDialog(hwnd, IDOK);
break;
case IDCANCEL:
EndDialog(hwnd, IDCANCEL);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
int WINAPI WinMain(
_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine,
_In_ int nShowCmd
)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
HWND hWnd = CreateDialogParamW(hInstance, MAKEINTRESOURCEW(IDD_MAIN), nullptr, &DialogProc, 0);
if (!hWnd)
{
MessageBoxW(nullptr, L"Dialog Creation Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);
MSG msg;
while (GetMessageW(&msg, hWnd, 0, 0))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return msg.wParam;
}
Resource.rc
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_MAIN, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 302
TOPMARGIN, 7
BOTTOMMARGIN, 169
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_MAIN DIALOGEX 0, 0, 309, 176
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Test"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LISTBOX IDC_LIST2,48,30,235,56,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
GROUPBOX "Static",IDC_STATIC,146,92,48,40
PUSHBUTTON "Button1",IDC_BUTTON1,215,127,50,14
END
/////////////////////////////////////////////////////////////////////////////
//
// AFX_DIALOG_LAYOUT
//
IDD_MAIN AFX_DIALOG_LAYOUT
BEGIN
0
END
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
resource.h
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Resource.rc
//
#define IDD_MAIN 103
#define IDC_LIST2 1005
#define IDC_BUTTON1 1006
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1007
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
The problem is you are passing hWnd as a parameter to GetMessage(). This causes GetMessage() to only retrieve messages for the window. But WM_QUIT is not sent to your window, but to your thread. Since GetMessage() never retrieves the WM_QUIT message, the message loop never exits.
The proper approach is to pass nullptr instead of hWnd.

GUI - unable to add columns to a ListView

I want to add columns to a ListView control. You can see what I tried below using ListView_InsertColumn, but I'm getting "identifier x is undefined". It should be in CommCtrl.h, but I don't know what's wrong. I've seen some people using CListView_InsertColumn instead. Not sure what the difference is.
#include <Windows.h>
#include "resource.h"
#pragma comment(linker, "\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#pragma comment(linker, "/SUBSYSTEM:WINDOWS")
#include <CommCtrl.h> // LV_COLUMN and ListView_x
INT_PTR CALLBACK DialogProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch (Message)
{
case WM_INITDIALOG:
LVCOLUMNW col;
col.mask = LVCF_TEXT | LVCF_WIDTH | LVIF_IMAGE;
col.cx = 40;
ListView_InsertColumn(GetDlgItem(hWnd, IDC_LIST2), 0, &col);
return TRUE;
case WM_NCDESTROY:
PostQuitMessage(0);
return FALSE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
case IDCANCEL:
DestroyWindow(hWnd);
break;
default:
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
int WINAPI WinMain(
_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPSTR lpCmdLine,
_In_ int nShowCmd
)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
HWND hWnd = CreateDialogParamW(hInstance, MAKEINTRESOURCEW(IDD_MAIN), nullptr, &DialogProc, 0);
if (!hWnd)
{
MessageBoxW(nullptr, L"Dialog Creation Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
return 0;
}
ShowWindow(hWnd, nShowCmd);
UpdateWindow(hWnd);
MSG msg;
while (GetMessageW(&msg, nullptr, 0, 0))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return msg.wParam;
}
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "winres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""winres.h""\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_MAIN, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 302
TOPMARGIN, 7
BOTTOMMARGIN, 169
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_MAIN DIALOGEX 0, 0, 309, 176
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Test"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
LISTBOX IDC_LIST2,29,44,235,56,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
END
/////////////////////////////////////////////////////////////////////////////
//
// AFX_DIALOG_LAYOUT
//
IDD_MAIN AFX_DIALOG_LAYOUT
BEGIN
0
END
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
As mentioned in the comments, the control you define in your resource script is a ListBox, not a ListView. For the latter, you'll need to use the generic CONTROL statement with a control class of "SysListView32" (this can be inserted from the Visual Resource Editor as a "List Control" object, with its "View" property set to "Report"). Note: Without the LVS_REPORT style, you can't add columns to your control.
Here's a suggested replacement for the dialog resource you have:
IDD_MAIN DIALOGEX 0, 0, 309, 176
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
CAPTION "Test"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
//LISTBOX IDC_LIST2, 29, 44, 235, 56, LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
CONTROL "", IDC_LIST2, "SysListView32", LVS_REPORT | LVS_SORTASCENDING | WS_VSCROLL | WS_TABSTOP,
29, 44, 235, 56
END
With only that change made, your program will crash/hang during the call to ListView_InsertColumn, because you have specified the LVCF_WIDTH and LVCF_IMAGE flags in the mask member of the LVCOLUMN structure but have not provided valid data for those flags. I can't just 'invent' an image for you but, with some 'dummy' text values (and an extra column, for good measure), here's a suggestion for some 'fixed' code:
switch (Message) {
case WM_INITDIALOG: {
wchar_t c0txt[] = L"abc-0";
LVCOLUMNW col;
col.mask = LVCF_TEXT | LVCF_WIDTH;// | LVIF_IMAGE;
col.cx = 40;
col.pszText = c0txt;
ListView_InsertColumn(GetDlgItem(hWnd, IDC_LIST2), 0, &col);
// Add another column...
wchar_t c1txt[] = L"xyz-1";
col.mask = LVCF_TEXT | LVCF_WIDTH;// | LVIF_IMAGE;
col.cx = 80;
col.pszText = c1txt;
ListView_InsertColumn(GetDlgItem(hWnd, IDC_LIST2), 1, &col);
return TRUE;
}
When building your code with just the changes outlined above, I get a list view control with two columns:

Resource window doesn't work properly on other systems (Visual Studio 2012)

I have created a simple Win32 Project application (not MFC!) in Visual Studio 2012 (Win7 x64).
For the main window I used a modeless window from resources.
Compiled program worked well. Then I tried to run this program on another computer. To do it first of all I compiled it in Release, the Runtime Library option was set to Multi-threaded (/ MT).
And I noticed the following problem - on the virtual win7 x64, the program started, but I couldn't move the program's main window with the mouse and there was no reaction to the pressing of the close button. I.e. I can't close the window using system menu.
I also compiled version for WinXP x86. It was the same result. I also noticed another thing - if I place a couple of buttons to window in the designer, and start program on WinXP, then I see the buttons moved down a bit ...
But on the PC where the program was compiled - everything works fine - the window moves with mouse, the system menu works also.
Where can there be a mistake?
Code:
#include "stdafx.h"
#include "Win32Project1.h"
INT_PTR WINAPI Dlg_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
//=========================================================================
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPTSTR lpCmdLine,
_In_ int nCmdShow)
{
HWND mainWnd = CreateDialog(hInstance, MAKEINTRESOURCE(mainWindow), NULL, (DLGPROC)Dlg_Proc);
ShowWindow(mainWnd, SW_SHOW);
MSG msg;
BOOL bRet;
while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0)
{
if (bRet == -1)
{
}
else if (!IsWindow(mainWnd) || !IsDialogMessage(mainWnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
//=========================================================================
INT_PTR WINAPI Dlg_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return TRUE;
}
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
.rc file:
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#ifndef APSTUDIO_INVOKED
#include "targetver.h"
#endif
#define APSTUDIO_HIDDEN_SYMBOLS
#include "windows.h"
#undef APSTUDIO_HIDDEN_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Russian (Russia) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
mainWindow DIALOGEX 0, 0, 309, 178
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
mainWindow, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 302
TOPMARGIN, 7
BOTTOMMARGIN, 171
END
END
#endif // APSTUDIO_INVOKED
#endif // Russian (Russia) resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_WIN32PROJECT1 ICON "Win32Project1.ico"
IDI_SMALL ICON "small.ico"
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#ifndef APSTUDIO_INVOKED\r\n"
"#include ""targetver.h""\r\n"
"#endif\r\n"
"#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
"#include ""windows.h""\r\n"
"#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
Remarks from DialogProc:
You should use the dialog box procedure only if you use the dialog box class for the dialog box. This is the default class and is used when no explicit class is specified in the dialog box template. Although the dialog box procedure is similar to a window procedure, it must not call the DefWindowProc function to process unwanted messages. Unwanted messages are processed internally by the dialog box window procedure.
You are doing exactly this - calling DefWindowProc from DialogProc callback instead of returning FALSE to indicate that message has not been processed. Also there should be no need to cast (DLGPROC)Dlg_Proc.

Dialog Background and Radio Button Transperancy

Hello Everyone,
I am making an application in Visual C++ 2008 Professional Edition which uses a background image for a dialog box. The problem is that I can't get radio buttons to be transparent so that the image is in the backdrop and only the caption of the radio button is visible.
Please check the image. The radio button should be transparent and only the text of the control should be visible. I have already checked the following link-:
Dialog box Background image
I am using the following code-:
#include <Windows.h>
#include <CommCtrl.h>
#include "resource.h"
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
LRESULT CALLBACK WindowFunc(HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK DialogFunc(HWND, UINT, WPARAM, LPARAM);
int controlsLoaded=0;
char szWinName[]="Test";
HWND hDlg=NULL;
HINSTANCE hInst;
int WINAPI WinMain(HINSTANCE hThisInst, HINSTANCE hPrevInst,
LPSTR lpszArgs, int nWinMode)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass;
wndclass.cbSize=sizeof(WNDCLASSEX);
wndclass.hInstance=hThisInst;
wndclass.lpszClassName=szWinName;
wndclass.lpfnWndProc=WindowFunc;
wndclass.style=0;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hIconSm=NULL;
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.lpszMenuName=NULL;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH) GetStockObject(LTGRAY_BRUSH);
if(!RegisterClassEx(&wndclass)) return 0;
/*Initialize the common controls for WinXP look and feel*/
InitCommonControls();
hInst=hThisInst;
hwnd=CreateWindow(
szWinName,
"Auto Timer (Work in progress)",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hThisInst,
NULL
);
while(GetMessage(&msg, NULL, 0, 0)>0)
{ if (!hDlg||!IsDialogMessage(hDlg,&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
LRESULT CALLBACK WindowFunc(HWND hwnd, UINT message, WPARAM wparam,
LPARAM lparam)
{
switch(message){
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CREATE:
hDlg=CreateDialog(hInst,MAKEINTRESOURCE(IDD_FORMVIEW),
hwnd,(DLGPROC)DialogFunc);
break;
default:
return DefWindowProc(hwnd,message,wparam,lparam);
}
return 0;
}
BOOL CALLBACK DialogFunc(HWND hwnd, UINT message,
WPARAM wparam, LPARAM lparam)
{
switch(message)
{
case WM_CLOSE:
DestroyWindow(hwnd);
hDlg=NULL;
PostQuitMessage(0);
return TRUE;
}
return FALSE;
}
The following is my resource file-:
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_FORMVIEW, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 251
TOPMARGIN, 7
BOTTOMMARGIN, 83
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_FORMVIEW DIALOGEX 0, 0, 259, 91
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_OVERLAPPEDWINDOW | WS_EX_APPWINDOW
CAPTION "Test"
FONT 8, "MS Shell Dlg", 400, 0, 0x0
BEGIN
CONTROL "Radio1",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON,103,48,94,20,WS_EX_TRANSPARENT
CONTROL 102,IDC_STATIC,"Static",SS_BITMAP,119,44,33,31,WS_EX_TRANSPARENT
END
/////////////////////////////////////////////////////////////////////////////
//
// Bitmap
//
IDB_BITMAP1 BITMAP "1.bmp"
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
I have tried returning the brush to the bitmap image with WM_CTLCOLORSTATIC message. But it doesn't work. Is there any way to send the message for drawing the controls manually? Because I think I can avoid this problem if the picture is drawn first and then radio button. For example WM_CTLCOLORSTATIC message is sent every time a static control is to be drawn is it the same message that is sent when a radio button is to be drawn because radio buttons are not static controls. Please do not give me msdn links and I am using pure Win32 and not MFC. Please I need help so far whatever I have tried is not helping and I have heard that there is no limitation to what the Win32 API can do. Oh and I have also posted this topic on dreamincode.net Check Here
Add to your DialogFunc:
case WM_CTLCOLORBTN:
//.....
int nCtrlId = GetDlgCtrlID((HWND)lParam);
if(nCtrlId == RadiobuttonID)
{
SetBkMode((HDC)wParam), TRANSPARENT);
return (HBRUSH)GetStockObject(HOLLOW_BRUSH);
}