From: Jimbo on 1 Jan 2010 03:42 Hello I am trying to make an Win32 application where whenever the left button is clicked, a bitmap is created at the mouse coordinates. Problem: the bitmap is not created when I left click(nothing happens), left click is being received. I believe its the way I am trying to make the bitmap which is the problem. Is there is a better way to do what I am trying to do? Loose "Algorithm": - Left mouse button is pressed anywhere on client window. - Windows proceedure function receives WM_LBUTTONDOWN message; mouse x,y coords are stored in variables int x,y & sends custom message IDB_DRAW which triggers bitmap creation. - Win Proceedure receives WM_COMMAND (wParam)IDB_DRAW message. A static window is created to display a bitmap at the x,y coords. (problem occurs here). Code: (code under "case IDB_DRAW" does not work & I dont know why?) LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { HBITMAP pic = NULL; int x,y; switch(msg) { case WM_CREATE: { //pic = LoadImage(GetModuleHandle(NULL), pic = (HBITMAP)LoadImage(NULL,"ball.bmp",IMAGE_BITMAP, 0,0, LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE); if (pic==NULL) { MessageBox(hwnd,"Failed to load bitmap","Error",MB_OK | MB_ICONERROR); } } break; case WM_LBUTTONDOWN: { // get mouse x,y coords x = LOWORD(lParam); y = HIWORD(lParam); // send message to create bitmap SendMessage(hwnd,IDB_DRAW,0,0); MessageBox(hwnd,"wdw ","kj",MB_OK); } break; case WM_COMMAND: { switch(LOWORD(wParam)) { case IDB_DRAW: { HWND bmDot = CreateWindowEx( 0,"Static","",WS_BORDER | WS_CHILD | WS_VISIBLE | SS_BITMAP, x,y,CW_USEDEFAULT, CW_USEDEFAULT,hwnd,NULL,gInstance,NULL); SendMessage(bmDot,STM_SETIMAGE,(WPARAM) IMAGE_BITMAP,(LPARAM)pic); } break; default: break; } } break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; }
From: Paul N on 1 Jan 2010 11:07 On 1 Jan, 08:42, Jimbo <nill...(a)yahoo.com> wrote: > Hello > > I am trying to make an Win32 application where whenever the left > button is clicked, a bitmap is created at the mouse coordinates. > > Problem: the bitmap is not created when I left click(nothing happens), > left click is being received. I believe its the way I am trying to > make the bitmap which is the problem. Is there is a better way to do > what I am trying to do? > > Loose "Algorithm": > - Left mouse button is pressed anywhere on client window. > - Windows proceedure function receives WM_LBUTTONDOWN message; mouse > x,y coords are stored in variables int x,y & sends custom message > IDB_DRAW which triggers bitmap creation. > - Win Proceedure receives WM_COMMAND (wParam)IDB_DRAW message. A > static window is created to display a bitmap at the x,y coords. > (problem occurs here). > > Code: (code under "case IDB_DRAW" does not work & I dont know why?) I'm not at all an expert, but I think I can see the problem here, so in case the experts are all on holiday, here are my thoughts: > LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM > lParam) > { > HBITMAP pic = NULL; > int x,y; > > switch(msg) > { > case WM_CREATE: > { > //pic = LoadImage(GetModuleHandle(NULL), > pic = (HBITMAP)LoadImage(NULL,"ball.bmp",IMAGE_BITMAP, > 0,0, > LR_CREATEDIBSECTION | LR_DEFAULTSIZE | > LR_LOADFROMFILE); > > if (pic==NULL) { > MessageBox(hwnd,"Failed to load bitmap","Error",MB_OK > | MB_ICONERROR); > } > } > break; > case WM_LBUTTONDOWN: > { > // get mouse x,y coords > x = LOWORD(lParam); > y = HIWORD(lParam); > // send message to create bitmap > SendMessage(hwnd,IDB_DRAW,0,0); This looks wrong. You are sending a message of type "IDB_DRAW", when what you want (see a couple of lines further down) is a message of type WM_COMMAND whose wParam is IDB_DRAW. > MessageBox(hwnd,"wdw ","kj",MB_OK); > } > break; > case WM_COMMAND: > { > switch(LOWORD(wParam)) > { > case IDB_DRAW: > { > HWND bmDot = CreateWindowEx( > 0,"Static","",WS_BORDER | WS_CHILD > | WS_VISIBLE | SS_BITMAP, > x,y,CW_USEDEFAULT, > CW_USEDEFAULT,hwnd,NULL,gInstance,NULL); > > SendMessage(bmDot,STM_SETIMAGE,(WPARAM) > IMAGE_BITMAP,(LPARAM)pic); > } > break; > default: > break; > } > } > break; > case WM_CLOSE: > DestroyWindow(hwnd); > break; > case WM_DESTROY: > PostQuitMessage(0); > break; > default: > return DefWindowProc(hwnd, msg, wParam, lParam); > } > return 0; > > > > } Hope that helps. Paul.
|
Pages: 1 Prev: loading dll (lame encoder) Next: (C++/Win32) Open a Movie file in Specific Application |