Click here to Skip to main content
15,913,944 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: WM_CHAR, WM_KEYDOWN??? Pin
Christian Graus12-Apr-05 17:49
protectorChristian Graus12-Apr-05 17:49 
GeneralRe: WM_CHAR, WM_KEYDOWN??? Pin
Hamed Musavi14-Apr-05 15:41
Hamed Musavi14-Apr-05 15:41 
GeneralRe: WM_CHAR, WM_KEYDOWN??? Pin
Christian Graus14-Apr-05 15:43
protectorChristian Graus14-Apr-05 15:43 
GeneralRe: WM_CHAR, WM_KEYDOWN??? Pin
Hamed Musavi14-Apr-05 15:47
Hamed Musavi14-Apr-05 15:47 
GeneralFolder Calls Pin
JWood12-Apr-05 16:20
JWood12-Apr-05 16:20 
GeneralRe: Folder Calls Pin
David Crow12-Apr-05 17:01
David Crow12-Apr-05 17:01 
GeneralRe: Folder Calls Pin
John R. Shaw12-Apr-05 19:30
John R. Shaw12-Apr-05 19:30 
GeneralWhy isn't my Dialog REPAINT Pin
Jobby Joseph12-Apr-05 13:42
Jobby Joseph12-Apr-05 13:42 
Hi Guys,
I am using a Dialog resource template to create a dialog and load that dialog using the function
DialogBox(hMod, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);

The WndProc is like this, What i am trying to do here is to load all the BMP files one by one in to a window when the user clicks the button 'Next' or 'Previous'.
I Tried different techniques, but when i click next the Window is not repainted. The cod for the WndProc is shown below


LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
int i = 0;
int nPos = 0;
switch (message)
{
//HDC hDC, MemDCExercising;
//PAINTSTRUCT Ps;
//HBITMAP bmpExercising;
//HWND ctrl, hwndItem;
//RECT rect;
char szDirectory[256];

WIN32_FIND_DATA FindFileData;
HANDLE hFind;

case WM_INITDIALOG:
GetCurrentDirectory(256, szDirectory);
sprintf(szDirectory,"%s\\debug\\*.bmp",szDirectory);

//finding the first file
hFind = FindFirstFile(szDirectory, &FindFileData);
if (hFind != INVALID_HANDLE_VALUE) {
sprintf(allFiles[i++],"%s", FindFileData.cFileName);
//Finding all the bmp files
while(FindNextFile (hFind,&FindFileData)) {
sprintf(allFiles[i++],"%s", FindFileData.cFileName);
}
totalFiles = i; //Total bmp files
} else { //if there are no BMP files then disable all bot h buttons
//EnableWindow(GetDlgItem(hDlg, IDC_PREVIOUS_IMAGE), FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_NEXT_IMAGE), FALSE);
}
EnableWindow(GetDlgItem(hDlg, IDC_PREVIOUS_IMAGE), FALSE);
return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
if (LOWORD(wParam) == IDC_NEXT_IMAGE) {
currentFile ++;
EnableWindow(GetDlgItem(hDlg, IDC_PREVIOUS_IMAGE), TRUE);
//RedrawWindow(hDlg, NULL, NULL, RDW_ERASE);
//InvalidateRect (GetDlgItem(hDlg, IDC_CANVAS), NULL, FALSE);
if(currentFile>=totalFiles-1) { //if all the files has been viewed then disable next button
EnableWindow(GetDlgItem(hDlg, IDC_NEXT_IMAGE), FALSE);
}
//hwndItem = (HWND) GetDlgItem(hDlg,IDC_CANVAS);
//repaintWindow(hDlg);
//nPos = SendMessage( hDlg, WM_PAINT, 0, 0 );
//InvalidateRect (hDlg, NULL, TRUE);
UpdateWindow (hDlg);
//RedrawWindow(hDlg, NULL, NULL, RDW_INTERNALPAINT);
}
if (LOWORD(wParam) == IDC_PREVIOUS_IMAGE) {
currentFile --;
EnableWindow(GetDlgItem(hDlg, IDC_NEXT_IMAGE), TRUE);
//RedrawWindow(hDlg, NULL, NULL, RDW_ERASE);
//InvalidateRect (GetDlgItem(hDlg, IDC_CANVAS), NULL, FALSE);
if(currentFile<=0) { //if all the files has been viewed then disable next button
currentFile = 0;
EnableWindow(GetDlgItem(hDlg, IDC_PREVIOUS_IMAGE), FALSE);
}
//hwndItem = (HWND) GetDlgItem(hDlg,IDC_CANVAS);
//repaintWindow(hDlg);
//nPos = SendMessage( hDlg, WM_PAINT, 0, 0 );
//InvalidateRect (hDlg, NULL, TRUE);
//RedrawWindow(hDlg, NULL, NULL, RDW_INTERNALPAINT);
UpdateWindow (hDlg);

}
return TRUE;
break;
case WM_DESTROY:
PostQuitMessage (WM_QUIT);
break;
case WM_PAINT:
/*ctrl = GetDlgItem(hDlg, IDC_CANVAS);
hDC = BeginPaint(ctrl, &Ps);

// Load the bitmap from the resource
//bmpExercising = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));
//Load bitmap from a file
bmpExercising = (HBITMAP)LoadImage(
hInst, // handle to instance
allFiles[currentFile], // image to load
IMAGE_BITMAP, // image type
0, // desired width
0, // desired height
LR_LOADFROMFILE// load options
);

//GetBitmapDimensionEx (bmpExercising, bmpSize);

// Create a memory device compatible with the above DC variable
MemDCExercising = CreateCompatibleDC(hDC);
// Select the new bitmap
SelectObject(MemDCExercising, bmpExercising);

GetWindowRect(ctrl,&rect); // Copy the bits from the memory DC into the current dc
StretchBlt(hDC, 0, 0, rect.right - rect.left,
rect.bottom - rect.top,
MemDCExercising, 0, 0,200,
200, SRCCOPY);

// Restore the old bitmap
DeleteDC(MemDCExercising);
DeleteObject(bmpExercising);
EndPaint(ctrl, &Ps);
//UpdateWindow(GetDlgItem(hwnd, IDD_DIALOG_BOX));
//return FALSE;
*/
repaintWindow(hDlg);
break;
//Initilize the dialog
//default:
// return DefWindowProc(hDlg, message, wParam, lParam);
}
return FALSE;
}

void repaintWindow (HWND hDlg) {
HDC hDC, MemDCExercising;
PAINTSTRUCT Ps;
HBITMAP bmpExercising;
HWND ctrl;//, hwndItem;
RECT rect;

ctrl = GetDlgItem(hDlg, IDC_CANVAS);
hDC = BeginPaint(ctrl, &Ps);

// Load the bitmap from the resource
//bmpExercising = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));
//Load bitmap from a file
bmpExercising = (HBITMAP)LoadImage(
hInst, // handle to instance
allFiles[currentFile], // image to load
IMAGE_BITMAP, // image type
0, // desired width
0, // desired height
LR_LOADFROMFILE// load options
);

//GetBitmapDimensionEx (bmpExercising, bmpSize);

// Create a memory device compatible with the above DC variable
MemDCExercising = CreateCompatibleDC(hDC);
// Select the new bitmap
SelectObject(MemDCExercising, bmpExercising);

GetWindowRect(ctrl,&rect); // Copy the bits from the memory DC into the current dc
StretchBlt(hDC, 0, 0, rect.right - rect.left,
rect.bottom - rect.top,
MemDCExercising, 0, 0,200,
200, SRCCOPY);

// Restore the old bitmap
DeleteDC(MemDCExercising);
DeleteObject(bmpExercising);
EndPaint(ctrl, &Ps);
//UpdateWindow(GetDlgItem(hwnd, IDD_DIALOG_BOX));
//return FALSE;
}

Please help me.

Thanking in Advance,
Jobby
GeneralRe: Why isn't my Dialog REPAINT Pin
John R. Shaw12-Apr-05 17:47
John R. Shaw12-Apr-05 17:47 
GeneralRe: Why isn't my Dialog REPAINT Pin
Jobby Joseph13-Apr-05 4:18
Jobby Joseph13-Apr-05 4:18 
GeneralRe: Why isn't my Dialog REPAINT Pin
Jobby Joseph13-Apr-05 10:57
Jobby Joseph13-Apr-05 10:57 
GeneralComputer freezing up on wait Pin
theFrenchHornet12-Apr-05 12:08
theFrenchHornet12-Apr-05 12:08 
GeneralRe: Computer freezing up on wait Pin
Jack Puppy12-Apr-05 13:06
Jack Puppy12-Apr-05 13:06 
GeneralRe: Computer freezing up on wait Pin
theFrenchHornet13-Apr-05 5:01
theFrenchHornet13-Apr-05 5:01 
GeneralRe: Computer freezing up on wait Pin
theFrenchHornet14-Apr-05 6:35
theFrenchHornet14-Apr-05 6:35 
GeneralRe: Computer freezing up on wait Pin
Blake Miller14-Apr-05 9:29
Blake Miller14-Apr-05 9:29 
GeneralRe: Computer freezing up on wait Pin
Blake Miller13-Apr-05 6:52
Blake Miller13-Apr-05 6:52 
GeneralRe: Computer freezing up on wait Pin
theFrenchHornet14-Apr-05 6:33
theFrenchHornet14-Apr-05 6:33 
GeneralReading A File Pin
LighthouseJ12-Apr-05 11:33
LighthouseJ12-Apr-05 11:33 
GeneralFollow-Up Pin
LighthouseJ12-Apr-05 16:03
LighthouseJ12-Apr-05 16:03 
GeneralRe: Follow-Up Pin
John R. Shaw12-Apr-05 19:16
John R. Shaw12-Apr-05 19:16 
GeneralRe: Follow-Up Pin
LighthouseJ12-Apr-05 19:30
LighthouseJ12-Apr-05 19:30 
GeneralRe: Follow-Up Pin
John R. Shaw12-Apr-05 20:43
John R. Shaw12-Apr-05 20:43 
GeneralRe: Follow-Up Pin
LighthouseJ13-Apr-05 4:02
LighthouseJ13-Apr-05 4:02 
GeneralRe: Reading A File Pin
Ryan Binns12-Apr-05 18:25
Ryan Binns12-Apr-05 18:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.