C++ MoveWindow对ListView控件的影响:为什么在调用函数后列标题会隐藏起来?
我有一个C++ MoveWindow对ListView控件的影响:为什么在调用函数后列标题会隐藏起来?,c++,listview,winapi,win32gui,movewindow,C++,Listview,Winapi,Win32gui,Movewindow,我有一个对话框,其中有一个列表视图控件(lvc)。因为在lvc之前有很多editbox(包括lvc在内的57个控件),所以lvc不在屏幕上。所以我必须制作一个垂直滚动条 垂直滚动条: 范围:0-250 每SB_PAGEDOWN,SB_PAGEUP,SB_LINEDOWN和SB_LINEUP将滚动位置更改25次 #define max_scroll_range 250 #define min_scroll_range 0 #define scroll_step max_scroll_range/
对话框
,其中有一个列表视图
控件(lvc)。因为在lvc之前有很多editbox
(包括lvc在内的57个控件),所以lvc不在屏幕上。所以我必须制作一个垂直滚动条
垂直滚动条:
范围:0-250
每
SB_PAGEDOWN
,SB_PAGEUP
,SB_LINEDOWN
和SB_LINEUP
将滚动位置更改25次
#define max_scroll_range 250
#define min_scroll_range 0
#define scroll_step max_scroll_range/10
项目文件概述
我提供了所有的文件,这样你就可以看到问题的现场
main.cpp
#include "include/basefile01.h"
/* Declare Windows procedure */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
HINSTANCE gi ;
HWND parentHwnd;
/* Make the class name into a global variable */
TCHAR szClassName[ ] = _T("IGAM");
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = gi = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = CS_DBLCLKS; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = (HICON)MAKEINTRESOURCE(APP_ICON_XL);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = MAKEINTRESOURCE(MAIN_MENU); /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default colour as the background of the window */
wincl.hbrBackground = (HBRUSH) GetStockObject( WHITE_BRUSH );
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
return 0;
/* The class is registered, let's create the program*/
parentHwnd = hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
_T("IGAM"), /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Make the window visible on the screen */
ShowWindow (hwnd, nCmdShow);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_COMMAND:
switch(LOWORD(wParam)){
case MAIN_MENU_file_new_invoice:
DialogBox(gi, MAKEINTRESOURCE(NEW_INVOICE_DIALOG), parentHwnd, (DLGPROC)invoice_dialog_box_message_handle);
break;
}
break;
case WM_DESTROY:
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
此文件调用将其与其他文件连接的对话框
basefile01.cpp
#include "../include/basefile01.h"
#include <vector>
#define max_scroll_range 250
#define min_scroll_range 0
#define scroll_step max_scroll_range/10
long iPrevVscroll = 0;
BOOL CALLBACK invoice_dialog_box_message_handle(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
static long iVscroll;
switch(msg)
{
case WM_INITDIALOG:
iVscroll = 0;
SetScrollRange(hwnd, SB_VERT, min_scroll_range, max_scroll_range, TRUE);
SetScrollPos(hwnd, SB_VERT, min_scroll_range, TRUE);
create_listViews_invoice_dialog(hwnd);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wp))
{
case IDCANCEL:EndDialog(hwnd, wp); return TRUE;
}
break;
/**
there are two variables @iVscroll and @iPrevVscroll
they are there because the every child window will be moved up
by the between previous scroll position and the current scroll position
*/
case WM_VSCROLL:
switch(LOWORD(wp))
{
case SB_PAGEDOWN:
case SB_LINEDOWN : iVscroll += scroll_step; break;
case SB_PAGEUP:
case SB_LINEUP: iVscroll -= scroll_step; break;
case SB_THUMBTRACK: iVscroll = HIWORD(wp); break;
};
/// iVscroll should be in the range of min_scroll_range and max_scroll_range
iVscroll = ( iVscroll < min_scroll_range ? min_scroll_range : ( iVscroll > max_scroll_range ? max_scroll_range : iVscroll ) );
/// don't move any child windows if iVscroll is at boundaries
if(!iVscroll || iVscroll == iPrevVscroll ) return TRUE;
SetScrollPos(hwnd, SB_VERT, iVscroll, TRUE);
/// Enumerate to all child windows of the dialog box; this is better than calling and moving each window in a loop
EnumChildWindows(hwnd, invoice_dialog_child_enum_scroll, (LPARAM)iVscroll);
iPrevVscroll = iVscroll;
/// redraw the whole dialog box client area
InvalidateRect (hwnd, NULL, TRUE) ;
UpdateWindow(hwnd);
return TRUE;
default :return FALSE;
}
}
BOOL CALLBACK invoice_dialog_child_enum_scroll(HWND hwnd, LPARAM lp)
{
long s = (long) lp;
RECT rc;
GetWindowRect(hwnd, &rc);
/// the above function return the coordinates relative to the top left of the screen at which\
i am looking at. So to convert those coordinates which are relative to\
the dialog box the following function is used
MapWindowPoints(HWND_DESKTOP, GetParent(hwnd), (LPPOINT)&rc, 2);
/// move the window by the difference between @iVscroll and @iPrevVscroll
MoveWindow(hwnd, rc.left, rc.top - ( s - iPrevVscroll ), rc.right-rc.left, rc.bottom - rc.top, TRUE);
//SetWindowPos(hwnd, HWND_TOP,rc.left, rc.top - ( s - iPrevVscroll ), rc.right-rc.left, rc.bottom - rc.top,SWP_NOOWNERZORDER | SWP_NOSIZE);
}
BOOL create_listViews_invoice_dialog(HWND hwnd)
{
/**
this function creates the listview successfully
*/
/// initializing the listview common control
INITCOMMONCONTROLSEX icx;
icx.dwSize = sizeof(INITCOMMONCONTROLSEX);
icx.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&icx);
RECT LV_rect = {10,25,380,375};
/// changing to the above coordinates to coordinates in dialog units
MapDialogRect(hwnd, &LV_rect);
/// creating the list view control
HWND lv_hwnd = CreateWindow(
WC_LISTVIEW,
L"",
WS_CHILD | LVS_REPORT | LVS_EDITLABELS | WS_VISIBLE,
LV_rect.left, LV_rect.top,
LV_rect.right - LV_rect.left,
LV_rect.bottom - LV_rect.top,
hwnd,
(HMENU)nid_itd_lv,
(HINSTANCE)GetWindowLong(GetParent(hwnd), GWL_HINSTANCE),
NULL
);
/// adding some extended styles and adding columns
ListView_SetExtendedListViewStyle(lv_hwnd, LVS_EX_FLATSB | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_LABELTIP );
create_invoice_lv_columns(lv_hwnd);
}
BOOL create_invoice_lv_columns(HWND hwnd)
{
LVCOLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_TEXT;
/// some variables deceleration
int col_fmt[5] = { LVCFMT_CENTER, LVCFMT_LEFT, LVCFMT_CENTER, LVCFMT_CENTER, LVCFMT_CENTER };
int col_wid[5] = { 30, 90, 50, 30, 70 };
std::vector<TCHAR*> col_nam(5);
col_nam[0] = _T("S.No"); col_nam[1] = _T("Description"); col_nam[2] = _T("HSN"); col_nam[3] = _T("QTY"); col_nam[4] = _T("Rate");
for(int i =0; i < 5; i++)
{
lvc.fmt = col_fmt[i];
lvc.cx = col_wid[i];
lvc.pszText = col_nam[i];
lvc.iSubItem = i;
ListView_InsertColumn(hwnd, i, &lvc);
}
}
主要资源
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "../include/main_rsc.h"
///////// MENUS
MAIN_MENU MENU
{
POPUP "File"
{
POPUP "New"
{
MENUITEM "Invoice", MAIN_MENU_file_new_invoice
MENUITEM "Challan", MAIN_MENU_file_new_challan
}
MENUITEM "&open", MAIN_MENU_file_open
POPUP "&Export"
{
MENUITEM "JPEG", MAIN_MENU_file_export_jpeg
MENUITEM "PDF", MAIN_MENU_file_export_pdf
}
}
}
NEW_INVOICE_DIALOG_MENU MENU
{
MENUITEM "&save", NEW_INVOICE_DIALOG_MENU_save
MENUITEM "&help",NEW_INVOICE_DIALOG_MENU_help,HELP
}
//////////////// ICONS
APP_ICON_XL ICON "icons/icon02_256.ico"
APP_ICON_S ICON "icons/icon02_16.ico"
/**
DIALOG resource
*/
NEW_INVOICE_DIALOG DIALOGEX 0,0,500,300
CAPTION "New Invoice"
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU | WS_THICKFRAME | WS_VSCROLL
MENU NEW_INVOICE_DIALOG_MENU
FONT 8, "Ms Shell Dlg"
{
GROUPBOX "Purchase Order Information", nid_order_info, 10, 10, 370, 65
LTEXT "PO NUMBER",nid_ponumber_t, 20, 20, 50, 12
EDITTEXT nid_ponumber_c, 70, 20, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "PO DATE", nid_podate_t, 20, 40, 50, 12
EDITTEXT nid_podate_c, 70, 40, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "Vendor Code", nid_vcode_t, 20, 60, 50, 12
EDITTEXT nid_vcode_c, 70, 60, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
GROUPBOX "Seller Information", nid_seller_info, 10,80, 180, 70
LTEXT "Invoice No.", nid_inv_no_t, 20, 90, 50, 20
EDITTEXT nid_inv_no_c, 70, 90, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "Invoice date", nid_inv_date_t, 20, 110, 50, 12
EDITTEXT nid_inv_date_c, 70, 110, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "GSTIN", nid_seller_gstin_t, 20, 130, 50, 12
EDITTEXT nid_seller_gstin_c, 70, 130, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
GROUPBOX "Billed To", nid_bt_info, 10, 155, 180, 100
LTEXT "Name", nid_bt_to_t, 20,170,50,12
EDITTEXT nid_bt_to_c, 70, 170,100,12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "Address", nid_bt_add_t, 20,190,50,12
EDITTEXT nid_bt_add_c, 70,190,100,12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "GSTIN", nid_bt_gstin_t, 20, 210, 50,12
EDITTEXT nid_bt_gstin_c, 70,210,100,12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "State", nid_bt_state_t, 20, 230,50,12
EDITTEXT nid_bt_state_c, 70,230,100,12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
CHECKBOX "Shipped to is same as Billed to", nid_is_bt_st_same_, 200, 230, 180,20
GROUPBOX "Shipping Information", nid_ship_info, 200, 80, 180, 140
LTEXT "Name ", nid_ship_to_t, 210, 100, 50, 12
EDITTEXT nid_ship_to_c, 260, 100, 100, 12,ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "Address", nid_ship_add_t , 210, 120, 50,12
EDITTEXT nid_ship_add_c, 260, 120,100,10, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "GSTIN", nid_ship_gstin_t, 210,140,50,12
EDITTEXT nid_ship_gstin_c, 260,140,100,12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "Date", nid_ship_date_t, 210,160,50,12
EDITTEXT nid_ship_date_c, 260,160,100,12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "Mode", nid_ship_mode_t, 210, 180,50,12
EDITTEXT nid_ship_mode_c, 260, 180,100,12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "State", nid_ship_state_t, 210,200,50,12
EDITTEXT nid_ship_state_c, 260,200,100,12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
GROUPBOX "Taxing information", nid_tax_info, 10,270,370, 45
CTEXT "CGST (%)", nid_tax_cgst_t, 25, 280, 100, 12
EDITTEXT nid_tax_cgst_c, 25,295, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_NUMBER
CTEXT "SGST (%)", nid_tax_sgst_t, 135, 280, 100, 12
EDITTEXT nid_tax_sgst_c, 135,295, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_NUMBER
CTEXT "IGST (%)", nid_tax_igst_t, 255, 280, 100, 12
EDITTEXT nid_tax_igst_c, 255,295, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_NUMBER
}
#包括
#包括
#包括
#包括“./include/main_rsc.h”
/////////菜单
主菜单
{
弹出“文件”
{
弹出“新建”
{
菜单项“发票”,主菜单文件新发票
菜单项“Challan”,主菜单\u文件\u新建\u Challan
}
菜单项“&打开”,主菜单\u文件\u打开
弹出窗口“&导出”
{
菜单项“JPEG”,主菜单\u文件\u导出\u JPEG
菜单项“PDF”,主菜单文件导出PDF
}
}
}
新建发票对话框菜单
{
菜单项“&保存”,新建\u发票\u对话框\u菜单\u保存
菜单项“&帮助”,新建发票对话框菜单帮助,帮助
}
////////////////图标
应用程序图标图标XL图标“图标/icon02\U 256.ico”
应用程序图标图标“图标/icon02\U 16.ico”
/**
对话资源
*/
新建发票对话框EX0,050300
标题“新发票”
样式DS|U 3DLOOK | DS|U中心| DS|U MODALFRAME | DS|U SHELLFONT | WS|U标题| WS|U可见| WS|U弹出| WS| U系统菜单| WS| U厚框| WS| WS|U VSCROLL
菜单新建发票对话框菜单
字体8,“Ms Shell Dlg”
{
GROUPBOX“采购订单信息”,nid_订单信息,10,10,370,65
LTEXT“采购订单编号”,编号为20、20、50、12
EDITTEXT nid_ponumber_c,70,20,100,12,ES_LEFT | WS|U BORDER | WS|U TABSTOP | WS|U GROUP | ES|U AUTOHSCROLL
LTEXT“订单日期”,nid_podate_t,20,40,50,12
EDITTEXT nid_podate_c,70,40,100,12,左起|右起|右起|右起|右起|右起|右起|右起|右起
LTEXT“供应商代码”,nid_vcode_t,20,60,50,12
EDITTEXT nid|U vcode|c,70,60,100,12,ES|U LEFT | WS|U BORDER | WS|U TABSTOP | WS|U GROUP | ES|U AUTOHSCROLL
GROUPBOX“卖家信息”,nid_卖家信息,10,80,180,70
LTEXT“发票号”,nid发票号,20,90,50,20
EDITTEXT nid_inv_no_c,70,90,100,12,Esu LEFT | WS|U BORDER | WS|U TABSTOP | WS|U GROUP | ES|U AUTOHSCROLL
LTEXT“发票日期”,nid发票日期,20、110、50、12
EDITTEXT nid_inv_date_c,70,110,100,12,ES_左| WS_BORDER | WS_TABSTOP | WS_GROUP | ES|u AUTOHSCROLL
LTEXT“GSTIN”,nid卖方,20、130、50、12
EDITTEXT nid|U卖方| gstin|c,70,130,100,12,ES|u LEFT | WS|u BORDER | WS|u TABSTOP | WS|u GROUP | ES u AUTOHSCROLL
GROUPBOX“计费对象”,nid_bt_信息,10155180100
LTEXT“名称”,nid_bt_to_t,20170,50,12
编辑文本nid|U bt|U to|c,70170100,12,ES|U LEFT | WS|U BORDER | WS|U TABSTOP | WS|U GROUP | ES|U AUTOHSCROLL
LTEXT“地址”,nid_bt_add_t,20190,50,12
EDITTEXT nid|U bt|U add|c,70190100,12,ES|U LEFT | WS|U BORDER | WS|U TABSTOP | WS|U GROUP | ES|U AUTOHSCROLL
LTEXT“GSTIN”,nid_bt_GSTIN_t,20210,50,12
编辑文本nid|U bt|U gstin|c,70210100,12,ES|u LEFT | WS|u BORDER | WS|u TABSTOP | WS|u GROUP | ES u AUTOHSCROLL
LTEXT“州”,nid_bt_州,20230,50,12
EDITTEXT nid_bt_state_c,70230100,12,Esu LEFT | WS|U BORDER | WS|U TABSTOP | WS|U GROUP | ES|U AUTOHSCROLL
复选框“发货至与开票至相同”,nid_为bt_st_相同,200、230、180、20
GROUPBOX“配送信息”,nid_配送信息,200、80、180、140
LTEXT“名称”,nid_ship_to_t,210、100、50、12
EDITTEXT nid|U ship|U to|c,260,100,100,12,ES|U LEFT | WS|U BORDER | WS|U TABSTOP | WS|U GROUP | ES|U AUTOHSCROLL
LTEXT“地址”,nid\u ship\u add\u t,210、120、50、12
EDITTEXT nid|U ship|U add|c,260,120100,10,ES|U LEFT | WS|U BORDER | WS|U TABSTOP | WS|U GROUP | ES|U AUTOHSCROLL
LTEXT“GSTIN”,nid_ship_GSTIN_t,210140,50,12
EDITTEXT nid_ship_gstin_c,260140100,12,Esu LEFT | WS|U BORDER | WS|U TABSTOP | WS|U GROUP | ES|U AUTOHSCROLL
LTEXT“日期”,未发货日期,210160,50,12
EDITTEXT nid_ship_date_c,260160100,12,ES_LEFT | WS|U BORDER | WS|U TABSTOP | WS|U GROUP | ES|U AUTOHSCROLL
LTEXT“模式”,nid船舶模式,210180,50,12
EDITTEXT nid|U ship|U mode|c,260180100,12,ES|U LEFT | WS|U BORDER | WS|U TABSTOP | WS|U GROUP | ES|U AUTOHSCROLL
LTEXT“州”,nid船舶州,210200,50,12
EDITTEXT nid_ship_state_c,26020100,12,Esu LEFT | WS|U BORDER | WS|U TABSTOP | WS|U GROUP | ES|U AUTOHSCROLL
分组框“税务信息”,国家税务局税务信息,10270370,45
CTEXT“CGST(%)”,国家税务总局,25280,100,12
EDITTEXT nid_tax_cgst_c,2529510012,ES_左| WS_边界| WS_TABSTOP | WS_集团| ES|编号
CTEXT“SGST(%)”,国家税务总局,13528010012
EDITTEXT nid_tax_sgst_c,135295,100,12,ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES|U编号
CTEXT“IGST(%)”,国家税务局IGST,255,280,100,12
EDITTEXT nid_tax_igst_c,25529510012,ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES|U编号
}
顺便说一句,我在windows vista home basics SPS2(32位)上使用代码bock
问题 问题在于
basefile01.cpp中的MoveWindow
函数在invoice\u dialog\u child\u enum\u scroll
内
无论何时处理WM_VSCROLL
,lvc向上移动,其所有列标题都消失。
但是,在创建lisview及其列时没有错误或错误(据我所知),因为当我更改lvc的坐标时,创建它时,它出现在屏幕上,此时我可以看到
#define MAIN_MENU 1
#define NEW_INVOICE_DIALOG_MENU 2
#define NEW_INVOICE_DIALOG 3
#define NEW_INVOICE_DIALOG_MENU_save 4
#define NEW_INVOICE_DIALOG_MENU_help 6
#define APP_ICON_XL 7
#define APP_ICON_S 8
#define MAIN_MENU_file_new_invoice 102
#define MAIN_MENU_file_new_challan 103
#define MAIN_MENU_file_open 104
#define MAIN_MENU_file_export_jpeg 105
#define MAIN_MENU_file_export_pdf 106
#define nid_ponumber_c 107
#define nid_ponumber_t 108
#define nid_podate_c 109
#define nid_podate_t 110
#define nid_vcode_c 111
#define nid_vcode_t 112
#define nid_inv_no_c 113
#define nid_inv_no_t 114
#define nid_inv_date_t 115
#define nid_inv_date_c 116
#define nid_seller_gstin_c 117
#define nid_seller_gstin_t 118
#define nid_seller_info 119
#define nid_seller_state_c 120
#define nid_seller_state_t 121
#define nid_ship_info 122
#define nid_ship_date_c 123
#define nid_ship_date_t 124
#define nid_ship_add_t 125
#define nid_ship_add_c 126
#define nid_ship_mode_t 127
#define nid_ship_mode_c 128
#define nid_ship_to_t 129
#define nid_ship_to_c 130
#define nid_ship_gstin_t 131
#define nid_ship_gstin_c 132
#define nid_ship_state_t 133
#define nid_ship_state_c 134
#define nid_order_info 135
#define nid_bt_info 136
#define nid_bt_to_t 137
#define nid_bt_to_c 138
#define nid_bt_add_t 139
#define nid_bt_add_c 140
#define nid_bt_gstin_t 141
#define nid_bt_gstin_c 142
#define nid_bt_state_t 143
#define nid_bt_state_c 144
#define nid_is_bt_st_same_ 145
#define nid_tax_info 146
#define nid_tax_rc_t 147
#define nid_tax_rc_c 148
#define nid_tax_cgst_t 149
#define nid_tax_cgst_c 150
#define nid_tax_sgst_t 151
#define nid_tax_sgst_c 152
#define nid_tax_igst_t 153
#define nid_tax_igst_c 154
#define nid_itd_info 155
#define nid_itd_lv 156
#define nid_itd_mat_t 157
#define nid_itd_mat_c 158
#define nid_itd_qty_t 159
#define nid_itd_qty_c 160
#define nid_itd_hsn_t 161
#define nid_itd_hsn_c 162
#define nid_itd_rate_t 163
#define nid_itd_rate_c 164
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include "../include/main_rsc.h"
///////// MENUS
MAIN_MENU MENU
{
POPUP "File"
{
POPUP "New"
{
MENUITEM "Invoice", MAIN_MENU_file_new_invoice
MENUITEM "Challan", MAIN_MENU_file_new_challan
}
MENUITEM "&open", MAIN_MENU_file_open
POPUP "&Export"
{
MENUITEM "JPEG", MAIN_MENU_file_export_jpeg
MENUITEM "PDF", MAIN_MENU_file_export_pdf
}
}
}
NEW_INVOICE_DIALOG_MENU MENU
{
MENUITEM "&save", NEW_INVOICE_DIALOG_MENU_save
MENUITEM "&help",NEW_INVOICE_DIALOG_MENU_help,HELP
}
//////////////// ICONS
APP_ICON_XL ICON "icons/icon02_256.ico"
APP_ICON_S ICON "icons/icon02_16.ico"
/**
DIALOG resource
*/
NEW_INVOICE_DIALOG DIALOGEX 0,0,500,300
CAPTION "New Invoice"
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU | WS_THICKFRAME | WS_VSCROLL
MENU NEW_INVOICE_DIALOG_MENU
FONT 8, "Ms Shell Dlg"
{
GROUPBOX "Purchase Order Information", nid_order_info, 10, 10, 370, 65
LTEXT "PO NUMBER",nid_ponumber_t, 20, 20, 50, 12
EDITTEXT nid_ponumber_c, 70, 20, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "PO DATE", nid_podate_t, 20, 40, 50, 12
EDITTEXT nid_podate_c, 70, 40, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "Vendor Code", nid_vcode_t, 20, 60, 50, 12
EDITTEXT nid_vcode_c, 70, 60, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
GROUPBOX "Seller Information", nid_seller_info, 10,80, 180, 70
LTEXT "Invoice No.", nid_inv_no_t, 20, 90, 50, 20
EDITTEXT nid_inv_no_c, 70, 90, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "Invoice date", nid_inv_date_t, 20, 110, 50, 12
EDITTEXT nid_inv_date_c, 70, 110, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "GSTIN", nid_seller_gstin_t, 20, 130, 50, 12
EDITTEXT nid_seller_gstin_c, 70, 130, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
GROUPBOX "Billed To", nid_bt_info, 10, 155, 180, 100
LTEXT "Name", nid_bt_to_t, 20,170,50,12
EDITTEXT nid_bt_to_c, 70, 170,100,12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "Address", nid_bt_add_t, 20,190,50,12
EDITTEXT nid_bt_add_c, 70,190,100,12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "GSTIN", nid_bt_gstin_t, 20, 210, 50,12
EDITTEXT nid_bt_gstin_c, 70,210,100,12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "State", nid_bt_state_t, 20, 230,50,12
EDITTEXT nid_bt_state_c, 70,230,100,12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
CHECKBOX "Shipped to is same as Billed to", nid_is_bt_st_same_, 200, 230, 180,20
GROUPBOX "Shipping Information", nid_ship_info, 200, 80, 180, 140
LTEXT "Name ", nid_ship_to_t, 210, 100, 50, 12
EDITTEXT nid_ship_to_c, 260, 100, 100, 12,ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "Address", nid_ship_add_t , 210, 120, 50,12
EDITTEXT nid_ship_add_c, 260, 120,100,10, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "GSTIN", nid_ship_gstin_t, 210,140,50,12
EDITTEXT nid_ship_gstin_c, 260,140,100,12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "Date", nid_ship_date_t, 210,160,50,12
EDITTEXT nid_ship_date_c, 260,160,100,12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "Mode", nid_ship_mode_t, 210, 180,50,12
EDITTEXT nid_ship_mode_c, 260, 180,100,12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
LTEXT "State", nid_ship_state_t, 210,200,50,12
EDITTEXT nid_ship_state_c, 260,200,100,12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_AUTOHSCROLL
GROUPBOX "Taxing information", nid_tax_info, 10,270,370, 45
CTEXT "CGST (%)", nid_tax_cgst_t, 25, 280, 100, 12
EDITTEXT nid_tax_cgst_c, 25,295, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_NUMBER
CTEXT "SGST (%)", nid_tax_sgst_t, 135, 280, 100, 12
EDITTEXT nid_tax_sgst_c, 135,295, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_NUMBER
CTEXT "IGST (%)", nid_tax_igst_t, 255, 280, 100, 12
EDITTEXT nid_tax_igst_c, 255,295, 100, 12, ES_LEFT | WS_BORDER | WS_TABSTOP | WS_GROUP | ES_NUMBER
}
for(HWND child = GetWindow(hwnd, GW_CHILD); child;
child = GetWindow(child, GW_HWNDNEXT)) { }
...
std::map<HWND, int> item_positions;
BOOL CALLBACK diaproc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM)
{
static HWND hlist;
switch(msg)
{
case WM_INITDIALOG:
{
hlist = CreateWindow(WC_LISTVIEW, NULL, WS_CHILD | WS_VISIBLE | LVS_REPORT,
10, 100, 300, 2000, hwnd, NULL, NULL, NULL);
ListView_SetExtendedListViewStyle(hlist, LVS_EX_GRIDLINES);
std::vector<TCHAR*> col_names = { TEXT("text1"), TEXT("text2") };
LVCOLUMN lvc;
lvc.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_WIDTH | LVCF_TEXT;
for(int i = 0; i < (int)col_names.size(); i++)
{
lvc.fmt = LVCFMT_LEFT;
lvc.cx = 100;
lvc.pszText = col_names[i];
lvc.iSubItem = i;
ListView_InsertColumn(hlist, i, &lvc);
}
RECT rc;
GetClientRect(hwnd, &rc);
//find the lowest point in dialog:
RECT list_rect;
GetClientRect(hlist, &list_rect);
POINT pt = { list_rect.right, list_rect.bottom };
ScreenToClient(hwnd, &pt);
SCROLLINFO info = { sizeof(SCROLLINFO) };
info.fMask = SIF_ALL;
info.nMin = 0;
info.nMax = pt.y + rc.bottom - 1;
info.nPage = rc.bottom;
info.fMask = SIF_ALL;
SetScrollInfo(hwnd, SB_VERT, &info, TRUE);
//save y-positions for later
for(HWND child = GetWindow(hwnd, GW_CHILD); child;
child = GetWindow(child, GW_HWNDNEXT))
{
GetWindowRect(child, &rc);
pt = { rc.left, rc.top };
ScreenToClient(hwnd, &pt);
item_positions[child] = pt.y;
}
return FALSE;
}
case WM_VSCROLL:
{
SCROLLINFO info = { sizeof(info) };
info.fMask = SIF_ALL;
GetScrollInfo(hwnd, SB_VERT, &info);
int pos = info.nPos;
int track = HIWORD(wParam);
switch(LOWORD(wParam))
{
case SB_LEFT: pos = info.nMin; break;
case SB_RIGHT: pos = info.nMax; break;
case SB_LINELEFT: pos--; break;
case SB_LINERIGHT: pos++; break;
case SB_PAGELEFT: pos -= info.nPage; break;
case SB_PAGERIGHT: pos += info.nPage; break;
case SB_THUMBPOSITION:
case SB_THUMBTRACK: pos = track; break;
}
SetScrollPos(hwnd, SB_VERT, pos, FALSE);
int count = 0;
for(HWND child = GetWindow(hwnd, GW_CHILD); child;
child = GetWindow(child, GW_HWNDNEXT))
count++;
HDWP hdwp = BeginDeferWindowPos(count);
for(HWND child = GetWindow(hwnd, GW_CHILD); child;
child = GetWindow(child, GW_HWNDNEXT))
{
RECT rc;
GetWindowRect(child, &rc);
POINT pt = { rc.left, rc.top };
ScreenToClient(hwnd, &pt);
if(item_positions.find(child) != item_positions.end())
{
int y = pos - item_positions[child];
DeferWindowPos(hdwp, child, NULL, pt.x, -y, 0, 0,
SWP_NOSIZE | SWP_NOACTIVATE);
}
}
EndDeferWindowPos(hdwp);
return TRUE;
}
case WM_COMMAND:
if(LOWORD(wParam) == IDCANCEL)
EndDialog(hwnd, wParam);
return TRUE;
default: return FALSE;
}
}
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE, LPSTR, int)
{
DialogBox(hinst, MAKEINTRESOURCE(IDD_DIALOG1), 0, (DLGPROC)diaproc);
return 0;
}