Z
zhgart
Guest
Set up a modeless dialog, but no display when run program, here is codes,
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
HWND hDlgModeless;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_WAPP1128_1, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WAPP1128_1);
hDlgModeless = CreateDialog(hInstance,"ColorScrDlg", hWnd, ColorScrDlg);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (hDlgModeless==0 || IsDialogMessage(hDlgModeless,&msg)) {
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
return msg.wParam;
}
.....
//////////////////BOOL CALLBACK COLORSCRDIALOG////////////////
BOOL CALLBACK ColorScrDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
static int color[3];
HWND hWndParent, hCtr;
int nCtrID, nIndex;
HBRUSH hBrusha;
switch (message) {
case WM_INITDIALOG:
for(nCtrID=10; nCtrID<13; nCtrID++) {
hCtr = GetDlgItem(hDlg,nCtrID);
SetScrollRange(hCtr,SB_CTL,0,255,FALSE);
SetScrollPos (hCtr,SB_CTL,0,FALSE);
}
return TRUE;
case WM_VSCROLL:
hCtr = (HWND)HIWORD (lParam);
nCtrID= GetWindowLong(hCtr, GWL_ID);
...
default :
return FALSE;
}
SetScrollPos (hCtr,SB_CTL,color[nIndex], TRUE);
SetDlgItemInt (hDlg,nCtrID+3,color[nIndex], FALSE);
hBrusha=(HBRUSH)GetClassLong (hWndParent,GCL_HBRBACKGROUND);
DeleteObject(hBrusha);
SetClassLong(hWndParent, GCL_HBRBACKGROUND,
(LONG)CreateSolidBrush(RGB (color[0],color[1],color[2])));
InvalidateRect(hWndParent,NULL,TRUE);
return TRUE;
}
return FALSE;
}
/////////////////////////////////Dialog1Color.rc///////////////////////
IDD_DIALOG1 DIALOGEX 0, 0, 187, 139
STYLE DS_MODALFRAME | WS_CHILD | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog1Color"
FONT 10, "System"
BEGIN
LTEXT "Copyright (C) 2014",IDC_STATIC,49,20,119,8 /////
DEFPUSHBUTTON "OK",IDOK,130,7,50,14
PUSHBUTTON "Cancel",IDCANCEL,130,24,50,14
CONTROL "Progress1",IDC_PROGRESS1ruler,"msctls_progress32",
WS_BORDER,117,118,63,14
GROUPBOX "Static",IDC_STATIC,14,13,97,119
CONTROL "Slider1",IDC_SLIDER1red,"msctls_trackbar32",
TBS_AUTOTICKS | TBS_VERT | TBS_BOTH,22,43,23,69,
WS_EX_CLIENTEDGE | WS_EX_STATICEDGE
CONTROL "Slider2",IDC_SLIDER2green,"msctls_trackbar32",TBS_VERT |
TBS_BOTH | TBS_NOTICKS | WS_BORDER | WS_TABSTOP,58,44,14,
67
CONTROL "Slider3",IDC_SLIDER3blue,"msctls_trackbar32",
TBS_AUTOTICKS | TBS_VERT | TBS_BOTH | WS_BORDER,83,42,23,
68,WS_EX_DLGMODALFRAME
END
Thanks
Continue reading...
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
HWND hDlgModeless;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_WAPP1128_1, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WAPP1128_1);
hDlgModeless = CreateDialog(hInstance,"ColorScrDlg", hWnd, ColorScrDlg);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (hDlgModeless==0 || IsDialogMessage(hDlgModeless,&msg)) {
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
return msg.wParam;
}
.....
//////////////////BOOL CALLBACK COLORSCRDIALOG////////////////
BOOL CALLBACK ColorScrDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
static int color[3];
HWND hWndParent, hCtr;
int nCtrID, nIndex;
HBRUSH hBrusha;
switch (message) {
case WM_INITDIALOG:
for(nCtrID=10; nCtrID<13; nCtrID++) {
hCtr = GetDlgItem(hDlg,nCtrID);
SetScrollRange(hCtr,SB_CTL,0,255,FALSE);
SetScrollPos (hCtr,SB_CTL,0,FALSE);
}
return TRUE;
case WM_VSCROLL:
hCtr = (HWND)HIWORD (lParam);
nCtrID= GetWindowLong(hCtr, GWL_ID);
...
default :
return FALSE;
}
SetScrollPos (hCtr,SB_CTL,color[nIndex], TRUE);
SetDlgItemInt (hDlg,nCtrID+3,color[nIndex], FALSE);
hBrusha=(HBRUSH)GetClassLong (hWndParent,GCL_HBRBACKGROUND);
DeleteObject(hBrusha);
SetClassLong(hWndParent, GCL_HBRBACKGROUND,
(LONG)CreateSolidBrush(RGB (color[0],color[1],color[2])));
InvalidateRect(hWndParent,NULL,TRUE);
return TRUE;
}
return FALSE;
}
/////////////////////////////////Dialog1Color.rc///////////////////////
IDD_DIALOG1 DIALOGEX 0, 0, 187, 139
STYLE DS_MODALFRAME | WS_CHILD | WS_CAPTION | WS_SYSMENU
CAPTION "Dialog1Color"
FONT 10, "System"
BEGIN
LTEXT "Copyright (C) 2014",IDC_STATIC,49,20,119,8 /////
DEFPUSHBUTTON "OK",IDOK,130,7,50,14
PUSHBUTTON "Cancel",IDCANCEL,130,24,50,14
CONTROL "Progress1",IDC_PROGRESS1ruler,"msctls_progress32",
WS_BORDER,117,118,63,14
GROUPBOX "Static",IDC_STATIC,14,13,97,119
CONTROL "Slider1",IDC_SLIDER1red,"msctls_trackbar32",
TBS_AUTOTICKS | TBS_VERT | TBS_BOTH,22,43,23,69,
WS_EX_CLIENTEDGE | WS_EX_STATICEDGE
CONTROL "Slider2",IDC_SLIDER2green,"msctls_trackbar32",TBS_VERT |
TBS_BOTH | TBS_NOTICKS | WS_BORDER | WS_TABSTOP,58,44,14,
67
CONTROL "Slider3",IDC_SLIDER3blue,"msctls_trackbar32",
TBS_AUTOTICKS | TBS_VERT | TBS_BOTH | WS_BORDER,83,42,23,
68,WS_EX_DLGMODALFRAME
END
Thanks
Continue reading...