c - PostMessage doesn't seem to work? -
c - PostMessage doesn't seem to work? -
i'm trying larn how utilize , receive raw input messages, , devised next programme test understanding far...
when recieve input message, seek alter string displayed , place new wm_paint
message on queue. message doesn't seem called. when resize window text appear different.
why wm_paint
message not getting processed @ all, until resize window example?
#define _win32_winnt 0x501 #include <windows.h> #include <assert.h> #include <cstring> #include <cstdio> lresult callback winprocedure(hwnd hwnd, uint msg, wparam wparam, lparam lparam); int winmain(hinstance hinst,hinstance,lpstr,int ncmdshow) { wndclass wc; hwnd hwnd; wc.hinstance = hinst; wc.lpfnwndproc = winprocedure; wc.style = cs_hredraw | cs_vredraw; wc.cbclsextra = 0; wc.cbwndextra = 0; wc.hicon = loadicon(null, idi_winlogo); wc.hcursor = loadcursor(null, idc_arrow); wc.hbrbackground = (hbrush)color_windowframe; wc.lpszmenuname = null; wc.lpszclassname = "untitled"; if (!registerclass(&wc)) { // error registering class homecoming -1; } if (!(hwnd = createwindow(wc.lpszclassname, wc.lpszclassname, ws_overlappedwindow, cw_usedefault,cw_usedefault,500,300,null,null,hinst,null))) { // error creating window homecoming -1; } showwindow(hwnd,ncmdshow); updatewindow(hwnd); rawinputdevice rid[1]; rid[0].ususagepage = 0x01; rid[0].ususage = 0x06; rid[0].dwflags = 0; // adds hid keyboard , ignores legacy keyboard messages rid[0].hwndtarget = 0; if (registerrawinputdevices(rid, 1, sizeof(rid[0])) == false) { homecoming -5; } msg msg; while (getmessage(&msg,null,0,0) > 0) { translatemessage(&msg); dispatchmessage(&msg); } homecoming 0; } lresult callback winprocedure(hwnd hwnd, uint msg, wparam wparam, lparam lparam) { static char buffer[5000] = "hi"; if (msg == wm_paint) { paintstruct ps; hdc dc; rect r; getclientrect(hwnd,&r); dc=beginpaint(hwnd,&ps); drawtext(dc,buffer,-1,&r,dt_singleline|dt_center|dt_vcenter); endpaint(hwnd,&ps); homecoming 0; } if (msg == wm_input) { strcpy(buffer, "recieved input."); //assert(false); postmessage(hwnd, wm_paint, wparam, lparam); homecoming 0; } if (msg == wm_destroy) { postquitmessage(0); homecoming 0; } homecoming defwindowproc(hwnd, msg, wparam, lparam); }
if take @ the documentation wm_paint
message, says clearly:
the wm_paint message generated scheme , should not sent application.
if doesn't work way expect, consult documentation first. there's reason why exist. utilize them advantage.
the reason why posting wm_paint
doesn't work because there's way more painting sending wm_paint
message. scheme sets proper structures allow application paint on window, among other things, example. sending wm_paint
window samll part of entire painting process.
what want invalidaterect()
function, tells operating scheme want repaint part of window. os proper painting procedure.
c windows winapi
Comments
Post a Comment